forked from MithunTechnologiesDevOps/Terraform_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
49 lines (47 loc) · 1.17 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
# Provider
provider "aws" {
region = "ap-south-1"
}
# VPC
resource "aws_vpc" "vpc" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
tags = {
Name = "demo_vpc"
}
}
# IGW for demo_vpc
resource "aws_internet_gateway" "vpc_igw" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "demo_vpc_igw"
}
}
# Subenets in demo_vpc
resource "aws_subnet" "subnets" {
count = length(var.subnets_cidr)
vpc_id = aws_vpc.vpc.id
cidr_block = element(var.subnets_cidr, count.index)
availability_zone = element(var.availability_zones, count.index)
map_public_ip_on_launch = true
tags = {
Name = "demo_vpc_subnet_${count.index + 1}"
}
}
# Route table for demo_vpc
resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.vpc_igw.id
}
tags = {
Name = "demo_vpc_public_rt"
}
}
# Route table and subnets assocation
resource "aws_route_table_association" "rt_sub_association" {
count = length(var.subnets_cidr)
subnet_id = element(aws_subnet.subnets.*.id, count.index)
route_table_id = aws_route_table.public_rt.id
}