Skip to main content

CI/CD Pipeline for NGINX on Docker — Phase 3: Infrastructure with Terraform

·1 min read

by Frank Doka

Article

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.

More articles

Cloud Resume Challenge — Phase 5: IaC, CI/CD & Smoke Testing

Defining all infrastructure in Terraform, building a GitHub Actions CI/CD pipeline, and adding Cypress smoke tests to validate every deploy.

Read more

Text-to-Speech Serverless App — Phase 5: Infrastructure as Code with Terraform

Defining all backend resources in Terraform — Lambda functions, API Gateway, DynamoDB, S3, SNS, and Cognito — for reproducible deployments.

Read more