-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
71 lines (61 loc) · 1.62 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
data "aws_vpc" "kubernetes" {
id = local.create_vpc ? aws_vpc.kubernetes[0].id : var.vpc_id
}
resource "aws_vpc" "kubernetes" {
count = local.create_vpc ? 1 : 0
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
assign_generated_ipv6_cidr_block = true
tags = {
Name = "${local.friendly_name} VPC"
CostCenter = var.cost_center
}
}
#default sg
resource "aws_default_security_group" "kubernetes" {
count = local.create_vpc ? 1 : 0
vpc_id = aws_vpc.kubernetes[0].id
ingress {
protocol = -1
self = true
from_port = 0
to_port = 0
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# Internet gateway and routing for public items
resource "aws_internet_gateway" "gw" {
count = local.create_vpc ? 1 : 0
vpc_id = aws_vpc.kubernetes[0].id
tags = {
Name = "${local.friendly_name} Internet Gateway"
}
}
# find out what the gateway is if we didn't create it
data "aws_internet_gateway" "default_gateway" {
filter {
name = "attachment.vpc-id"
values = [data.aws_vpc.kubernetes.id]
}
}
# reference to the default routing table
data "aws_route_table" "default" {
vpc_id = data.aws_vpc.kubernetes.id
filter {
name = "association.main"
values = [true]
}
}
# use the gateway to get to the internet
resource "aws_route" "internet" {
count = local.create_vpc ? 1 : 0
route_table_id = data.aws_route_table.default.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw[0].id
}