This project deploys a secure AWS infrastructure using Terraform, featuring a VPC setup with an EC2 instance and DynamoDB tables. The project includes remote state management using S3 and DynamoDB for state locking.
- AWS CLI configured
- Terraform installed
- Environment variables set up in
.envfile:- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
- REGION
- BUCKET_NAME
- DYNAMODB_TABLE
- S3 Backend
- Bucket:
terracotta-aws-statefile-demo-bucket - State file path:
terraform/state.tfstate - Encryption enabled
- Bucket:
- DynamoDB State Locking
- Table:
terracotta-aws-demo-lock-table
- Table:
- Amazon VPC
- CIDR Block: 10.0.0.0/16
- DNS support and DNS hostnames enabled
- Single public subnet (10.0.1.0/24) in us-west-2a
- Internet Gateway for public internet access
- Route table configured for public subnet access
- EC2 Instance
- Instance Type: t2.micro (configurable)
- Latest Amazon Linux 2023 AMI (automatically fetched)
- Deployed in public subnet
- Auto-assigned public IP
- Security group configuration:
- Inbound: SSH (port 22) from any source
- Outbound: All traffic allowed
- DynamoDB Table
- Table Name: BasicTable (configurable)
- Billing Mode: Pay-per-request (On-demand)
- Primary Key: Id (String)
- No provisioned capacity (scales automatically)
- Initialize the backend infrastructure:
chmod +x scripts/createS3stateDynamodb.sh
./scripts/createS3stateDynamodb.sh- Initialize Terraform:
terraform init- Review the planned changes:
terraform plan- Apply the infrastructure:
terraform initAll infrastructure configurations can be customized through variables in variables.tf:
| Variable | Description | Default |
|---|---|---|
| aws_region | AWS region | us-west-2 |
| vpc_cidr | VPC CIDR block | 10.0.0.0/16 |
| public_subnet_cidr | Public subnet CIDR | 10.0.1.0/24 |
| availability_zone | AZ for subnet | us-west-2a |
| instance_type | EC2 instance type | t2.micro |
| dynamodb_table_name | DynamoDB table name | BasicTable |
The infrastructure provides the following outputs:
- VPC ID
- Public Subnet ID
- EC2 Instance Public IP
- VPC isolation with controlled internet access
- Security Groups with principle of least privilege
- Encrypted S3 state storage
- DynamoDB state locking for collaborative work
- Public subnet with internet gateway for EC2 access
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
[Add your license information here]