CI/CD reviewed plan workflow
Why review infrastructure changes before deployment
Continuous integration (CI) checks a proposed change; continuous delivery (CD) prepares a reviewed change for deployment. A pull request is a proposal to merge code, not permission to alter infrastructure. For a fictional inventory service, a change to a Terraform resource should be reviewed twice: first as source code, then as concrete planned effects. Separate the untrusted proposal from the trusted deployment path.
Untrusted PR -> isolated static review -> human code reviewProtected commit -> trusted init/test -> saved plan -> policy/cost review -> independent approval of digest + target -> serialized apply -> verify service and state -> protected audit recordThe first lane has no deployment credentials or production backend access. Only a protected, reviewed revision can enter the second lane. An approval of the source diff does not approve an unseen resource replacement.
Choose checks according to trust
A formatting check inspects style. Validation checks Terraform configuration against available schemas; initialization may obtain executable providers and modules. Tests can invoke providers and can create objects. A plan can refresh data or call providers even if it makes no intended resource changes. Do not run arbitrary PR HCL with production credentials. A trusted dependency mirror, reviewed lockfile, pinned module revisions, disposable runner and egress restrictions are necessary for controlled execution. On an untrusted fork start with text-only checks, and only enable more checks within a deliberately isolated, credential-free environment.
Create a local reviewable plan
Use the following complete fixture in a new disposable directory. The provisional baseline is Terraform 1.14.8; exact patch support has not been verified. It uses the built-in terraform_data resource and has no external provider, remote backend or cloud account.
terraform { required_version = "= 1.14.8"}
resource "terraform_data" "release" { input = "catalog-v2"}
output "release" { value = terraform_data.release.output}With an approved local CLI and no inherited backend or CLI overrides, save it as main.tf. The following commands are an unexecuted manual lab, not an automatic pipeline. Initialization uses only the built-in provider for this configuration.
terraform fmt -check -recursiveterraform init -input=falseterraform validateterraform plan -input=false -out=review.tfplanterraform show -no-color review.tfplanThe expected first plan creates terraform_data.release and reports its input; output is known after apply. Review the actual result, including deletes, replacements, unknowns, scope and cost. Store the saved plan privately: it can include unredacted values. Do not print the full plan in public CI logs; use a restricted reviewer view. The text display is not a substitute for controlling access to the binary plan.
Apply the exact artifact and verify
After an independent reviewer approves the exact artifact and target, the trusted apply lane verifies the digest, commit, dependency versions, state target and freshness. It obtains narrowly scoped short-lived credentials only when needed. In the local lab only, use the commands below after confirming that the plan is still valid.
# Only after the independent approval and identity checks:terraform apply -input=false review.tfplanterraform output releaseExpected output value is catalog-v2 (CLI formatting may include quotes). Passing a saved plan to apply does not prompt for approval. The approval must already have happened outside Terraform. Do not replace the saved plan with a fresh automatic plan under the old approval. For HCP remote execution, use its supported run confirmation workflow rather than assuming a locally generated binary can be uploaded and applied. Keep the run ID, redacted changes, approval and verification result. Apply success is not proof of application health.
Map the design to CI platforms
The following is a design comparison, not valid workflow YAML. Each platform has its own trigger, permission and approval model.
Platform Untrusted lane Protected deployment laneGitHub Actions pull_request environment + concurrencyGitLab CI merge request pipeline protected environment + resource_groupAzure Pipelines restricted PR build environment approvals + exclusive lockGitHub environment protections depend on plan and repository visibility. GitLab fork pipelines and parent-project runs have different access to variables and runners. Azure approvals and checks are configured on protected resources outside ordinary pipeline YAML. Verify edition, permissions and protection settings; a label called production or a manual job is not itself an authorization boundary. No action revisions or runner images have been selected for deployment. The supplied workflow illustrations are intentionally non-executable; a native workflow needs a separately reviewed, pinned toolchain.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CI/CD reviewed plan workflow — knowledge check
Review trusted delivery and stale-plan decisions.
Which step belongs to an external fork PR without cloud authorization?
What is required after source code review?
Why restrict saved-plan access?
What does applying an approved saved plan do about confirmation?
What proves the service is healthy?