2.6 KiB
2.6 KiB
Terraform Workflows (Brownfield / Reconciliation)
Terraform in this repository is primarily used for importing and reconciling existing infrastructure.
This is a brownfield workflow: real infrastructure exists first, then code/state are brought into alignment.
Core workflow pattern
- Define/import one existing object.
- Inspect current provider state.
- Reconcile hand-maintained
.tfconfiguration. - Use targeted
ignore_changesonly when necessary. - Iterate until plan is sane/no-op for intended scope.
- Avoid casual apply operations.
Docker mirror workflow (documentation-oriented)
Directory: infrastructure/terraform/docker/
Use when intentionally mirroring selected running containers as structured documentation.
Steps
- Add minimal
docker_containerresource block (or uncomment/import-ready block). - Add
import {}block or runterraform importfor the container. - Run plan and inspect generated/state values.
- Keep only meaningful, maintainable arguments in hand-edited files.
- Use generated files as draft input, not final truth.
- Re-run plan until intended scope is clean.
Proxmox VM workflow
Directory: infrastructure/terraform/proxmox/
Use for existing Proxmox VMs and metadata reconciliation.
Steps
- Add/import one VM resource at a time.
- Confirm provider import ID format and vm/node mapping.
- Inspect with
terraform state show/ plan output. - Move useful arguments into stable hand-maintained files.
- Keep lifecycle ignore rules narrow and explicit.
- Iterate per VM until plan stabilizes.
Physical host metadata workflow
Physical host metadata currently lives in Proxmox Terraform locals/outputs and is used as documentation inventory context.
When updating:
- update locals with factual host metadata,
- ensure outputs remain documentation-friendly,
- avoid leaking sensitive internal data not needed for repository goals.
Generated config guidance
infrastructure/terraform/scripts/reconcile_from_plan.sh can generate Terraform draft configuration via -generate-config-out.
Treat generated files as:
- a starting point,
- reviewed manually,
- reduced to meaningful attributes,
- reformatted and split into maintainable files.
Safety reminders
- Do not commit
.tfstate*or real.tfvars. - Do not commit credentials.
- Do not run
terraform apply/destroycasually. - Keep changes incremental and reviewable.