Use this when managing VMs, networks and storage declaratively in versioned code, or when real infrastructure has drifted from the code.
Infrastructure as Code
Infrastructure as Code declares VMs, networks and storage in versioned files (Terraform, Pulumi, Bicep, Ansible), so changes are reviewed, planned and applied consistently, and drift from the declared state can be detected.
1. Infrastructure as Code describes VMs, networks and storage in versioned files.
2. Plan → review → apply.
3. Remote state with locking.
4. Detect drift.
5. Secrets out of code.
code → plan → review → apply → state
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Checks Verify boundary
terraform planshows no drift after deployment.- State stored remotely with locking.
- Credentials provided via environment/secret store, not in code.
Step 2 Common mistakes Narrow the fault
- State files with credentials stored unprotected.
- Manual changes in the GUI causing drift.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- The plan is the review; read it.
- Manual changes become drift.
- State files contain secrets; protect them.
terraform plan— drift and changesansible-playbook site.yml --check --diff— config driftgit log— reviewed changes
ReferenceWhy it matters1 section · depth on demand
Workflow
1. Write code (Terraform/OpenTofu).
2. plan in CI on pull request.
3. Review.
4. apply from the pipeline with stored state.
5. Drift checks on a schedule.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Infrastructure as Code describes VMs, networks and storage in versioned files and applies them through APIs. Benefits: reviews via pull requests, reproducible environments, drift detection.
Practical issues with hypervisors: provider maturity varies (vSphere provider is mature; Proxmox community providers such as bpg/proxmox are widely used), state files contain sensitive data (encrypt and lock remote state), and imported legacy VMs need careful import to avoid destroy/recreate plans. Always review plan output for replacements before apply.
Tools
| Tool | Platforms |
|---|---|
| Terraform/OpenTofu | vSphere, Proxmox, Hyper-V (community), cloud |
| Pulumi | Same, with general-purpose languages |
| Ansible | VM lifecycle modules |
| Packer | Templates/images |
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Automation → Infrastructure as Code. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://libvirt.org/html/index.html · confidence 94%