Home/Refreshers/Infrastructure as code: refresher
Infrastructure as code
Writing down the infrastructure you want in files, and letting a tool make reality match them.
Remember
- Terraform creates things in a cloud account. Ansible sets up the inside of machines. Argo CD keeps a Kubernetes cluster matching Git.
- Declarative: you describe the end result, and the tool works out the steps.
- Idempotent: running it twice is safe. The second run changes nothing.
- The files live in Git, so every change has an author, a review, and a way back.
Preview, apply, undo
| Preview with Terraform | terraform plan |
| Preview with Ansible | ansible-playbook -i inventory.ini site.yml --check --diff |
| Preview with Argo CD | argocd app diff <app> |
| Undo any of them | git revert <commit>, then apply or sync again |
Watch out
- A change made by hand in a console is drift. The next run either undoes it or trips over it.
- Secrets end up in files and in state. Keep them out of Git.
- A preview too long to read gets skipped. Keep each change small.
Check it worked
Run the same thing twice. The second run reports no changes.