This project uses Terraform to mangage and deploy a simple VPC including public and private subnets, Internet Gateway, route tables, Nat Gateway, Security Groups and EC2 instances.
| Name | Version |
|---|---|
| terraform | >= 1.11.4 |
| aws | >= 5.96 |
| Name | Version |
|---|---|
| aws | >= 5.96 |
| tls | >= 4.10 |
| local | >= 2.52 |
aws configure --profile your_profile_nameNote:
your_profile_name: Your AWS CLI profile name.
Create a terraform.tfvars file:
For example:
################################################################################
# Project
################################################################################
aws_region = "your_region"
aws_profile = "your_profile"
aws_environment = "your_environment"
aws_owner = "your_name"
aws_project_name = "your_project_name"
################################################################################
# VPC
################################################################################
vpc = {
name = "my-vpc"
vpc_cidr = "10.0.0.0/16"
public_subnets = {
public-subnet-01 = {
cidr = "10.0.0.0/20"
az = "ap-southeast-1a"
}
}
private_subnets = {
private-subnet-01 = {
cidr = "10.0.16.0/20"
az = "ap-southeast-1a"
}
}
enable_nat_gateway = true
}
################################################################################
# Public Security Group
################################################################################
public_security_group = {
name = "public-sg-01"
description = "Public security group 01"
ingress_rules_with_cidr = {
ssh = {
description = "SSH from my IP"
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr_ipv4 = "0.0.0.0/0"
}
}
egress_rules_with_cidr = {
all_out = {
description = "Allow all outbound"
from_port = 0
to_port = 0
ip_protocol = "-1"
cidr_ipv4 = "0.0.0.0/0"
}
}
}
################################################################################
# Private Security Group
################################################################################
private_security_group = {
name = "private-sg-01"
description = "Private security group 01"
ingress_rules_with_cidr = {}
egress_rules_with_cidr = {
all_out = {
description = "Allow all outbound"
from_port = 0
to_port = 0
ip_protocol = "-1"
cidr_ipv4 = "0.0.0.0/0"
}
}
}
################################################################################
# Key Pair
################################################################################
key_pair = {
private_key_algorithm = "RSA"
private_key_rsa_bits = 4096
key_name = "ssh-key"
name_prefix = "my-vpc"
}
################################################################################
# EC2
################################################################################
ec2 = {
name_prefix = "my-vpc"
ami = ""
instance_type = "t2.micro"
}Note:
aws_region: The AWS region where you deploy using Terraform.aws_profile: Your AWS CLI profile name.aws_environment: The name of your environment (e.g., dev, staging, prod).aws_owner: Your name or the owner of the infrastructure.aws_project_name: The name of your project.
terraform initterraform planterraform applyterraform destroy