forked from idealo/terraform-aws-mwaa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
103 lines (94 loc) · 2.99 KB
/
vpc.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
This module deploys a VPC, with a pair of public and private subnets spread
across two Availability Zones. It deploys an internet gateway, with a default
route on the public subnets. It deploys a pair of NAT gateways (one in each
AZ), and default routes for them in the private subnets.
*/
resource "aws_subnet" "public" {
count = var.create_networking_config ? length(var.public_subnet_cidrs): 0
cidr_block = var.public_subnet_cidrs[count.index]
vpc_id = var.vpc_id
map_public_ip_on_launch = true
availability_zone = count.index % 2 == 0 ? "${var.region}a" : "${var.region}b"
tags = merge({
Name = "mwaa-${var.environment_name}-public-subnet-${count.index}"
}, var.tags)
}
resource "aws_subnet" "private" {
count = var.create_networking_config ? length(var.private_subnet_cidrs): 0
cidr_block = var.private_subnet_cidrs[count.index]
vpc_id = var.vpc_id
map_public_ip_on_launch = false
availability_zone = count.index % 2 == 0 ? "${var.region}a" : "${var.region}b"
tags = merge({
Name = "mwaa-${var.environment_name}-private-subnet-${count.index}"
}, var.tags)
}
resource "aws_eip" "this" {
count = var.create_networking_config ? length(var.public_subnet_cidrs): 0
vpc = true
tags = merge({
Name = "mwaa-${var.environment_name}-eip-${count.index}"
}, var.tags)
}
resource "aws_nat_gateway" "this" {
count = var.create_networking_config ? length(var.public_subnet_cidrs): 0
allocation_id = aws_eip.this[count.index].id
subnet_id = aws_subnet.public[count.index].id
tags = merge({
Name = "mwaa-${var.environment_name}-nat-gateway-${count.index}"
}, var.tags)
}
resource "aws_route_table" "public" {
count = var.create_networking_config ? 1: 0
vpc_id = var.vpc_id
route {
cidr_block = "0.0.0.0/0"
gateway_id = var.internet_gateway_id
}
tags = merge({
Name = "mwaa-${var.environment_name}-public-routes"
}, var.tags)
}
resource "aws_route_table_association" "public" {
count = var.create_networking_config ? length(aws_subnet.public): 0
route_table_id = aws_route_table.public[0].id
subnet_id = aws_subnet.public[count.index].id
}
resource "aws_route_table" "private" {
count = length(aws_nat_gateway.this)
vpc_id = var.vpc_id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.this[count.index].id
}
tags = merge({
Name = "mwaa-${var.environment_name}-private-routes-a"
}, var.tags)
}
resource "aws_route_table_association" "private" {
count = var.create_networking_config ? length(aws_subnet.private): 0
route_table_id = aws_route_table.private[count.index].id
subnet_id = aws_subnet.private[count.index].id
}
resource "aws_security_group" "this" {
vpc_id = var.vpc_id
name = "mwaa-${var.environment_name}-no-ingress-sg"
tags = merge({
Name = "mwaa-${var.environment_name}-no-ingress-sg"
}, var.tags )
ingress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0"
]
}
}