Published

How to Reconcile Terraform Change Approvals with AWS CloudTrail Events

Build an auditable Terraform change trail by linking reviewed plans, deployment approvals, AWS CloudTrail activity, and independently verified resource state.

Two large industrial machines framed by dense steel pipes and concrete beams

An approved Terraform pull request is not proof that the intended change reached AWS. The review may refer to a speculative plan, while the deployment job generates a different plan, assumes the wrong role, targets another workspace, or never completes. Conversely, CloudTrail can show an AWS API mutation without establishing which change request authorized it. A defensible change-control record must join code review, the exact plan submitted for execution, the deployment identity, observable AWS activity, and resulting configuration state.

This is a practical design for teams running Terraform against AWS through a controlled CI/CD pipeline. It produces evidence that an engineer or assessor can inspect and challenge. The joins, validation rules and retention choices below are engineering recommendations, not mandatory AWS, GitHub, Terraform or NIST product behavior.

Separate the five claims

An audit record is easier to evaluate when it does not collapse different systems into one green deployment badge. The source repository proves which revision was reviewed and merged. The pipeline records which plan was approved and which job was authorized to apply it. Terraform reports the proposed operations and execution result. CloudTrail records supported AWS activity made by the deployment principal. AWS Config, where enabled for the applicable resource types and Regions, can provide configuration history after the change. Each system has coverage limits, and no one source establishes all five claims.

NIST SP 800-53 CM-3 addresses configuration change control, but attaching a pull-request link to a ticket is an implementation artifact, not an independent assessment of the full control. Organizations must define the actual approval rules, scope, emergency changes, separation of duties and review expectations within their own governance process. The design below helps preserve evidence for such a process; it does not establish authorization or compliance by itself.

Define the deployment population before collecting events

Start from an inventory of Terraform workspaces or state backends, deployment repositories, AWS accounts, partitions and Regions. This is the denominator for a meaningful coverage measure. A successful job for one workspace does not prove that other stacks use the same guarded path. Track exceptions for one-off maintenance roles, manual console changes, break-glass access and workloads that use CloudFormation or another provisioner. An omitted workspace must remain visible as an exception rather than disappearing from the audit.

  • Deployment identity: repository, protected branch or tag, commit SHA, change-request or pull-request identifier and workflow run ID.
  • Terraform target: root module, workspace, state backend identifier, Terraform version, provider lock-file digest and variable-set identifier without secret values.
  • AWS target: partition, account ID, approved Regions, role ARN, intended service scope and change window in UTC.
  • Governance: change owner, reviewer identity, required approval condition, emergency-change path and evidence retention owner.

Bind the approved change to the actual plan

A pull-request plan is often speculative: it helps reviewers understand a proposed change, but it might no longer describe the infrastructure at deployment time. For a controlled apply, generate a final saved plan against the intended state backend and exact revision, retain its content digest and approve the artifact or a trustworthy summary bound to that digest. HashiCorp documents the terraform plan -out=FILE flow and applying the saved plan with terraform apply FILE. The apply must consume that same approved plan; re-running an unreviewed plan after the gate undermines the binding.

Treat the saved plan as restricted execution material. HashiCorp explicitly notes that plan files may contain sensitive values in cleartext even when terminal output hides them. Store the plan in access-controlled short-lived artifact storage, not a public pull-request attachment or the source repository. Preserve a SHA-256 digest, build ID, policy-check result, expected resource actions and artifact expiry in the long-term evidence record. A digest proves that two copies match; it does not prove the plan was safe or approved.

Make the execution gate observable

Protect the branch and application workflow according to the organization’s repository settings and subscription capabilities. GitHub deployment environments support protection rules, including reviewers in supported plans, but a team must check whether the protection mechanism actually applies to its private repository. The evidence should name the enforced gate, not merely state that the workflow contains an environment name. A reviewer approving a code change and a reviewer authorizing production deployment are potentially different decisions.

Before applying, require a release record that binds the reviewed commit, final plan digest, target account and workspace, successful validation checks and approval event. Refuse execution if any of those values changes after approval. Keep the apply job’s permissions narrow: a trusted identity provider, an explicitly scoped IAM role, and only the AWS actions needed for the planned deployment. If the pipeline uses OpenID Connect, preserve the workflow run identifier and the AWS role-assumption context available to the collector. Do not assume CloudTrail automatically contains the GitHub pull-request URL.

Collect AWS activity from the correct account and Region

For each apply, collect CloudTrail management events over a bounded UTC interval that includes role assumption, execution and expected service propagation. CloudTrail records supported management operations, with fields such as eventTime, eventSource, eventName, awsRegion, userIdentity, requestID and eventID. Query the configured trail or event data store appropriate for the account and Region; a local Event history view is not an organization-wide, indefinite evidence repository. Check logging coverage separately before treating an empty query as proof that nothing changed.

Normalize records by AWS account, Region, service, API operation, principal/session, event identifier, timestamp, target resource reference when present and request outcome. Separate mutations from reads, and errors from successful calls. CloudTrail data events are not enabled by default for trails and event data stores; if the change involves a data-plane operation, explicitly validate whether that event category was configured and supported. CloudTrail events are not a sequential execution trace and should not be interpreted as a precise one-to-one list of Terraform resource actions.

Correlate intent, execution and AWS observations

A useful correlator starts with the specific deployment role session and its bounded execution window, then relates CloudTrail events to planned resource types and target identifiers. Inspect userIdentity and sessionContext rather than matching the application role name alone; the same role may be used by several runs. Where the principal attribution is ambiguous, retain that ambiguity as a validation failure or manual-review item. Event timestamps help narrow candidates but are not a secure correlation key on their own.

Compare planned resource actions with observed API activity by operation family and affected resource, not by requiring equal counts. A Terraform provider may issue multiple API calls, make read-after-write requests, retry operations or delegate work to an AWS service. The meaningful questions are whether the expected resources reached their authorized state, whether an unexpected mutation was attributed to the deployment session, and whether the recorded job completed without unreviewed additional actions. Distinguish unsupported telemetry coverage from a true absence of activity.

Verify the resulting configuration independently

After apply, query authoritative resource APIs or the relevant AWS Config history for a selected set of material changes. A pipeline exit code of zero is execution evidence, not sufficient confirmation that every security property remains correct. AWS Config supports resource configuration history where a recorder covers the resource type and Region; record that prerequisite. For security-group changes, for example, independently inspect the effective ingress/egress rules and compare them with the approved intent rather than relying only on a plan summary.

Define a bounded verification window and a clear state for asynchronous changes. A resource can have a successful API mutation yet still be provisioning or converging. Mark such rows as PENDING until the selected postcondition is verifiable, then either pass or fail against a time limit chosen by the service owner. Record the observation time, API operation and evidence digest. Do not silently reinterpret a delayed observation as an immediate deployment failure.

Create one reviewable evidence record per deployment

Store an append-only or tightly access-controlled record that links the change request to both the final planned artifact and AWS observations. Separate the event inventory from the summary decision so a reviewer can inspect rejected or unexpected matches. A practical pipeline is source revision -> approved plan -> controlled apply -> CloudTrail and resource-state collection -> correlation and validation -> retained evidence. Use stable IDs and explicit error states at every transition.

  • Identity: deployment ID, repository/commit, change request, approval event and reviewer identity.
  • Artifact: Terraform workspace, backend reference, plan SHA-256, plan generation time, apply job, runner identity and outcome.
  • Cloud context: AWS account/Region, assumed-role session context, logging coverage result and event collection interval.
  • Observations: CloudTrail event IDs and request IDs, affected-resource references, post-change API or AWS Config checks and raw response digests.
  • Decision: PASS, FAIL, PENDING or INCOMPLETE; validation rule version, exclusions, evidence owner, remediation ticket and retention reference.

Store raw CloudTrail records and verification responses under controls suitable for the environment, while keeping the normalized index small enough for review. If the organization enables CloudTrail log-file integrity validation, AWS documents digest-based checking with the validate-logs command. That mechanism validates covered delivered trail files, not an arbitrary exported CSV or every possible AWS API event. Preserve the validation result and the collection scope rather than simply labeling all telemetry immutable.

Exercise negative cases before trusting the dashboard

A pipeline that only records successful deployments has not demonstrated that it detects broken evidence. Run controlled tests in a non-production account: attempt an apply whose plan digest differs from the approved value; remove the required approval; target the wrong workspace; disable a test collector’s permission; and generate an authorized out-of-band test mutation. The expected result is a blocked deploy, explicit collection failure or unmatched-event exception, not a false PASS. Restore the test configuration and capture the outcome.

Measure at least four distinct rates: eligible deployments with complete approval-to-plan binding, eligible deployments with attributable apply sessions, deployments with complete CloudTrail observation coverage, and deployments with independently checked postconditions. Use separate denominators and count UNKNOWN or INCOMPLETE explicitly. A compliance-looking percentage that excludes broken collectors or missing accounts is not an assurance metric.

Operational failure modes and rollback

Common failure modes include a plan regenerated after approval, a mutable deployment branch, an apply job using unexpected credentials, AWS events arriving outside the original query window, an unrecorded Region, unsupported service event types, missing AWS Config recorder coverage and sensitive plan artifacts copied into broadly accessible CI logs. The response differs by failure: block execution for a binding error; investigate principal identity for an attribution error; rerun a read-only collector for a transient ingestion gap; and open a change exception when an out-of-band mutation is confirmed.

Roll back deployment policy changes by restoring the last known-good gating configuration, not by deleting inconvenient evidence. For a problematic infrastructure change, use a separately approved corrective Terraform plan that records its own identity, approvals and AWS events. Terraform state, observed infrastructure and approval history should remain separately traceable. Do not assume blindly applying an older plan reverses the effects of a newer change.

Release checklist and assessment boundary

  • The approved commit, final plan digest and applied artifact are identical and attributable.
  • The role, account, workspace and Region match the declared release scope.
  • CloudTrail collection covers the service operations and execution window being claimed.
  • Material resources have independently verified postconditions or explicit pending exceptions.
  • Unmatched events, logging gaps, failed collectors and emergency changes remain visible with owners.
  • Evidence references, review decisions and retention policy can be reproduced without leaking plan secrets.

This workflow can support CM-3 implementation evidence, configuration monitoring and investigation work. It does not itself establish NIST conformity, FedRAMP authorization, an ATO or independent assessment. The credible result is narrower and operationally stronger: for a specific change, a reviewer can follow the approval, exact plan, execution identity, recorded AWS activity and observed state, including the places where the evidence is incomplete.

Sources

Browse all writing · RSS feed

Tymur Chmeruk

Written by

Tymur Chmeruk

Cloud Security & Infrastructure Engineer · Baltimore–Washington Metro · [email protected]