mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-22 07:01:56 +03:00
+42
-43
@@ -1,112 +1,111 @@
|
||||
resource "aws_elastic_beanstalk_application" "app" {
|
||||
name = "app"
|
||||
name = "app"
|
||||
description = "app"
|
||||
}
|
||||
|
||||
resource "aws_elastic_beanstalk_environment" "app-prod" {
|
||||
name = "app-prod"
|
||||
application = "${aws_elastic_beanstalk_application.app.name}"
|
||||
name = "app-prod"
|
||||
application = aws_elastic_beanstalk_application.app.name
|
||||
solution_stack_name = "64bit Amazon Linux 2016.09 v2.3.0 running PHP 7.0"
|
||||
setting {
|
||||
namespace = "aws:ec2:vpc"
|
||||
name = "VPCId"
|
||||
value = "${aws_vpc.main.id}"
|
||||
value = aws_vpc.main.id
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:ec2:vpc"
|
||||
name = "Subnets"
|
||||
value = "${aws_subnet.main-private-1.id},${aws_subnet.main-private-2.id}"
|
||||
name = "Subnets"
|
||||
value = "${aws_subnet.main-private-1.id},${aws_subnet.main-private-2.id}"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:ec2:vpc"
|
||||
name = "AssociatePublicIpAddress"
|
||||
value = "false"
|
||||
name = "AssociatePublicIpAddress"
|
||||
value = "false"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:launchconfiguration"
|
||||
name = "IamInstanceProfile"
|
||||
value = "${aws_iam_instance_profile.app-ec2-role.name}"
|
||||
name = "IamInstanceProfile"
|
||||
value = aws_iam_instance_profile.app-ec2-role.name
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:launchconfiguration"
|
||||
name = "SecurityGroups"
|
||||
value = "${aws_security_group.app-prod.id}"
|
||||
name = "SecurityGroups"
|
||||
value = aws_security_group.app-prod.id
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:launchconfiguration"
|
||||
name = "EC2KeyName"
|
||||
value = "${aws_key_pair.mykeypair.id}"
|
||||
name = "EC2KeyName"
|
||||
value = aws_key_pair.mykeypair.id
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:launchconfiguration"
|
||||
name = "InstanceType"
|
||||
value = "t2.micro"
|
||||
name = "InstanceType"
|
||||
value = "t2.micro"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:environment"
|
||||
name = "ServiceRole"
|
||||
value = "${aws_iam_role.elasticbeanstalk-service-role.name}"
|
||||
name = "ServiceRole"
|
||||
value = aws_iam_role.elasticbeanstalk-service-role.name
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:ec2:vpc"
|
||||
name = "ELBScheme"
|
||||
value = "public"
|
||||
name = "ELBScheme"
|
||||
value = "public"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:ec2:vpc"
|
||||
name = "ELBSubnets"
|
||||
value = "${aws_subnet.main-public-1.id},${aws_subnet.main-public-2.id}"
|
||||
name = "ELBSubnets"
|
||||
value = "${aws_subnet.main-public-1.id},${aws_subnet.main-public-2.id}"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elb:loadbalancer"
|
||||
name = "CrossZone"
|
||||
value = "true"
|
||||
name = "CrossZone"
|
||||
value = "true"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:command"
|
||||
name = "BatchSize"
|
||||
value = "30"
|
||||
name = "BatchSize"
|
||||
value = "30"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:command"
|
||||
name = "BatchSizeType"
|
||||
value = "Percentage"
|
||||
name = "BatchSizeType"
|
||||
value = "Percentage"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:asg"
|
||||
name = "Availability Zones"
|
||||
value = "Any 2"
|
||||
name = "Availability Zones"
|
||||
value = "Any 2"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:asg"
|
||||
name = "MinSize"
|
||||
value = "1"
|
||||
name = "MinSize"
|
||||
value = "1"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:autoscaling:updatepolicy:rollingupdate"
|
||||
name = "RollingUpdateType"
|
||||
value = "Health"
|
||||
name = "RollingUpdateType"
|
||||
value = "Health"
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "RDS_USERNAME"
|
||||
value = "${aws_db_instance.mariadb.username}"
|
||||
name = "RDS_USERNAME"
|
||||
value = aws_db_instance.mariadb.username
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "RDS_PASSWORD"
|
||||
value = "${aws_db_instance.mariadb.password}"
|
||||
name = "RDS_PASSWORD"
|
||||
value = aws_db_instance.mariadb.password
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "RDS_DATABASE"
|
||||
value = "mydb"
|
||||
value = "${aws_db_instance.mariadb.name}"
|
||||
name = "RDS_DATABASE"
|
||||
value = aws_db_instance.mariadb.name
|
||||
}
|
||||
setting {
|
||||
namespace = "aws:elasticbeanstalk:application:environment"
|
||||
name = "RDS_HOSTNAME"
|
||||
value = "${aws_db_instance.mariadb.endpoint}"
|
||||
name = "RDS_HOSTNAME"
|
||||
value = aws_db_instance.mariadb.endpoint
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-18
@@ -1,7 +1,7 @@
|
||||
# iam roles
|
||||
resource "aws_iam_role" "app-ec2-role" {
|
||||
name = "app-ec2-role"
|
||||
assume_role_policy = <<EOF
|
||||
name = "app-ec2-role"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -16,16 +16,18 @@ resource "aws_iam_role" "app-ec2-role" {
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
resource "aws_iam_instance_profile" "app-ec2-role" {
|
||||
name = "app-ec2-role"
|
||||
role = "${aws_iam_role.app-ec2-role.name}"
|
||||
name = "app-ec2-role"
|
||||
role = aws_iam_role.app-ec2-role.name
|
||||
}
|
||||
|
||||
# service
|
||||
resource "aws_iam_role" "elasticbeanstalk-service-role" {
|
||||
name = "elasticbeanstalk-service-role"
|
||||
assume_role_policy = <<EOF
|
||||
name = "elasticbeanstalk-service-role"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -40,26 +42,31 @@ resource "aws_iam_role" "elasticbeanstalk-service-role" {
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# policies
|
||||
resource "aws_iam_policy_attachment" "app-attach1" {
|
||||
name = "app-attach1"
|
||||
roles = ["${aws_iam_role.app-ec2-role.name}"]
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier"
|
||||
name = "app-attach1"
|
||||
roles = [aws_iam_role.app-ec2-role.name]
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier"
|
||||
}
|
||||
|
||||
resource "aws_iam_policy_attachment" "app-attach2" {
|
||||
name = "app-attach2"
|
||||
roles = ["${aws_iam_role.app-ec2-role.name}"]
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker"
|
||||
name = "app-attach2"
|
||||
roles = [aws_iam_role.app-ec2-role.name]
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker"
|
||||
}
|
||||
|
||||
resource "aws_iam_policy_attachment" "app-attach3" {
|
||||
name = "app-attach3"
|
||||
roles = ["${aws_iam_role.app-ec2-role.name}"]
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier"
|
||||
name = "app-attach3"
|
||||
roles = [aws_iam_role.app-ec2-role.name]
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier"
|
||||
}
|
||||
|
||||
resource "aws_iam_policy_attachment" "app-attach4" {
|
||||
name = "app-attach4"
|
||||
roles = ["${aws_iam_role.elasticbeanstalk-service-role.name}"]
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth"
|
||||
name = "app-attach4"
|
||||
roles = [aws_iam_role.elasticbeanstalk-service-role.name]
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth"
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,7 +1,8 @@
|
||||
resource "aws_key_pair" "mykeypair" {
|
||||
key_name = "mykeypair"
|
||||
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
|
||||
key_name = "mykeypair"
|
||||
public_key = file(var.PATH_TO_PUBLIC_KEY)
|
||||
lifecycle {
|
||||
ignore_changes = ["public_key"]
|
||||
ignore_changes = [public_key]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
output "eb" {
|
||||
value = "${aws_elastic_beanstalk_environment.app-prod.cname}"
|
||||
value = aws_elastic_beanstalk_environment.app-prod.cname
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
provider "aws" {
|
||||
region = "${var.AWS_REGION}"
|
||||
provider "aws" {
|
||||
region = var.AWS_REGION
|
||||
}
|
||||
|
||||
|
||||
+32
-33
@@ -1,40 +1,39 @@
|
||||
resource "aws_db_subnet_group" "mariadb-subnet" {
|
||||
name = "mariadb-subnet"
|
||||
description = "RDS subnet group"
|
||||
subnet_ids = ["${aws_subnet.main-private-1.id}","${aws_subnet.main-private-2.id}"]
|
||||
name = "mariadb-subnet"
|
||||
description = "RDS subnet group"
|
||||
subnet_ids = [aws_subnet.main-private-1.id, aws_subnet.main-private-2.id]
|
||||
}
|
||||
|
||||
resource "aws_db_parameter_group" "mariadb-parameters" {
|
||||
name = "mariadb-params"
|
||||
family = "mariadb10.1"
|
||||
description = "MariaDB parameter group"
|
||||
name = "mariadb-params"
|
||||
family = "mariadb10.1"
|
||||
description = "MariaDB parameter group"
|
||||
|
||||
parameter {
|
||||
name = "max_allowed_packet"
|
||||
value = "16777216"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
resource "aws_db_instance" "mariadb" {
|
||||
allocated_storage = 100 # 100 GB of storage, gives us more IOPS than a lower number
|
||||
engine = "mariadb"
|
||||
engine_version = "10.1.14"
|
||||
instance_class = "db.t2.small" # use micro if you want to use the free tier
|
||||
identifier = "mariadb"
|
||||
name = "mydatabase" # database name
|
||||
username = "root" # username
|
||||
password = "${var.RDS_PASSWORD}" # password
|
||||
db_subnet_group_name = "${aws_db_subnet_group.mariadb-subnet.name}"
|
||||
parameter_group_name = "${aws_db_parameter_group.mariadb-parameters.name}"
|
||||
multi_az = "false" # set to true to have high availability: 2 instances synchronized with each other
|
||||
vpc_security_group_ids = ["${aws_security_group.allow-mariadb.id}"]
|
||||
storage_type = "gp2"
|
||||
backup_retention_period = 30 # how long you’re going to keep your backups
|
||||
availability_zone = "${aws_subnet.main-private-1.availability_zone}" # prefered AZ
|
||||
final_snapshot_identifier = "mariadb-final-snapshot" # final snapshot when executing terraform destroy
|
||||
tags {
|
||||
Name = "mariadb-instance"
|
||||
parameter {
|
||||
name = "max_allowed_packet"
|
||||
value = "16777216"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_db_instance" "mariadb" {
|
||||
allocated_storage = 100 # 100 GB of storage, gives us more IOPS than a lower number
|
||||
engine = "mariadb"
|
||||
engine_version = "10.1.14"
|
||||
instance_class = "db.t2.small" # use micro if you want to use the free tier
|
||||
identifier = "mariadb"
|
||||
name = "mydatabase" # database name
|
||||
username = "root" # username
|
||||
password = var.RDS_PASSWORD # password
|
||||
db_subnet_group_name = aws_db_subnet_group.mariadb-subnet.name
|
||||
parameter_group_name = aws_db_parameter_group.mariadb-parameters.name
|
||||
multi_az = "false" # set to true to have high availability: 2 instances synchronized with each other
|
||||
vpc_security_group_ids = [aws_security_group.allow-mariadb.id]
|
||||
storage_type = "gp2"
|
||||
backup_retention_period = 30 # how long you’re going to keep your backups
|
||||
availability_zone = aws_subnet.main-private-1.availability_zone # prefered AZ
|
||||
final_snapshot_identifier = "mariadb-final-snapshot" # final snapshot when executing terraform destroy
|
||||
tags = {
|
||||
Name = "mariadb-instance"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
-25
@@ -1,44 +1,45 @@
|
||||
resource "aws_security_group" "app-prod" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
name = "application - production"
|
||||
vpc_id = aws_vpc.main.id
|
||||
name = "application - production"
|
||||
description = "security group for my app"
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
|
||||
tags {
|
||||
tags = {
|
||||
Name = "myinstance"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "allow-mariadb" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
name = "allow-mariadb"
|
||||
vpc_id = aws_vpc.main.id
|
||||
name = "allow-mariadb"
|
||||
description = "allow-mariadb"
|
||||
ingress {
|
||||
from_port = 3306
|
||||
to_port = 3306
|
||||
protocol = "tcp"
|
||||
security_groups = ["${aws_security_group.app-prod.id}"] # allowing access from our example instance
|
||||
from_port = 3306
|
||||
to_port = 3306
|
||||
protocol = "tcp"
|
||||
security_groups = [aws_security_group.app-prod.id] # allowing access from our example instance
|
||||
}
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
self = true
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
self = true
|
||||
}
|
||||
tags {
|
||||
tags = {
|
||||
Name = "allow-mariadb"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -1,10 +1,15 @@
|
||||
variable "AWS_REGION" {
|
||||
default = "eu-west-1"
|
||||
}
|
||||
|
||||
variable "PATH_TO_PRIVATE_KEY" {
|
||||
default = "mykey"
|
||||
}
|
||||
|
||||
variable "PATH_TO_PUBLIC_KEY" {
|
||||
default = "mykey.pub"
|
||||
}
|
||||
variable "RDS_PASSWORD" {}
|
||||
|
||||
variable "RDS_PASSWORD" {
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
terraform {
|
||||
required_version = ">= 0.12"
|
||||
}
|
||||
+106
-93
@@ -1,143 +1,156 @@
|
||||
# Internet VPC
|
||||
resource "aws_vpc" "main" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
instance_tenancy = "default"
|
||||
enable_dns_support = "true"
|
||||
enable_dns_hostnames = "true"
|
||||
enable_classiclink = "false"
|
||||
tags {
|
||||
Name = "main"
|
||||
}
|
||||
cidr_block = "10.0.0.0/16"
|
||||
instance_tenancy = "default"
|
||||
enable_dns_support = "true"
|
||||
enable_dns_hostnames = "true"
|
||||
enable_classiclink = "false"
|
||||
tags = {
|
||||
Name = "main"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Subnets
|
||||
resource "aws_subnet" "main-public-1" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
cidr_block = "10.0.1.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
availability_zone = "eu-west-1a"
|
||||
vpc_id = aws_vpc.main.id
|
||||
cidr_block = "10.0.1.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
availability_zone = "eu-west-1a"
|
||||
|
||||
tags {
|
||||
Name = "main-public-1"
|
||||
}
|
||||
tags = {
|
||||
Name = "main-public-1"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "main-public-2" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
cidr_block = "10.0.2.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
availability_zone = "eu-west-1b"
|
||||
vpc_id = aws_vpc.main.id
|
||||
cidr_block = "10.0.2.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
availability_zone = "eu-west-1b"
|
||||
|
||||
tags {
|
||||
Name = "main-public-2"
|
||||
}
|
||||
tags = {
|
||||
Name = "main-public-2"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "main-public-3" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
cidr_block = "10.0.3.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
availability_zone = "eu-west-1c"
|
||||
vpc_id = aws_vpc.main.id
|
||||
cidr_block = "10.0.3.0/24"
|
||||
map_public_ip_on_launch = "true"
|
||||
availability_zone = "eu-west-1c"
|
||||
|
||||
tags {
|
||||
Name = "main-public-3"
|
||||
}
|
||||
tags = {
|
||||
Name = "main-public-3"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "main-private-1" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
cidr_block = "10.0.4.0/24"
|
||||
map_public_ip_on_launch = "false"
|
||||
availability_zone = "eu-west-1a"
|
||||
vpc_id = aws_vpc.main.id
|
||||
cidr_block = "10.0.4.0/24"
|
||||
map_public_ip_on_launch = "false"
|
||||
availability_zone = "eu-west-1a"
|
||||
|
||||
tags {
|
||||
Name = "main-private-1"
|
||||
}
|
||||
tags = {
|
||||
Name = "main-private-1"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "main-private-2" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
cidr_block = "10.0.5.0/24"
|
||||
map_public_ip_on_launch = "false"
|
||||
availability_zone = "eu-west-1b"
|
||||
vpc_id = aws_vpc.main.id
|
||||
cidr_block = "10.0.5.0/24"
|
||||
map_public_ip_on_launch = "false"
|
||||
availability_zone = "eu-west-1b"
|
||||
|
||||
tags {
|
||||
Name = "main-private-2"
|
||||
}
|
||||
tags = {
|
||||
Name = "main-private-2"
|
||||
}
|
||||
}
|
||||
resource "aws_subnet" "main-private-3" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
cidr_block = "10.0.6.0/24"
|
||||
map_public_ip_on_launch = "false"
|
||||
availability_zone = "eu-west-1c"
|
||||
|
||||
tags {
|
||||
Name = "main-private-3"
|
||||
}
|
||||
resource "aws_subnet" "main-private-3" {
|
||||
vpc_id = aws_vpc.main.id
|
||||
cidr_block = "10.0.6.0/24"
|
||||
map_public_ip_on_launch = "false"
|
||||
availability_zone = "eu-west-1c"
|
||||
|
||||
tags = {
|
||||
Name = "main-private-3"
|
||||
}
|
||||
}
|
||||
|
||||
# Internet GW
|
||||
resource "aws_internet_gateway" "main-gw" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
vpc_id = aws_vpc.main.id
|
||||
|
||||
tags {
|
||||
Name = "main"
|
||||
}
|
||||
tags = {
|
||||
Name = "main"
|
||||
}
|
||||
}
|
||||
|
||||
# route tables
|
||||
resource "aws_route_table" "main-public" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
gateway_id = "${aws_internet_gateway.main-gw.id}"
|
||||
}
|
||||
vpc_id = aws_vpc.main.id
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
gateway_id = aws_internet_gateway.main-gw.id
|
||||
}
|
||||
|
||||
tags {
|
||||
Name = "main-public-1"
|
||||
}
|
||||
tags = {
|
||||
Name = "main-public-1"
|
||||
}
|
||||
}
|
||||
|
||||
# route associations public
|
||||
resource "aws_route_table_association" "main-public-1-a" {
|
||||
subnet_id = "${aws_subnet.main-public-1.id}"
|
||||
route_table_id = "${aws_route_table.main-public.id}"
|
||||
subnet_id = aws_subnet.main-public-1.id
|
||||
route_table_id = aws_route_table.main-public.id
|
||||
}
|
||||
resource "aws_route_table_association" "main-public-2-a" {
|
||||
subnet_id = "${aws_subnet.main-public-2.id}"
|
||||
route_table_id = "${aws_route_table.main-public.id}"
|
||||
}
|
||||
resource "aws_route_table_association" "main-public-3-a" {
|
||||
subnet_id = "${aws_subnet.main-public-3.id}"
|
||||
route_table_id = "${aws_route_table.main-public.id}"
|
||||
}
|
||||
resource "aws_route_table" "main-private" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
nat_gateway_id = "${aws_nat_gateway.nat-gw.id}"
|
||||
}
|
||||
|
||||
tags {
|
||||
Name = "main-private-1"
|
||||
}
|
||||
resource "aws_route_table_association" "main-public-2-a" {
|
||||
subnet_id = aws_subnet.main-public-2.id
|
||||
route_table_id = aws_route_table.main-public.id
|
||||
}
|
||||
|
||||
resource "aws_route_table_association" "main-public-3-a" {
|
||||
subnet_id = aws_subnet.main-public-3.id
|
||||
route_table_id = aws_route_table.main-public.id
|
||||
}
|
||||
|
||||
resource "aws_route_table" "main-private" {
|
||||
vpc_id = aws_vpc.main.id
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
nat_gateway_id = aws_nat_gateway.nat-gw.id
|
||||
}
|
||||
|
||||
tags = {
|
||||
Name = "main-private-1"
|
||||
}
|
||||
}
|
||||
|
||||
# route associations private
|
||||
resource "aws_route_table_association" "main-private-1-a" {
|
||||
subnet_id = "${aws_subnet.main-private-1.id}"
|
||||
route_table_id = "${aws_route_table.main-private.id}"
|
||||
subnet_id = aws_subnet.main-private-1.id
|
||||
route_table_id = aws_route_table.main-private.id
|
||||
}
|
||||
|
||||
resource "aws_route_table_association" "main-private-2-a" {
|
||||
subnet_id = "${aws_subnet.main-private-2.id}"
|
||||
route_table_id = "${aws_route_table.main-private.id}"
|
||||
subnet_id = aws_subnet.main-private-2.id
|
||||
route_table_id = aws_route_table.main-private.id
|
||||
}
|
||||
|
||||
resource "aws_route_table_association" "main-private-3-a" {
|
||||
subnet_id = "${aws_subnet.main-private-3.id}"
|
||||
route_table_id = "${aws_route_table.main-private.id}"
|
||||
subnet_id = aws_subnet.main-private-3.id
|
||||
route_table_id = aws_route_table.main-private.id
|
||||
}
|
||||
|
||||
# nat gw
|
||||
resource "aws_eip" "nat" {
|
||||
vpc = true
|
||||
vpc = true
|
||||
}
|
||||
|
||||
resource "aws_nat_gateway" "nat-gw" {
|
||||
allocation_id = "${aws_eip.nat.id}"
|
||||
subnet_id = "${aws_subnet.main-public-1.id}"
|
||||
depends_on = ["aws_internet_gateway.main-gw"]
|
||||
allocation_id = aws_eip.nat.id
|
||||
subnet_id = aws_subnet.main-public-1.id
|
||||
depends_on = [aws_internet_gateway.main-gw]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user