-
Notifications
You must be signed in to change notification settings - Fork 7
/
vpc.tf
68 lines (54 loc) · 1.53 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
provider "aws" {
region = "${var.region}"
}
terraform {
backend "s3" {
bucket = "javahome-we-789"
key = "javahome-app/terraform.tfstate"
region = "ap-south-1"
dynamodb_table = "terraform-lock"
}
}
resource "aws_vpc" "my_vpc" {
cidr_block = "${var.vpc_cidr}"
instance_tenancy = "${var.vpc_tenancy}"
tags = "${var.vpc_tags}"
}
resource "aws_subnet" "public" {
count = "${length(local.az_names)}"
vpc_id = "${aws_vpc.my_vpc.id}"
cidr_block = "${cidrsubnet(var.vpc_cidr, 8, count.index)}"
map_public_ip_on_launch = true
availability_zone = "${local.az_names[count.index]}"
tags = {
Name = "Subnet-${count.index + 1}-${terraform.workspace}"
}
}
# Create Internet Gatewway for Public subnets
resource "aws_internet_gateway" "igw" {
vpc_id = "${aws_vpc.my_vpc.id}"
tags = {
Name = "JavaHomeIGW"
Environment = "${terraform.workspace}"
}
}
resource "aws_route_table" "pub_rt" {
vpc_id = "${aws_vpc.my_vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.igw.id}"
}
tags = {
Name = "JavaHomePubRT"
Environment = "${terraform.workspace}"
}
}
# Public subnet and route table association
resource "aws_route_table_association" "pub_rt_association" {
count = "${length(local.az_names)}"
subnet_id = "${local.pub_sub_ids[count.index]}"
route_table_id = "${aws_route_table.pub_rt.id}"
}
output "az_names" {
value = "${local.az_names}"
}