-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc.tf
48 lines (36 loc) · 1.23 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
data "aws_availability_zones" "available" {}
resource "aws_vpc" "vpc" {
cidr_block = "${var.cidr["A"]}.${var.cidr["B"]}.${var.cidr["C"]}.${var.cidr["D"]}/${var.cidr["NET"]}"
tags = {
"Name" = var.vpc_name
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
}
}
resource "aws_subnet" "subnet" {
count = var.subnet_count
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = "${var.cidr["A"]}.${var.cidr["B"]}.${count.index}.${var.cidr["D"]}/${var.subnet_netbit}"
vpc_id = aws_vpc.vpc.id
tags = {
"Name" = "${var.subnet_name}-${count.index}"
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
}
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = var.igw_name
}
}
resource "aws_route_table" "rt-table" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
}
resource "aws_route_table_association" "rt-table-assoc" {
count = var.subnet_count
subnet_id = aws_subnet.subnet[count.index].id
route_table_id = aws_route_table.rt-table.id
}