-
Notifications
You must be signed in to change notification settings - Fork 2
/
vpc.tf
141 lines (122 loc) · 5.53 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
resource "aws_vpc" "etleap" {
count = local.created_vpc_count
tags = merge({Name = "Etleap VPC ${var.deployment_id}"}, local.default_tags)
cidr_block = local.vpc_cidr_block
enable_dns_hostnames = true
}
resource "aws_internet_gateway" "etleap" {
count = local.created_vpc_count
tags = merge({Name = "Etleap IG"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
}
resource "aws_route_table" "private" {
count = local.created_vpc_count
tags = merge({Name = "Etleap Private ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
}
resource "aws_route_table" "public" {
count = local.created_vpc_count
tags = merge({Name = "Etleap Public ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
}
resource "aws_route" "private" {
count = local.created_vpc_count
route_table_id = aws_route_table.private[0].id
destination_cidr_block = "0.0.0.0/0"
network_interface_id = aws_instance.nat[0].primary_network_interface_id
}
resource "aws_route" "prod_public" {
count = local.created_vpc_count
route_table_id = aws_route_table.public[0].id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.etleap[0].id
}
resource "aws_subnet" "a_private" {
count = local.created_vpc_count
tags = merge({Name = "Etleap A Private ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
cidr_block = "${var.vpc_cidr_block_1}.${var.vpc_cidr_block_2}.${var.vpc_cidr_block_3 + 0}.0/24"
availability_zone = "${local.region}a"
}
resource "aws_subnet" "b_private" {
count = local.created_vpc_count
tags = merge({Name = "Etleap B Private ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
cidr_block = "${var.vpc_cidr_block_1}.${var.vpc_cidr_block_2}.${var.vpc_cidr_block_3 + 1}.0/24"
availability_zone = "${local.region}b"
}
resource "aws_subnet" "c_private" {
count = local.created_vpc_count
tags = merge({Name = "Etleap C Private ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
cidr_block = "${var.vpc_cidr_block_1}.${var.vpc_cidr_block_2}.${var.vpc_cidr_block_3 + 2}.0/24"
availability_zone = "${local.region}c"
}
resource "aws_subnet" "a_public" {
count = local.created_vpc_count
tags = merge({Name = "Etleap A Public ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
cidr_block = "${var.vpc_cidr_block_1}.${var.vpc_cidr_block_2}.${var.vpc_cidr_block_3 + 3}.0/26"
availability_zone = "${local.region}a"
}
resource "aws_subnet" "b_public" {
count = local.created_vpc_count
tags = merge({Name = "Etleap B Public ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
cidr_block = "${var.vpc_cidr_block_1}.${var.vpc_cidr_block_2}.${var.vpc_cidr_block_3 + 3}.64/26"
availability_zone = "${local.region}b"
}
resource "aws_subnet" "c_public" {
count = local.created_vpc_count
tags = merge({Name = "Etleap C Public ${var.deployment_id}"}, local.default_tags)
vpc_id = aws_vpc.etleap[0].id
cidr_block = "${var.vpc_cidr_block_1}.${var.vpc_cidr_block_2}.${var.vpc_cidr_block_3 + 3}.128/26"
availability_zone = "${local.region}c"
}
resource "aws_route_table_association" "a_private" {
count = local.created_vpc_count
subnet_id = aws_subnet.a_private[0].id
route_table_id = aws_route_table.private[0].id
}
resource "aws_route_table_association" "b_private" {
count = local.created_vpc_count
subnet_id = aws_subnet.b_private[0].id
route_table_id = aws_route_table.private[0].id
}
resource "aws_route_table_association" "c_private" {
count = local.created_vpc_count
subnet_id = aws_subnet.c_private[0].id
route_table_id = aws_route_table.private[0].id
}
resource "aws_route_table_association" "a_public" {
count = local.created_vpc_count
subnet_id = aws_subnet.a_public[0].id
route_table_id = aws_route_table.public[0].id
}
resource "aws_route_table_association" "b_public" {
count = local.created_vpc_count
subnet_id = aws_subnet.b_public[0].id
route_table_id = aws_route_table.public[0].id
}
resource "aws_route_table_association" "c_public" {
count = local.created_vpc_count
subnet_id = aws_subnet.c_public[0].id
route_table_id = aws_route_table.public[0].id
}
locals {
vpc_id = var.vpc_id == null ? aws_vpc.etleap[0].id : var.vpc_id
subnet_a_private_id = var.vpc_id == null ? aws_subnet.a_private[0].id : var.private_subnets[0]
subnet_b_private_id = var.vpc_id == null ? aws_subnet.b_private[0].id : var.private_subnets[1]
subnet_c_private_id = var.vpc_id == null ? aws_subnet.c_private[0].id : var.private_subnets[2]
subnet_a_public_id = var.vpc_id == null ? aws_subnet.a_public[0].id : var.public_subnets[0]
subnet_b_public_id = var.vpc_id == null ? aws_subnet.b_public[0].id : var.public_subnets[1]
subnet_c_public_id = var.vpc_id == null ? aws_subnet.c_public[0].id : var.public_subnets[2]
created_vpc_count = var.vpc_id == null ? 1 : 0
}
resource "aws_ssm_parameter" "vpc_cidr" {
name = local.vpc_cidr_block_config_name
tags = local.default_tags
description = "Etleap ${var.deployment_id} - VPC CIDR"
type = "String"
value = local.vpc_cidr_block
}