3. Govern with OPA

What you will try

You can run this scenario immediately after setup. OPA uses the rules in policy.rego to select one of three paths from the Terraform plan. A private bucket proceeds automatically, a public bucket is denied and a new VPC waits for human review.

1. Check EKS and the workflow

Complete Prepare EKS for the labs. In the eks-lab working directory with the rendered files, check the context and read the manifest before submitting it.

kubectl config current-context
kubectl -n argo-workflows get workflowtemplate iacstack-governed-opa-aws
cat rendered/opa-s3-private.yaml

In opa-s3-private.yaml, spec.workflowRef.name: governed-opa-aws selects the alias registered in controller-values.yaml. Open terraform/governed/s3.tf and terraform/governed/vpc.tf. They call terraform-aws-modules/s3-bucket/aws 4.1.2 and terraform-aws-modules/vpc/aws 5.19.0 using the hashicorp/aws provider. The stack name selects the root and inputs. policy.rego evaluates the resulting plan.

Where is this scenario’s pipeline?

Request: opa-s3-private.yaml, opa-s3-public.yaml and opa-vpc.yaml · Alias registration: controller-values.yaml · Full pipeline: opa.yaml.

All three stacks select the same alias. Follow plan → observe → policy in the YAML. The first step produces the proposed Terraform changes. The second collects VPC Flow Log observations when applicable. The third evaluates these data with the rules in policies/policy.rego. governance-review publishes the decision. Find the conditional manual-approval, apply and policy-denied steps to see how one pipeline handles all three outcomes.

Trace the result back to the stack. The authorize step can finish a denial with iacstack result --outcome Blocked or request authorization for the plan. In apply, the runner claims authorization, applies the saved plan and reports Verified after verification. The alias maps the execution-result output to the result the controller reads.

Three OPA policy paths: direct apply, review before apply, and deny

2. Submit the request

kubectl apply --dry-run=server -f rendered/opa-s3-private.yaml
kubectl apply -f rendered/opa-s3-private.yaml
kubectl -n platform-system get iacstack opa-s3-private -w

When the attempt appears, stop watching with Ctrl+C. Copy the name returned below and open that workflow in the Argo list.

STACK=opa-s3-private
WF=$(kubectl -n platform-system get iacstack "$STACK" -o jsonpath='{.status.execution.workflow}')
kubectl -n argo-workflows get workflow "$WF"

3. Read the Plan Review and OPA Decision

The two screenshots below come from the same EKS lab run for the public-bucket case. Their plan fingerprints match.

Open the two HTML reports from the same attempt:

  1. Terraform-Plan → Artifacts → plan-review: Check the resource address, proposed action, and plan fingerprint. The HTML shows selected attributes. Open Logs → main on the same node for the complete diff.

    Full S3 Plan Review example with metadata, change counts, and the plan’s resources

  2. OPA-Governance-Review → Artifacts → policy-review: Read the rule outcome and compare its fingerprint with Plan Review. The first HTML report shows what Terraform proposes; the second explains which route the OPA decision selects.

    Full OPA Decision example with metadata, fingerprint, and the decision for the plan

4. Verify creation of the private bucket

  1. Expect AutoApply in Policy Review. After Apply, check the stack for Verified:

    kubectl -n platform-system get iacstack opa-s3-private -o json | jq '.status'
    
  2. Query the exact bucket in AWS. All four fields under PublicAccessBlockConfiguration should be true:

    bash lab-aws.sh s3api get-public-access-block \
      --bucket "iacstack-opa-s3-private-$(cat rendered/aws-account)-$(cat rendered/s3-suffix)"
    

5. Verify that OPA denies the public plan

kubectl apply --dry-run=server -f rendered/opa-s3-public.yaml
kubectl apply -f rendered/opa-s3-public.yaml
kubectl -n platform-system get iacstack opa-s3-public -w
  1. Stop watching with Ctrl+C and repeat the workflow lookup from step 2 with STACK=opa-s3-public. Expect Deny in Policy Review. In the graph, policy-denied completes and apply is skipped. A technical Succeeded phase means the workflow enforced the denial; the stack should report Blocked and PolicyDenied.

  2. Query the expected bucket by name. With the correct AWS account and permissions, 404 indicates absence. A 403 does not establish whether the bucket exists; check your AWS identity and permissions before drawing a conclusion.

    kubectl -n platform-system get iacstack opa-s3-public -o json | jq '.status'
    bash lab-aws.sh s3api head-bucket \
      --bucket "iacstack-opa-s3-public-$(cat rendered/aws-account)-$(cat rendered/s3-suffix)"
    

6. Review and verify creation of the VPC

kubectl apply --dry-run=server -f rendered/opa-vpc.yaml
kubectl apply -f rendered/opa-vpc.yaml
kubectl -n platform-system get iacstack opa-vpc -w
  1. Repeat the workflow lookup with STACK=opa-vpc. Check the proposed VPC with CIDR 10.90.0.0/24 in Plan Review and RequireApproval in Policy Review. Argo does not apply before human review.

  2. In Manual-Approval → Resume, choose Approve and enter a sample change ticket and a review comment. After Apply finishes, check the stack status:

    kubectl -n platform-system get iacstack opa-vpc -o json | jq '.status'
    
  3. Query the VPC in AWS. Expect one row with a vpc-… ID, the CIDR from the plan, and state available. The manifest schedules DriftCheck every two minutes after creation.

    bash lab-aws.sh ec2 describe-vpcs \
      --filters Name=tag:Name,Values=iacstack-opa-vpc Name=tag:Project,Values=iacstack-lab \
      --query 'Vpcs[].[VpcId,CidrBlock,State]' --output table
    

Customize Argo Workflows · Lab teardown