-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpc.tf
More file actions
65 lines (51 loc) · 1.65 KB
/
vpc.tf
File metadata and controls
65 lines (51 loc) · 1.65 KB
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
# Create a VPC
resource "aws_vpc" "vprofileapp_vpc" {
cidr_block = var.cidr_block
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "VProfile-App-Vpc"
}
}
resource "aws_internet_gateway" "my_igw" {
vpc_id = aws_vpc.vprofileapp_vpc.id
tags = {
Name = "VProfile-App-Igw"
}
}
# Create Route Table
resource "aws_route_table" "my_route_table" {
vpc_id = aws_vpc.vprofileapp_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.my_igw.id
}
tags = {
Name = "VProfile-App-RouteTable"
}
}
resource "aws_route_table_association" "public_subnet_association" {
count = length(aws_subnet.public_subnets)
subnet_id = aws_subnet.public_subnets[count.index].id
route_table_id = aws_route_table.my_route_table.id
}
# Create Public Subnets
resource "aws_subnet" "public_subnets" {
count = length(var.public_subnet_cidr_blocks)
vpc_id = aws_vpc.vprofileapp_vpc.id
cidr_block = var.public_subnet_cidr_blocks[count.index]
availability_zone = var.availability_zone[count.index] # Replace with your desired availability zone
tags = {
Name = "VprofileApp-PublicSubnet-${count.index}"
}
}
# Create Private Subnets
resource "aws_subnet" "private_subnets" {
count = length(var.private_subnet_cidr_blocks)
vpc_id = aws_vpc.vprofileapp_vpc.id
cidr_block = var.private_subnet_cidr_blocks[count.index]
availability_zone = var.availability_zone[0] # Replace with your desired availability zone
tags = {
Name = "VProfileApp-PrivateSubnet-${count.index}"
}
}