|
| 1 | +#tfsec:ignore:aws-ec2-require-vpc-flow-logs-for-all-vpcs |
| 2 | +resource "aws_vpc" "main" { |
| 3 | + cidr_block = "10.0.0.0/16" |
| 4 | + |
| 5 | + tags = { |
| 6 | + Name = "SOAT Tech Challenge VPC" |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +resource "aws_subnet" "public_subnets" { |
| 11 | + count = length(var.private_subnet_cidrs) |
| 12 | + |
| 13 | + vpc_id = aws_vpc.main.id |
| 14 | + cidr_block = element(var.public_subnet_cidrs, count.index) |
| 15 | + availability_zone = element(local.azs, count.index) |
| 16 | + |
| 17 | + tags = { |
| 18 | + Name = "SOAT-TC Public Subnet ${count.index + 1}" |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +resource "aws_subnet" "private_subnets" { |
| 23 | + count = length(var.private_subnet_cidrs) |
| 24 | + |
| 25 | + vpc_id = aws_vpc.main.id |
| 26 | + cidr_block = element(var.private_subnet_cidrs, count.index) |
| 27 | + availability_zone = element(local.azs, count.index) |
| 28 | + |
| 29 | + tags = { |
| 30 | + Name = "SOAT-TC Private Subnet ${count.index + 1}" |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +resource "aws_internet_gateway" "main" { |
| 36 | + vpc_id = aws_vpc.main.id |
| 37 | + |
| 38 | + tags = { |
| 39 | + Name = "SOAT-TC Internet Gateway" |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +resource "aws_route_table" "public_rt" { |
| 44 | + vpc_id = aws_vpc.main.id |
| 45 | + |
| 46 | + |
| 47 | + route { |
| 48 | + cidr_block = "0.0.0.0/0" |
| 49 | + gateway_id = aws_internet_gateway.main.id |
| 50 | + } |
| 51 | + |
| 52 | + tags = { |
| 53 | + Name = "SOAT-TC Public Route Table" |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +resource "aws_route_table" "private_rt" { |
| 58 | + vpc_id = aws_vpc.main.id |
| 59 | + |
| 60 | + tags = { |
| 61 | + Name = "SOAT-TC Private Route Table" |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +resource "aws_route_table_association" "public_rt_association" { |
| 66 | + count = length(var.public_subnet_cidrs) |
| 67 | + subnet_id = element(aws_subnet.public_subnets[*].id, count.index) |
| 68 | + route_table_id = aws_route_table.public_rt.id |
| 69 | +} |
| 70 | + |
| 71 | +resource "aws_route_table_association" "private_rt_association" { |
| 72 | + count = length(var.private_subnet_cidrs) |
| 73 | + subnet_id = element(aws_subnet.private_subnets[*].id, count.index) |
| 74 | + route_table_id = aws_route_table.private_rt.id |
| 75 | +} |
0 commit comments