☁️
Dockerfile

Terraform AWS VPC

VPC with public/private subnets, IGW, and NAT gateway

📋Configuration Files

main.tf

yaml
1terraform {
2 required_providers {
3 aws = { source = "hashicorp/aws", version = "~> 5.0" }
4 }
5}
6
7provider "aws" {
8 region = var.aws_region
9}
10
11resource "aws_vpc" "main" {
12 cidr_block = "10.0.0.0/16"
13 enable_dns_hostnames = true
14 enable_dns_support = true
15 tags = { Name = "main-vpc" }
16}
17
18resource "aws_subnet" "public" {
19 vpc_id = aws_vpc.main.id
20 cidr_block = "10.0.1.0/24"
21 map_public_ip_on_launch = true
22 availability_zone = "${var.aws_region}a"
23 tags = { Name = "public-subnet" }
24}
25
26resource "aws_internet_gateway" "igw" {
27 vpc_id = aws_vpc.main.id
28}

variables.tf

yaml
1variable "aws_region" {
2 description = "AWS region"
3 type = string
4 default = "us-east-1"
5}
📄

Step 01

Apply Terraform VPC

(01)Init and apply

Linux
1terraform init
2terraform plan
3terraform apply