A modular Terraform project that provisions a Virtual Private Cloud (VPC), subnets, and an EC2 web server instance on AWS. It handles automatic installation of Docker and Nginx on the target machine.
The configuration is split into distinct modules for better maintainability:
subnetmodule: Responsible for provisioning the VPC, Subnet, Internet Gateway, and Default Route Table.webservermodule: Responsible for provisioning the EC2 instance, Security Group, and AMI logic. Also handles the execution of entry scripts via SSH to spin up services.
- Request an AWS account.
- Install Terraform CLI.
- Install AWS CLI.
- Ensure you have an SSH Key Pair configured on your local machine (
~/.ssh/id_ed25519).
- Create a
terraform.tfvarsfile to store your uncommitted configuration:
vpc_cidr_block = "10.0.0.0/16"
subnet_cider_block = "10.0.10.0/24"
availability_zone = "eu-central-1b"
env_prefix = "dev"
my_ip = "YOUR_IP_ADDRESS/32"
instance_type = "t2.micro"
public_key_path = "~/.ssh/id_ed25519.pub"
private_key_location = "~/.ssh/id_ed25519"- Initialize Terraform to download provider plugins and register modules:
terraform init- Review the infrastructure plan:
terraform plan- Apply the configuration to provision the AWS cloud resources:
terraform apply- When done, destroy the resources to avoid incurring charges:
terraform destroy