Infrastructure as Code
Browse all articles, tutorials, and guides about Infrastructure as Code
Guides
Introduction to Packer
Learn HashiCorp Packer 1.16: install it, write HCL2 templates, build AWS AMIs and Docker images, use provisioners and variables, and follow best practices.
Introduction to Terraform
Learn Terraform 1.17 step by step: install it, write HCL, manage state, use variables and modules, set up S3 remote state with locking, and test your code.
Introduction to Ansible
Learn Ansible step by step with ansible-core 2.21: install it, write playbooks, manage inventory, variables, handlers, templates, roles and Vault.
Posts
OpenTofu 1.13 Re-Encodes base64gzip and Drops WinRM. We Upgraded the Same State to See What Breaks
OpenTofu 1.13 shipped on September 30. We applied configs with 1.12.7 and planned them with 1.13.1 against the same state. Gzipped user data planned an update and a replacement with no config change. A WinRM provisioner passed validate and plan, then failed at apply. The new assume functions turned an Invalid count argument error into a clean plan. Here is what to check before you bump the version.
Terraform Module Outputs, Inputs and Sources: How Modules Pass Data to Each Other
How to get a value out of a Terraform module, pass a resource into another module, chain modules with for_each, pin a Git branch or tag as a module source, share providers and variables across modules, and fix the "Provider configuration not present" error that shows up when you refactor. The terminal examples were run on Terraform 1.15.
Terraform State: Remove, Move and Migrate Resources, and Set Up a Remote Backend
The state questions every Terraform team hits: how to stop managing a resource without deleting it, rename one without a rebuild, move it to another project, bootstrap a remote backend, and why the DynamoDB lock table is on its way out. Every command here was run on Terraform 1.15.
Gate Your Terraform Plans: Rules Decide, the Model Explains
A pull request says "3 to add, 1 to change, 1 to destroy" and everyone approves it. This is a GitHub Action that reads the plan JSON, fails the job on selected changes that risk data loss or public exposure, and uses DigitalOcean inference only to write the comment. Measured against twenty labelled plans, including the four it misses.
Who Owns the State File, and Other Questions That Decide Your Week
Most Terraform pain is not HCL. It is state: who is allowed to write it, how it is split, how you find out it no longer matches reality, and how a plan gets reviewed before it applies. Four decisions, a real drift run, and the tooling that exists for each.
Terraform Variables, Loops, and Outputs: The Complete Guide
Everything about moving values through Terraform in one place: declaring vs assigning variables, tfvars and TF_VAR_ precedence, locals, maps and lists, for_each and its pitfalls, splat outputs for counted resources, sensitive values, and the classic "variables may not be used here" error.
Terraform Strings and Conditionals: The Complete Guide
Building strings, checking substrings, ternaries, optional attributes and conditional resources, in one place.
OpenTofu 1.12: destroy = false Retires the tofu state rm Ritual
OpenTofu 1.12 lets a resource declare that it should be forgotten instead of destroyed, makes prevent_destroy dynamic, and quietly ends the manual providers lock step. Here is what each change does, plus the footguns the release notes will not warn you about.
OpenTofu in 2026: Should You Switch from Terraform (and What It Actually Costs You)
OpenTofu has matured into a real Terraform alternative in 2026. Here is what the fork gives you, why the migration is easier than you think, and where the actual lock-in hides.
Infrastructure as Code: A Beginner's Guide to IaC Fundamentals
Learn the fundamentals of Infrastructure as Code - what it is, why it matters, key concepts, popular tools, and best practices for managing infrastructure with code.
How to Save Terraform Plan and Apply Output to a File
Learn how to save Terraform plan output for review, share readable apply logs, and use the -out flag for safe two-step deployments.
How to Run Terraform From a Different Directory and in Scripts
Use terraform -chdir to run init, plan and apply against another folder, run Terraform without interactive prompts, limit a run to one resource with -target, and destroy everything except one resource without losing it.
Should .terraform.lock.hcl Be in .gitignore? Checksums and Versions
No: commit .terraform.lock.hcl. Learn what the lock file records, how version constraints work, how to fix checksum mismatch and "Invalid legacy provider address" errors, how to install a specific Terraform version, and which providers manage on-premises servers.
How to Organize a Terraform Repository: Environments, Modules, Files
A practical layout for a Terraform repository: one root folder per environment and component, small reusable modules, and clear file names. Also covers dev, staging and production, workspaces, and how to split main.tf into several files.
How to Read a .env File in Terraform, and Where path.module Points
Terraform reads only TF_VAR_ environment variables and never a .env file. Learn how to load one safely, how path.module, path.root and path.cwd differ, and how to upload a local folder or create an empty folder in S3.
How to Reference for_each Resources in Terraform: Keys, Indexes and Import
A resource with for_each is a map of instances. Learn how to reference one instance or all of them, how to get a list index inside for_each, and how to import existing objects into for_each addresses without quoting errors.
Terraform Infrastructure as Code Best Practices
Practical Terraform best practices for 2026: repository layout, remote state with native S3 locking, version pins and the lock file, data sources instead of hardcoded IDs, secrets kept out of state, terraform test, and a CI pipeline that applies the plan you reviewed.