All case studiesLab project
Automated Infrastructure Provisioning
Terraform provisions the infrastructure, Ansible roles configure it, and environment-specific inventories keep staging and production consistent — with secrets handled through Ansible Vault.
- Terraform
- Ansible
- Ansible Vault
- AWS
- Bash
This is a personal lab build used to practise and demonstrate the approach. It describes architecture and decisions, not results from a client engagement.
Problem
Servers were being created and configured by hand, so environments drifted apart and rebuilding one from scratch was slow and error-prone.
Architecture
- Provisioning
- Terraform modules
- Remote state
- Configuration
- Ansible roles
- Per-environment inventories
- Secrets
- Ansible Vault
- Environment variables
- Targets
- Staging hosts
- Production hosts
Technical decisions
- Terraform for what exists, Ansible for how it's configured
- Keeping a clear boundary between provisioning and configuration made each tool easier to reason about and test independently.
- Role-based playbooks
- Small, focused roles (base hardening, Docker, monitoring agent, application) compose into per-host playbooks and can be reused across projects.
- Environment-specific inventories and variables
- The same roles run against staging and production; only inventory and group variables differ, so promotion is predictable.
Implementation
- Wrote reusable Terraform modules with input variables and outputs consumed by Ansible.
- Configured remote state with locking to make concurrent runs safe.
- Built idempotent Ansible roles and verified repeated runs produce no changes.
- Encrypted sensitive variables with Ansible Vault.
- Wrapped common workflows in documented scripts.
Security considerations
- No plaintext secrets in the repository; vault-encrypted variables only.
- Least-privilege IAM for the provisioning identity.
- SSH key-based access only; password authentication disabled by the base role.
Operational benefits
- Environments can be rebuilt from code instead of memory.
- Configuration changes go through review like any other code change.
- Staging and production stay aligned by construction.
Lessons learned
- Idempotency has to be tested, not assumed — run every playbook twice.
- Keep Terraform state access tightly controlled; it can contain sensitive values.