Provision and manage a simple AWS stack using Terraform with GitHub Actions for CI/CD.
-
Networking
- VPC with 2 public + 2 private subnets across 2 AZs
- Internet Gateway (NAT disabled by default)
- DNS support/hostnames enabled
-
Compute
- EC2 instance (Ubuntu) in a public subnet
- Elastic IP
- Security groups for SSH and HTTP/HTTPS
-
Database
- RDS MySQL 8.0 in private subnets
- Master credentials stored in AWS Secrets Manager
- DB SG allows access only from the app/EC2 SG
-
Identity
- EC2 IAM role + instance profile
- Policy to read the RDS master secret (least-priv)
-
State
- Terraform remote state in S3
- (Locking: S3 lockfile or DynamoDB if configured)
- Terraform >= 1.11.0
- AWS account + S3 bucket for remote state
- GitHub OIDC β AWS IAM role (role ARN stored as secret)
- (Optional) SSH public key if you still use SSH instead of SSM
Add repository Actions secrets:
AWS_ROLE_ARNβ IAM Role ARN assumed via OIDC by workflows
If you still want SSH:
SSH_PUBLIC_KEYβ your OpenSSH public key (used if wired in variables)
.
βββ *.tf # Terraform modules/resources (VPC, EC2, RDS, IAM, SGs)
βββ backend.tf # S3 backend (bucket/key/region)
βββ variables.tf # Inputs (name, vpc_cidr, etc.)
βββ outputs.tf # Useful outputs (DB endpoint, secret ARN, etc.)
βββ .github/
βββ workflows/
βββ terraform_ci.yml # PR checks & push-to-main apply
βββ terraform_destroy.yml # Manual destroy (guarded)
- on: pull_request β main
terraform init,fmt -check,validate,plan(speculative)
- on: push β main
terraform init,fmt -check,validateterraform plan -out=tfplanterraform apply tfplan
Uses AWS OIDC (aws-actions/configure-aws-credentials@v4) with AWS_ROLE_ARN.
- Manual (
workflow_dispatch) - Requires typing
DESTROYto proceed - Runs
terraform plan -destroyand then applies after approval
The state bucket and OIDC role are intentionally not part of the destroy plan.
terraform init
terraform plan
terraform apply- Push a feature branch and open a PR β checks + plan run automatically.
- Merge to
mainβ plan + apply run and deploy the infra.
- GitHub β Actions β Terraform Destroy β Run workflow
- Enter
DESTROYand run - Review logs; infrastructure is torn down safely
- RDS connection timing: New DBs take a few minutes; wait until status is
available.