-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
112 lines (85 loc) · 2.68 KB
/
main.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
resource "aws_vpc" "this" {
cidr_block = var.aws_vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
instance_tenancy = "default"
tags = merge(var.tags, {
"Name" = format("%s-%s", var.name, "vpc")
})
}
resource "aws_internet_gateway" "this" {
vpc_id = aws_vpc.this.id
tags = merge(var.tags, {
"Name" = format("%s-%s", var.name, "igw")
})
}
resource "aws_eip" "this" {
depends_on = [
aws_internet_gateway.this
]
count = length(var.aws_azs)
vpc = true
tags = merge(var.tags, {
"Name" = format("%s-%s-%s", var.name, "eip", var.aws_azs[count.index])
})
}
resource "aws_subnet" "public" {
count = length(var.aws_public_subnets)
cidr_block = var.aws_public_subnets[count.index]
vpc_id = aws_vpc.this.id
availability_zone = var.aws_azs[count.index]
map_public_ip_on_launch = true
tags = merge(var.tags, {
"Name" = format("%s-%s-%s", var.name, "subnet-public", var.aws_azs[count.index])
"kubernetes.io/role/elb" = 1
})
}
resource "aws_subnet" "private" {
count = length(var.aws_private_subnets)
cidr_block = var.aws_private_subnets[count.index]
vpc_id = aws_vpc.this.id
availability_zone = var.aws_azs[count.index]
tags = merge(var.tags, {
"Name" = format("%s-%s-%s", var.name, "subnet-private", var.aws_azs[count.index])
"kubernetes.io/role/internal-elb" = 1
})
}
resource "aws_nat_gateway" "this" {
count = length(var.aws_azs)
allocation_id = aws_eip.this.*.id[count.index]
subnet_id = aws_subnet.public.*.id[count.index]
tags = merge(var.tags, {
"Name" = format("%s-%s-%s", var.name, "nat-gw", var.aws_azs[count.index])
})
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.this.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.this.id
}
tags = merge(var.tags, {
"Name" = format("%s-%s", var.name, "route-table-public")
})
}
resource "aws_route_table" "private" {
count = length(var.aws_azs)
vpc_id = aws_vpc.this.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.this.*.id[count.index]
}
tags = merge(var.tags, {
"Name" = format("%s-%s-%s", var.name, "route-table-private", var.aws_azs[count.index])
})
}
resource "aws_route_table_association" "public" {
count = length(var.aws_public_subnets)
route_table_id = aws_route_table.public.id
subnet_id = aws_subnet.public.*.id[count.index]
}
resource "aws_route_table_association" "private" {
count = length(var.aws_azs)
route_table_id = aws_route_table.private.*.id[count.index]
subnet_id = aws_subnet.private.*.id[count.index]
}