Files
talks/2023-03-15-wgtn-ansible-meetup/0-deploy-demo-infra/network-main.tf

49 lines
1.4 KiB
HCL

# Create the vpc
resource "aws_vpc" "vpc" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
tags = {
Name = "${lower(var.app_name)}-${lower(var.app_environment)}-vpc"
Environment = var.app_environment
}
}
# Define the public subnet
resource "aws_subnet" "public-subnet" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.public_subnet_cidr
availability_zone = var.aws_az
tags = {
Name = "${lower(var.app_name)}-${lower(var.app_environment)}-public-subnet"
Environment = var.app_environment
}
}
# Define the internet gateway
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${lower(var.app_name)}-${lower(var.app_environment)}-igw"
Environment = var.app_environment
}
}
# Define the public route table
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.gw.id
}
tags = {
Name = "${lower(var.app_name)}-${lower(var.app_environment)}-public-subnet-rt"
Environment = var.app_environment
}
}
# Assign the public route table to the public subnet
resource "aws_route_table_association" "public-rt-association" {
subnet_id = aws_subnet.public-subnet.id
route_table_id = aws_route_table.public-rt.id
}