IaC integration and rollback
Separate infrastructure and application ownership
Infrastructure as code (IaC) describes infrastructure resources and their desired settings. Terraform can manage load balancers, networking or instance infrastructure through providers; it is not the Nginx parser and cannot by itself establish HTTP correctness. Ansible can render and distribute a trusted template; a GitOps controller can reconcile Kubernetes objects from a declared source. Assign a single owner per resource to avoid one automation overwriting another. This boundary example is conceptual, not an executable provisioning plan.
Terraform -> network, instances, entry load balancerImage build -> Nginx binary and approved configurationConfiguration manager OR GitOps controller -> selected runtime configurationHTTP verification -> application behavior and release identityReview an infrastructure plan separately
A Terraform plan proposes resource changes based on configuration, state and provider observations. Even planning may contact APIs, and saved plan files can contain sensitive values. A plan is not authorization to apply and a reviewed plan can become stale. The commands below illustrate an optional workflow only in a separately approved isolated workspace with trusted providers; do not run them for this offline lab. Review replacements, listener changes, access policies and dependencies. Keep state and plan files access-controlled, and require a separate apply approval.
terraform plan -out=review.tfplanterraform show review.tfplan# Stop for review; no apply in this lesson.Validate rendered configuration before activation
Ansible’s template integration can check a temporary candidate before replacing a target, but a check of one file is insufficient for a configuration split across includes. The following is an illustrative task fragment for a hypothetical approved isolated Linux target, not a complete playbook. It uses a standalone configuration with no relative includes. For multi-file releases, stage the entire versioned tree and validate it with the same path layout and identity used at activation. The validate command is not a shell pipeline. Verify permissions, secret delivery and expected responses separately.
- name: Stage standalone candidate ansible.builtin.template: src: nginx.conf.j2 dest: /srv/nginx-lab/candidate.conf mode: "0640" validate: "/usr/sbin/nginx -t -p /srv/nginx-lab/ -c %s"Stage rollout and preserve independent rollback
Keep the last known-good configuration, artifact identity and required runtime inputs independently accessible. In a redundant deployment, activate the candidate on one drained node, test it, and restore traffic only when the release marker and policy assertions pass. On failure, stop promotion, restore the previous artifact, validate and reload the intended instance, then check actual HTTP behavior again. A successful reload command does not prove all workers use the new config; long-lived requests can remain on old workers. Infrastructure changes may need a separate approved recovery plan; do not blindly revert Terraform state or assume a Git revert undoes external changes. The example is a synthetic decision log.
A: last known-good, verifiedB: candidate, syntax PASS, behavior FAILDecision: hold B, restore A on affected targetVerify A marker and policy, record outcomeInfrastructure: assess separately; no automatic state rewriteApply what you learned
Practice: A new proxy configuration passes syntax but fails HTTP verification on the first drained node. Terraform also proposed a listener replacement that has not been applied. Decide what to restore and what to do with the plan. The manual exercise and quiz are staged separately. Related references and the next lesson are listed in the chapter authored map.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
IaC integration and rollback
Assess configuration release and verification reasoning.
What does Terraform plan provide?
What can a saved Terraform plan contain?
What should validate a multi-file Nginx release?
What is first after a failed canary verification?
Why not use two independent writers for the same config?