mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-22 07:01:56 +03:00
@@ -1,18 +1,18 @@
|
||||
data "template_file" "jenkins-init" {
|
||||
template = "${file("scripts/jenkins-init.sh")}"
|
||||
vars {
|
||||
DEVICE = "${var.INSTANCE_DEVICE_NAME}"
|
||||
JENKINS_VERSION = "${var.JENKINS_VERSION}"
|
||||
template = file("scripts/jenkins-init.sh")
|
||||
vars = {
|
||||
DEVICE = var.INSTANCE_DEVICE_NAME
|
||||
JENKINS_VERSION = var.JENKINS_VERSION
|
||||
}
|
||||
}
|
||||
data "template_cloudinit_config" "cloudinit-jenkins" {
|
||||
|
||||
gzip = false
|
||||
data "template_cloudinit_config" "cloudinit-jenkins" {
|
||||
gzip = false
|
||||
base64_encode = false
|
||||
|
||||
part {
|
||||
content_type = "text/x-shellscript"
|
||||
content = "${data.template_file.jenkins-init.rendered}"
|
||||
content = data.template_file.jenkins-init.rendered
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
resource "aws_ecr_repository" "myapp" {
|
||||
name = "myapp"
|
||||
}
|
||||
|
||||
|
||||
+21
-18
@@ -1,28 +1,31 @@
|
||||
# cluster
|
||||
resource "aws_ecs_cluster" "example-cluster" {
|
||||
name = "example-cluster"
|
||||
name = "example-cluster"
|
||||
}
|
||||
|
||||
resource "aws_launch_configuration" "ecs-example-launchconfig" {
|
||||
name_prefix = "ecs-launchconfig"
|
||||
image_id = "${lookup(var.ECS_AMIS, var.AWS_REGION)}"
|
||||
instance_type = "${var.ECS_INSTANCE_TYPE}"
|
||||
key_name = "${aws_key_pair.mykeypair.key_name}"
|
||||
iam_instance_profile = "${aws_iam_instance_profile.ecs-ec2-role.id}"
|
||||
security_groups = ["${aws_security_group.ecs-securitygroup.id}"]
|
||||
image_id = var.ECS_AMIS[var.AWS_REGION]
|
||||
instance_type = var.ECS_INSTANCE_TYPE
|
||||
key_name = aws_key_pair.mykeypair.key_name
|
||||
iam_instance_profile = aws_iam_instance_profile.ecs-ec2-role.id
|
||||
security_groups = [aws_security_group.ecs-securitygroup.id]
|
||||
user_data = "#!/bin/bash\necho 'ECS_CLUSTER=example-cluster' > /etc/ecs/ecs.config\nstart ecs"
|
||||
lifecycle { create_before_destroy = true }
|
||||
}
|
||||
resource "aws_autoscaling_group" "ecs-example-autoscaling" {
|
||||
name = "ecs-example-autoscaling"
|
||||
vpc_zone_identifier = ["${aws_subnet.main-public-1.id}", "${aws_subnet.main-public-2.id}"]
|
||||
launch_configuration = "${aws_launch_configuration.ecs-example-launchconfig.name}"
|
||||
min_size = 1
|
||||
max_size = 1
|
||||
tag {
|
||||
key = "Name"
|
||||
value = "ecs-ec2-container"
|
||||
propagate_at_launch = true
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_autoscaling_group" "ecs-example-autoscaling" {
|
||||
name = "ecs-example-autoscaling"
|
||||
vpc_zone_identifier = [aws_subnet.main-public-1.id, aws_subnet.main-public-2.id]
|
||||
launch_configuration = aws_launch_configuration.ecs-example-launchconfig.name
|
||||
min_size = 1
|
||||
max_size = 1
|
||||
tag {
|
||||
key = "Name"
|
||||
value = "ecs-ec2-container"
|
||||
propagate_at_launch = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-14
@@ -1,7 +1,7 @@
|
||||
# ecs ec2 role
|
||||
resource "aws_iam_role" "ecs-ec2-role" {
|
||||
name = "ecs-ec2-role"
|
||||
assume_role_policy = <<EOF
|
||||
name = "ecs-ec2-role"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -16,15 +16,17 @@ resource "aws_iam_role" "ecs-ec2-role" {
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
resource "aws_iam_instance_profile" "ecs-ec2-role" {
|
||||
name = "ecs-ec2-role"
|
||||
role = "${aws_iam_role.ecs-ec2-role.name}"
|
||||
name = "ecs-ec2-role"
|
||||
role = aws_iam_role.ecs-ec2-role.name
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "ecs-consul-server-role" {
|
||||
name = "ecs-consul-server-role"
|
||||
assume_role_policy = <<EOF
|
||||
name = "ecs-consul-server-role"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -39,12 +41,13 @@ resource "aws_iam_role" "ecs-consul-server-role" {
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "ecs-ec2-role-policy" {
|
||||
name = "ecs-ec2-role-policy"
|
||||
role = "${aws_iam_role.ecs-ec2-role.id}"
|
||||
policy = <<EOF
|
||||
name = "ecs-ec2-role-policy"
|
||||
role = aws_iam_role.ecs-ec2-role.id
|
||||
policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -83,12 +86,13 @@ resource "aws_iam_role_policy" "ecs-ec2-role-policy" {
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# ecs service role
|
||||
resource "aws_iam_role" "ecs-service-role" {
|
||||
name = "ecs-service-role"
|
||||
assume_role_policy = <<EOF
|
||||
name = "ecs-service-role"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -103,11 +107,12 @@ resource "aws_iam_role" "ecs-service-role" {
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
resource "aws_iam_policy_attachment" "ecs-service-attach1" {
|
||||
name = "ecs-service-attach1"
|
||||
roles = ["${aws_iam_role.ecs-service-role.name}"]
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
|
||||
name = "ecs-service-attach1"
|
||||
roles = [aws_iam_role.ecs-service-role.name]
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
|
||||
}
|
||||
|
||||
|
||||
+14
-15
@@ -1,33 +1,32 @@
|
||||
resource "aws_instance" "jenkins-instance" {
|
||||
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
|
||||
ami = var.AMIS[var.AWS_REGION]
|
||||
instance_type = "t2.small"
|
||||
|
||||
# the VPC subnet
|
||||
subnet_id = "${aws_subnet.main-public-1.id}"
|
||||
subnet_id = aws_subnet.main-public-1.id
|
||||
|
||||
# the security group
|
||||
vpc_security_group_ids = ["${aws_security_group.jenkins-securitygroup.id}"]
|
||||
vpc_security_group_ids = [aws_security_group.jenkins-securitygroup.id]
|
||||
|
||||
# the public SSH key
|
||||
key_name = "${aws_key_pair.mykeypair.key_name}"
|
||||
key_name = aws_key_pair.mykeypair.key_name
|
||||
|
||||
# user data
|
||||
user_data = "${data.template_cloudinit_config.cloudinit-jenkins.rendered}"
|
||||
|
||||
user_data = data.template_cloudinit_config.cloudinit-jenkins.rendered
|
||||
}
|
||||
|
||||
resource "aws_ebs_volume" "jenkins-data" {
|
||||
availability_zone = "eu-west-1a"
|
||||
size = 20
|
||||
type = "gp2"
|
||||
tags {
|
||||
Name = "jenkins-data"
|
||||
}
|
||||
availability_zone = "eu-west-1a"
|
||||
size = 20
|
||||
type = "gp2"
|
||||
tags = {
|
||||
Name = "jenkins-data"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_volume_attachment" "jenkins-data-attachment" {
|
||||
device_name = "${var.INSTANCE_DEVICE_NAME}"
|
||||
volume_id = "${aws_ebs_volume.jenkins-data.id}"
|
||||
instance_id = "${aws_instance.jenkins-instance.id}"
|
||||
device_name = var.INSTANCE_DEVICE_NAME
|
||||
volume_id = aws_ebs_volume.jenkins-data.id
|
||||
instance_id = aws_instance.jenkins-instance.id
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
variable "MYAPP_SERVICE_ENABLE" { default = "0" }
|
||||
variable "MYAPP_VERSION" { default = "0" }
|
||||
variable "MYAPP_SERVICE_ENABLE" {
|
||||
default = "0"
|
||||
}
|
||||
|
||||
variable "MYAPP_VERSION" {
|
||||
default = "0"
|
||||
}
|
||||
|
||||
|
||||
+29
-27
@@ -1,33 +1,35 @@
|
||||
# app
|
||||
|
||||
data "template_file" "myapp-task-definition-template" {
|
||||
template = "${file("templates/app.json.tpl")}"
|
||||
vars {
|
||||
REPOSITORY_URL = "${replace("${aws_ecr_repository.myapp.repository_url}", "https://", "")}"
|
||||
APP_VERSION = "${var.MYAPP_VERSION}"
|
||||
template = file("templates/app.json.tpl")
|
||||
vars = {
|
||||
REPOSITORY_URL = replace(aws_ecr_repository.myapp.repository_url, "https://", "")
|
||||
APP_VERSION = var.MYAPP_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_ecs_task_definition" "myapp-task-definition" {
|
||||
family = "myapp"
|
||||
container_definitions = "${data.template_file.myapp-task-definition-template.rendered}"
|
||||
container_definitions = data.template_file.myapp-task-definition-template.rendered
|
||||
}
|
||||
|
||||
resource "aws_ecs_service" "myapp-service" {
|
||||
count = "${var.MYAPP_SERVICE_ENABLE}"
|
||||
name = "myapp"
|
||||
cluster = "${aws_ecs_cluster.example-cluster.id}"
|
||||
task_definition = "${aws_ecs_task_definition.myapp-task-definition.arn}"
|
||||
desired_count = 1
|
||||
iam_role = "${aws_iam_role.ecs-service-role.arn}"
|
||||
depends_on = ["aws_iam_policy_attachment.ecs-service-attach1"]
|
||||
count = var.MYAPP_SERVICE_ENABLE
|
||||
name = "myapp"
|
||||
cluster = aws_ecs_cluster.example-cluster.id
|
||||
task_definition = aws_ecs_task_definition.myapp-task-definition.arn
|
||||
desired_count = 1
|
||||
iam_role = aws_iam_role.ecs-service-role.arn
|
||||
depends_on = [aws_iam_policy_attachment.ecs-service-attach1]
|
||||
|
||||
load_balancer {
|
||||
elb_name = "${aws_elb.myapp-elb.name}"
|
||||
elb_name = aws_elb.myapp-elb.name
|
||||
container_name = "myapp"
|
||||
container_port = 3000
|
||||
}
|
||||
lifecycle { ignore_changes = ["task_definition"] }
|
||||
lifecycle {
|
||||
ignore_changes = [task_definition]
|
||||
}
|
||||
}
|
||||
|
||||
# load balancer
|
||||
@@ -35,29 +37,29 @@ resource "aws_elb" "myapp-elb" {
|
||||
name = "myapp-elb"
|
||||
|
||||
listener {
|
||||
instance_port = 3000
|
||||
instance_port = 3000
|
||||
instance_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
}
|
||||
|
||||
health_check {
|
||||
healthy_threshold = 3
|
||||
healthy_threshold = 3
|
||||
unhealthy_threshold = 3
|
||||
timeout = 30
|
||||
target = "HTTP:3000/"
|
||||
interval = 60
|
||||
timeout = 30
|
||||
target = "HTTP:3000/"
|
||||
interval = 60
|
||||
}
|
||||
|
||||
cross_zone_load_balancing = true
|
||||
idle_timeout = 400
|
||||
connection_draining = true
|
||||
cross_zone_load_balancing = true
|
||||
idle_timeout = 400
|
||||
connection_draining = true
|
||||
connection_draining_timeout = 400
|
||||
|
||||
subnets = ["${aws_subnet.main-public-1.id}","${aws_subnet.main-public-2.id}"]
|
||||
security_groups = ["${aws_security_group.myapp-elb-securitygroup.id}"]
|
||||
subnets = [aws_subnet.main-public-1.id, aws_subnet.main-public-2.id]
|
||||
security_groups = [aws_security_group.myapp-elb-securitygroup.id]
|
||||
|
||||
tags {
|
||||
tags = {
|
||||
Name = "myapp-elb"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
output "elb" {
|
||||
value = "${aws_elb.myapp-elb.dns_name}"
|
||||
value = aws_elb.myapp-elb.dns_name
|
||||
}
|
||||
|
||||
output "jenkins" {
|
||||
value = "${aws_instance.jenkins-instance.public_ip}"
|
||||
value = aws_instance.jenkins-instance.public_ip
|
||||
}
|
||||
|
||||
output "myapp-repository-URL" {
|
||||
value = "${aws_ecr_repository.myapp.repository_url}"
|
||||
value = aws_ecr_repository.myapp.repository_url
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
provider "aws" {
|
||||
region = "${var.AWS_REGION}"
|
||||
provider "aws" {
|
||||
region = var.AWS_REGION
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -1,8 +1,9 @@
|
||||
resource "aws_s3_bucket" "terraform-state" {
|
||||
bucket = "terraform-state-a2b6219"
|
||||
acl = "private"
|
||||
bucket = "terraform-state-a2b6219"
|
||||
acl = "private"
|
||||
|
||||
tags {
|
||||
Name = "Terraform state"
|
||||
}
|
||||
tags = {
|
||||
Name = "Terraform state"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,76 +1,79 @@
|
||||
resource "aws_security_group" "ecs-securitygroup" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
name = "ecs"
|
||||
vpc_id = aws_vpc.main.id
|
||||
name = "ecs"
|
||||
description = "security group for ecs"
|
||||
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 = 3000
|
||||
to_port = 3000
|
||||
protocol = "tcp"
|
||||
security_groups = ["${aws_security_group.myapp-elb-securitygroup.id}"]
|
||||
}
|
||||
from_port = 3000
|
||||
to_port = 3000
|
||||
protocol = "tcp"
|
||||
security_groups = [aws_security_group.myapp-elb-securitygroup.id]
|
||||
}
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
tags {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
tags = {
|
||||
Name = "ecs"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "myapp-elb-securitygroup" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
name = "myapp-elb"
|
||||
vpc_id = aws_vpc.main.id
|
||||
name = "myapp-elb"
|
||||
description = "security group for ecs"
|
||||
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 = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
tags {
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
tags = {
|
||||
Name = "myapp-elb"
|
||||
}
|
||||
}
|
||||
|
||||
# jenkins
|
||||
resource "aws_security_group" "jenkins-securitygroup" {
|
||||
vpc_id = "${aws_vpc.main.id}"
|
||||
name = "jenkins-securitygroup"
|
||||
vpc_id = aws_vpc.main.id
|
||||
name = "jenkins-securitygroup"
|
||||
description = "security group that allows ssh and all egress traffic"
|
||||
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"]
|
||||
}
|
||||
ingress {
|
||||
from_port = 8080
|
||||
to_port = 8080
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
tags {
|
||||
from_port = 8080
|
||||
to_port = 8080
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
tags = {
|
||||
Name = "jenkins-securitygroup"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,43 @@
|
||||
variable "AWS_REGION" {
|
||||
default = "eu-west-1"
|
||||
}
|
||||
|
||||
variable "PATH_TO_PRIVATE_KEY" {
|
||||
default = "mykey"
|
||||
}
|
||||
|
||||
variable "PATH_TO_PUBLIC_KEY" {
|
||||
default = "mykey.pub"
|
||||
}
|
||||
|
||||
variable "ECS_INSTANCE_TYPE" {
|
||||
default = "t2.micro"
|
||||
}
|
||||
|
||||
variable "ECS_AMIS" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
default = {
|
||||
us-east-1 = "ami-1924770e"
|
||||
us-west-2 = "ami-56ed4936"
|
||||
eu-west-1 = "ami-c8337dbb"
|
||||
}
|
||||
}
|
||||
|
||||
# Full List: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html
|
||||
|
||||
variable "AMIS" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
default = {
|
||||
us-east-1 = "ami-13be557e"
|
||||
us-west-2 = "ami-06b94666"
|
||||
eu-west-1 = "ami-844e0bf7"
|
||||
}
|
||||
}
|
||||
|
||||
variable "INSTANCE_DEVICE_NAME" {
|
||||
default = "/dev/xvdh"
|
||||
}
|
||||
|
||||
variable "JENKINS_VERSION" {
|
||||
default = "2.73.2"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
terraform {
|
||||
required_version = ">= 0.12"
|
||||
}
|
||||
+77
-70
@@ -1,110 +1,117 @@
|
||||
# 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}"
|
||||
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}"
|
||||
subnet_id = aws_subnet.main-public-3.id
|
||||
route_table_id = aws_route_table.main-public.id
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user