CI/CD Pipeline for NGINX on Docker — Phase 3: Infrastructure with Terraform
by Frank Doka
CI/CD Pipeline for NGINX on Docker — Phase 3: Infrastructure with Terraform
Phase 3 provisions the AWS infrastructure that will host the Docker container — defined entirely in code, reproducible on every run.
What I Defined
All resources fit in main.tf and variables.tf:
- EC2 instance — Amazon Linux AMI, sized for a single NGINX container
- Security group — Inbound rules for HTTP (80), HTTPS (443), and SSH (22); outbound open for package installs and Docker Hub pulls
- Key pair — SSH key reference for Ansible access in Phase 4
- Output values — Instance public IP and ID, exported so Ansible's dynamic inventory can discover the host at runtime
Why Terraform Outputs Matter
The variables.tf file bridges Terraform and Ansible. Terraform provisions the instance; its outputs tell Ansible where to find it. No hardcoded IPs, no manual inventory files — the pipeline discovers its own infrastructure.
What's Next
Phase 4 uses Ansible with AWS dynamic inventory to configure the EC2 instance, install Docker, and deploy the container.