-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpc.tf
76 lines (59 loc) · 1.82 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
# make a VPC
resource "aws_vpc" "the_vpc" {
cidr_block = "${var.first-2-octets}.0.0/16"
enable_dns_hostnames = "true"
enable_dns_support = "true"
assign_generated_ipv6_cidr_block = "true"
tags {
Name = "${var.tag_prefix}-vpc"
}
}
# make an internet gateway
resource "aws_internet_gateway" "the_vpc_igw" {
vpc_id = "${aws_vpc.the_vpc.id}"
tags {
Name = "${var.tag_prefix}-igw"
}
}
# route access to the internet through IGW
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.the_vpc.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.the_vpc_igw.id}"
}
# create vpc-endpoint for EC2
resource "aws_vpc_endpoint" "ec2" {
vpc_id = "${aws_vpc.the_vpc.id}"
service_name = "com.amazonaws.${var.aws_region}.ec2"
private_dns_enabled = "true"
vpc_endpoint_type = "Interface"
security_group_ids = [
"${aws_security_group.private-endpoint-sg.id}",
]
subnet_ids = [
"${aws_subnet.private-a.id}",
"${aws_subnet.private-b.id}",
"${aws_subnet.private-c.id}",
]
}
# create vpc-endpoint for S3
resource "aws_vpc_endpoint" "s3" {
vpc_id = "${aws_vpc.the_vpc.id}"
service_name = "com.amazonaws.${var.aws_region}.s3"
route_table_ids = ["${aws_vpc.the_vpc.main_route_table_id}"]
}
# create vpc-endpoint for SSM
resource "aws_vpc_endpoint" "ssm" {
vpc_id = "${aws_vpc.the_vpc.id}"
service_name = "com.amazonaws.${var.aws_region}.ssm"
private_dns_enabled = "true"
vpc_endpoint_type = "Interface"
security_group_ids = [
"${aws_security_group.private-endpoint-sg.id}",
]
subnet_ids = [
"${aws_subnet.private-a.id}",
"${aws_subnet.private-b.id}",
"${aws_subnet.private-c.id}",
]
}