NEW: subnet based on map
This commit is contained in:
parent
8db5915acc
commit
74a62c702d
136
terraform/subnet-map.tf
Normal file
136
terraform/subnet-map.tf
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
variable "uat2-subnets" {
|
||||||
|
type = "map"
|
||||||
|
|
||||||
|
default = {
|
||||||
|
"0" = "UAT2-PUBLIC-01A,10.255.101.0/28,eu-west-1a"
|
||||||
|
"1" = "UAT2-PUBLIC-01B,10.255.101.16/28,eu-west-1b"
|
||||||
|
"2" = "UAT2-PUBLIC-01C,10.255.101.32/28,eu-west-1c"
|
||||||
|
"3" = "UAT2-1APP-01A,10.255.101.48/28,eu-west-1a"
|
||||||
|
"4" = "UAT2-1APP-01B,10.255.101.64/28,eu-west-1b"
|
||||||
|
"5" = "UAT2-1APP-01C,10.255.101.80/28,eu-west-1c"
|
||||||
|
"6" = "UAT2-PRIVATE-APP-01A,10.255.101.96/28,eu-west-1a"
|
||||||
|
"7" = "UAT2-PRIVATE-APP-01B,10.255.101.112/28,eu-west-1b"
|
||||||
|
"8" = "UAT2-PRIVATE-APP-01C,10.255.101.128/28,eu-west-1c"
|
||||||
|
"9" = "UAT2-PRIVATE-DB-1A,10.255.101.144/28,eu-west-1a"
|
||||||
|
"10" = "UAT2-PRIVATE-DB-1B,10.255.101.160/28,eu-west-1b"
|
||||||
|
"11" = "UAT2-PRIVATE-DB-1C,10.255.101.176/28,eu-west-1c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_subnet" "uat2-subnets-resource" {
|
||||||
|
count = "${length(var.uat2-subnets)}"
|
||||||
|
tags = "${merge(var.globalTags, map("Name",element(split(",",var.uat2-subnets[count.index]),0)))}"
|
||||||
|
vpc_id = "vpc-111"
|
||||||
|
cidr_block = "${element(split(",",var.uat2-subnets[count.index]),1)}"
|
||||||
|
availability_zone = "${element(split(",",var.uat2-subnets[count.index]),2)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Private RT
|
||||||
|
resource "aws_route_table" "PrivateRouteTable1a" {
|
||||||
|
vpc_id = "vpc-111"
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "0.0.0.0/0"
|
||||||
|
nat_gateway_id = "nat-222"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "192.168.1.0/24"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "10.254.0.0/16"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "rt-uat2-private-1a"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route_table" "PrivateRouteTable1b" {
|
||||||
|
vpc_id = "vpc-111"
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "0.0.0.0/0"
|
||||||
|
nat_gateway_id = "nat-222"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "192.168.1.0/24"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "10.254.0.0/16"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "rt-uat2-private-1b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route_table" "PrivateRouteTable1c" {
|
||||||
|
vpc_id = "vpc-111"
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "0.0.0.0/0"
|
||||||
|
nat_gateway_id = "nat-222"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "192.168.1.0/24"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "10.254.0.0/16"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "rt-uat2-private-1c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Public RT
|
||||||
|
resource "aws_route_table" "PublicRouteTable" {
|
||||||
|
vpc_id = "vpc-111"
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "0.0.0.0/0"
|
||||||
|
gateway_id = "igw-111"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "192.168.1.0/24"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "10.254.0.0/16"
|
||||||
|
network_interface_id = "eni-333"
|
||||||
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
Name = "rt-uat2-public"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Associate Public RT
|
||||||
|
resource "aws_route_table_association" "PublicRTAsso" {
|
||||||
|
subnet_id = "${element(aws_subnet.uat2-subnets-resource.*.id, count.index)}"
|
||||||
|
route_table_id = "${aws_route_table.PublicRouteTable.id}"
|
||||||
|
|
||||||
|
count = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
# Associate Private RT
|
||||||
|
resource "aws_route_table_association" "PrivateRTAsso" {
|
||||||
|
subnet_id = "${element(aws_subnet.uat2-subnets-resource.*.id, count.index+3)}"
|
||||||
|
route_table_id = "${aws_route_table.PrivateRouteTable1a.id}"
|
||||||
|
|
||||||
|
count = 9
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user