forked from NagireddyGuduru/terraform-project
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvpc.tf
54 lines (42 loc) · 1.22 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
# VPC for our applications
resource "aws_vpc" "javahome_vpc" {
cidr_block = "${var.vpc_cidr}"
tags {
Name = "JavaHomeVPC"
}
}
# Create Internet Gateway and attach it to javahome_vpc
resource "aws_internet_gateway" "javahome_igw" {
vpc_id = "${aws_vpc.javahome_vpc.id}"
tags {
Name = "main"
}
}
# Build subnets for our VPCs
resource "aws_subnet" "public" {
count = "${length(var.subnets_cidr)}"
vpc_id = "${aws_vpc.javahome_vpc.id}"
availability_zone = "${element(var.azs,count.index)}"
cidr_block = "${element(var.subnets_cidr,count.index)}"
map_public_ip_on_launch = true
tags {
Name = "Subnet-${count.index +1}"
}
}
# Create Route table, attache Internet Gateway and associate with public subnets
resource "aws_route_table" "public_rt" {
vpc_id = "${aws_vpc.javahome_vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.javahome_igw.id}"
}
tags {
Name = "PublicRT"
}
}
# Attach route table with public subnets
resource "aws_route_table_association" "a" {
count = "${length(var.subnets_cidr)}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
route_table_id = "${aws_route_table.public_rt.id}"
}