-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws_vpc.tf
54 lines (47 loc) · 1.43 KB
/
aws_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
# Resource: aws_vpc (provides a VPC resource)
# and associated resources for vpc.
# Create a VPC
resource "aws_vpc" "redis_cluster_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = format("%s-%s-cluster-vpc", var.base_name, var.region),
Owner = var.owner
}
}
# Create private subnet
resource "aws_subnet" "re_subnet" {
vpc_id = aws_vpc.redis_cluster_vpc.id # requires the vpc id from the vpc resource
cidr_block = var.subnet_cidr_block
availability_zone = var.subnet_az
tags = {
Name = format("%s-subnet1", var.base_name),
Owner = var.owner
}
}
# network
# Create Internet Gateway (enables your vpc to connect to the internet)
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.redis_cluster_vpc.id
tags = {
Name = format("%s-igw", var.base_name),
Owner = var.owner
}
}
# Create a custom route table
# (custom route table for the subnet. Subnet can reach the internet using this)
resource "aws_default_route_table" "route_table" {
default_route_table_id = aws_vpc.redis_cluster_vpc.default_route_table_id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = {
Name = format("%s-rt", var.base_name),
Owner = var.owner
}
}
# assocaite the route table to the subnet.
resource "aws_route_table_association" "subnet_association" {
subnet_id = aws_subnet.re_subnet.id
route_table_id = aws_default_route_table.route_table.id
}