How maadbreck/lab02-infracode works
Project Type and Purpose
• This is an “Infrastructure as Code” project using Terraform together with the kreuzwerker/docker provider to provision a local Docker-based environment.
• It spins up:
• Three independent Node.js applications (app1, app2, app3)
• A Redis cache
• A PostgreSQL database
• An NGINX reverse-proxy/web server
• A Grafana container for monitoring
File Structure Analysis
Top‐level:
• README.md – high-level overview and usage
• apps/ – three subfolders (app1, app2, app3), each containing a Dockerfile, entrypoint (app.js), and package.json
• terraform/ – Terraform configuration files and state folders
terraform/ contains:
• providers.tf – Docker provider definition
• variables.tf and terraform.tfvars – configurable variables (e.g., ports, image tags)
• networks.tf – Docker network definitions
• services.tf – resource blocks creating containers for Node apps, Postgres, Redis, Grafana, NGINX
• nginx.tf – specific NGINX configuration and container setup
• outputs.tf – exposes container endpoints (e.g., app URLs, Grafana URL)
a. Infrastructure Provisioner
– Terraform CLI (init, workspace, apply)
b. Docker Host (local machine or VM)
– Single Docker daemon that houses all containers
c. Docker Network(s)
– Internal bridge network connecting all containers
d. Containers:
1. Node.js App1 (HTTP → port 5001)
2. Node.js App2 (HTTP → port 5002)
3. Node.js App3 (HTTP → port 5003)
4. PostgreSQL (TCP 5432)
5. Redis (TCP 6379)
6. Grafana (HTTP → port 5000)
7. NGINX (HTTP → port 3000)
Relationships and Data Flows
• Apps ↔ Redis/Postgres: each app container connects over the Docker network to Redis and to Postgres.
• External Client → NGINX: all incoming HTTP traffic on port 3000 hits NGINX.
• NGINX → Node Apps: NGINX is configured (in nginx.tf) to reverse-proxy requests to apps on ports 5001–5003.
Architectural Patterns and Principles
• Modularization: each service in its own container (separation of concerns)
• Immutable infrastructure: containers are built via Dockerfiles and recreated on Terraform apply
• Declarative provisioning: Terraform code defines desired state
• Single Docker network for service discovery