Sentinel to Terraform Policy Migration: What to Convert and What to Keep

Terraform policy went GA across the CLI, HCP Terraform and Terraform Enterprise in October 2026, and Sentinel has no retirement date. Which policies gain from moving, which stay on tfrun, and the CI gate you need because 1.17.0 exits 0 on a failed policy.

By VVV Ops ·

Terraform 1.17.0 shipped on 21 October 2026 with Terraform policy marked generally available, and the rest of the stack followed within weeks. Terraform Enterprise 2.1.0 added it on 26 October, the HCP Terraform changelog declared it GA for workspaces and Stacks on 27 October, and on 5 November HashiCorp released an agent that converts Sentinel and OPA policies into the new HCL format. The 23 November release post covers Terraform policy for Stacks, which the older frameworks cannot reach: HashiCorp's policy enforcement overview says Sentinel and OPA policy sets only support workspaces.

Sentinel has no end date. The same changelog says the new prewritten policies support both Terraform policy and Sentinel, and nothing HashiCorp published this autumn announces a retirement, although its comparison page now recommends Terraform policy for governance. That leaves a migration with no deadline, and we would run it policy by policy, moving the sets that gain something and keeping the ones that read data Terraform policy cannot see. Whatever moves, gate CI on the JSON output: as AWS documents for 1.17.0, the exit code does not stop a failing run.

Our post on Terraform security on AWS covers where plan-time policy sits next to static analysis and Conftest. This one assumes Sentinel or OPA policy sets already run in HCP Terraform or Terraform Enterprise, and looks at what changes when they become .policy.hcl files.

Which Sentinel policies gain from moving

Four things only Terraform policy does line up with kinds of policy that are awkward in Sentinel today. The first comes from the enforcement overview, the other three from HashiCorp's framework comparison:

  • Stacks get no policy at all from a Sentinel or OPA set. If Stacks are on the roadmap, their guardrails have to be written in Terraform policy.
  • Provider and module policies run during terraform init, before anything is downloaded, and a violation blocks the download. The comparison page notes that Sentinel and OPA run after downloads are complete.
  • core::getdatasource() can read an approved KMS key or AMI at evaluation time. The Sentinel version of that check usually carries a hard-coded list that someone has to keep current.
  • Values that are only known after apply, such as ARNs and IDs, can be checked once the apply finishes. Sentinel has no stage for that.

The policies we would leave on Sentinel are the ones built on the tfrun import. It exposes the run's workspace through tfrun.workspace and the cost estimate through tfrun.cost_estimate, including delta_monthly_cost. The Terraform policy functions reference lists 77 core:: functions and none of them returns run, workspace or cost data. The resource_policy reference does expose workspace tags as meta.tfe_workspace.tags, so a tfrun policy that only keys on tags may be portable. A monthly cost ceiling written against tfrun stays where it is until that changes.

Enforcement levels map one to one, defaults do not

The policy set documentation describes three levels on each side:

| Sentinel | Terraform policy | On failure | |---|---|---| | advisory | advisory | Warning, run continues | | soft-mandatory | mandatory_overridable | Run stops unless someone with override rights lets it through | | hard-mandatory | mandatory | Run stops |

Two details change behavior after conversion. The resource_policy reference sets the default enforcement_level to "mandatory", so a converted policy that lost its level line will block runs the Sentinel original only warned about. Grep the output for policies without the attribute before anything is attached.

Overrides also move. A Sentinel policy set can be configured so that users with the right permissions override any failed check in it, "even policies set to Hard mandatory". For Terraform policy, organization admins either let all team members override mandatory_overridable failures or delegate that to named teams, and the same page describes the set-wide switch for Sentinel only. Before mapping a hard-mandatory policy to mandatory, look at whether anyone has overridden it in the run history. If they have, map it to mandatory_overridable and ask its owner.

OPA policy sets in HCP Terraform have advisory and mandatory, and OPA's mandatory can be overridden by anyone with the Manage Policy Overrides permission. Mapping a Rego policy to mandatory removes an override that exists today, so mandatory_overridable is the like-for-like level and each policy needs a decision.

Behaviors that change what a converted policy catches

The stage a Terraform policy runs at comes from the attributes its condition reads. The Terraform policy overview lists setup, plan and apply stages, and a condition on a value known only after apply is evaluated after the resource exists, with the violation left for someone to fix and redeploy. AWS's Prescriptive Guidance for the Terraform AWS provider gives the common trap: tags_all on a resource with no tags cannot be evaluated until after apply, so check default_tags on the provider configuration instead.

Replacements arrive as two operations. The resource_policy reference says a planned replacement is evaluated as a delete and a create, and a policy that must cover both needs two resource_policy blocks. A policy that calls core::getresources and leaves no-op out of its operations list only sees resources the current run changes, so a cross-resource check can miss everything that already existed.

Module policies need the full registry address. The same AWS guidance says a policy labeled terraform-aws-modules/lambda/aws matches no module, because during init the source includes registry.terraform.io, and test mocks with the short address pass while the policy never runs.

This is HashiCorp's example of an update-only policy that reads prior state, with one case from its test file:

# policies/prevent_downsize.policy.hcl
policy {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 6.0.0, < 7.0.0"
    }
  }
}

resource_policy "aws_ebs_volume" "prevent_downsize" {
  operations = ["update"]

  enforce {
    condition     = attrs.size >= prior_attrs.size
    error_message = "EBS volume size cannot be reduced from ${prior_attrs.size}GB to ${attrs.size}GB. Downsizing volumes can cause data loss."
  }
}
# tests/prevent_downsize.policytest.hcl
policytest {
  targets = ["../policies/prevent_downsize.policy.hcl"]
}

resource "aws_ebs_volume" "fail_decrease" {
  expect_failure = true

  prior_attrs = {
    availability_zone = "us-east-1a"
    size              = 100
    encrypted         = true
  }

  attrs = {
    availability_zone = "us-east-1a"
    size              = 50
    encrypted         = true
  }
}

Because operations is ["update"], this policy says nothing about a plan that replaces the volume. When the Sentinel original walked every resource change in the plan, that is the kind of gap a converted policy can open without any test failing.

Converting with the policy agent, then running both

The agent runs in a container and talks to a model through GitHub Copilot, Amazon Bedrock or LiteLLM. Its README asks for Linux terraform and tfpolicy binaries (tfpolicy 0.3.0 or later) matching the image architecture, and a local Terraform MCP server for provider schema lookups:

docker pull docker.io/hashicorp/terraform-policy-agent:0.0.33

docker run -d --name terraform-mcp-server \
  -p 127.0.0.1:8500:8080 \
  -e TRANSPORT_MODE=streamable-http \
  -e TRANSPORT_HOST=0.0.0.0 \
  -e MCP_SESSION_MODE=stateless \
  --restart unless-stopped \
  docker.io/hashicorp/terraform-mcp-server:1.1.0

# In a checkout of hashicorp/terraform-policy-agent:
# cp .env.example .env, then set the model provider, binary paths
# and EXTERNAL_REPO_DIR=/path/to/your/sentinel-policies
./pre-check.sh
./run.sh

For each input policy it writes a .policy.hcl file, a .policytest.hcl file with fixtures and a report.md, plus a summary.md across the run with a Policy Limitation column. In external mode the results land in EXTERNAL_REPO_DIR/tfpolicy/. HashiCorp's own cautions are worth taking literally: output can differ between runs, passing generated tests does not prove the new policy matches the old one, and the policy text goes to whichever model provider you configure. A Sentinel repository can hold account IDs and allowlists, so clear that with whoever owns the data before the first run.

The agent uses Sentinel mock files under test/<policy-name>/ when they exist. For every policy that will end up mandatory, we would add a passing and a failing mock taken from a real plan before converting, because those become test cases the model did not write. It is the same rule we apply to AI-written Terraform in our Claude Code guardrails post: the model proposes, and a person reads the diff.

HCP Terraform lets policy sets in different frameworks apply to the same workspace, which makes a parallel run possible:

  1. List every Sentinel policy with its enforcement level and the imports it uses. Anything that reads cost or run data from tfrun stays on Sentinel.
  2. Convert the rest and read each report.md limitation before touching the output.
  3. Attach the new set at advisory to a test workspace until its first version has uploaded. The AWS guidance warns that a Terraform policy set with no policies fails every run it applies to.
  4. Attach it next to the Sentinel set on real workspaces and compare results until each policy has seen both a pass and a deny on real runs.
  5. Raise each policy to its mapped level, then detach the Sentinel original.
  6. Give every new Stack the Terraform policy set from its first deployment.

Version floors before the first policy set

HashiCorp's own pages disagree on the minimum. The tfpolicy install page says Terraform v1.16 or later, and the HCP Terraform enforcement overview says v1.17 or later. Use the higher one, and in practice 1.17.1: its changelog entry "Always evaluate module policies during destroy plan" implies 1.17.0 did not always evaluate them on destroy plans. The current release is 1.17.2, from 11 November.

On Terraform Enterprise, 2.1.0 introduced Terraform policy but bundles Terraform 1.16.0. Releases 2.1.1 (3 November) and 2.1.2 (25 November) bundle 1.17.1, so we would upgrade to one of those before attaching a set, and pin each workspace's Terraform version to 1.17.1 or later.

The same 1.17.0 release added -minimal-refresh, which refreshes only resources that already have planned changes. Keep it out of scheduled drift jobs like the one in our drift detection post, since it hides changes made outside Terraform.

A CI gate that reads policy results

Teams that run plans in their own pipeline, with GitHub Actions or Atlantis, can evaluate the same policies from the CLI with -policies=<directory>. The AWS guidance lists the catches. The CLI needs the separate tfpolicy-plugin binary and a cloud block that selects a workspace in an HCP Terraform organization, which supplies the entitlement. With Terraform 1.17.0, init -policies stops on a failed module policy, but plan -policies and apply -policies report failed policies and still exit 0, and apply still makes the changes. HashiCorp's changelogs for 1.17.1 and 1.17.2 do not mention the exit code, and we found the behavior documented only on that AWS page, so check what your version does before you rely on it either way.

So the gate reads the JSON stream. The machine-readable UI reference puts the outcome in a top-level result and the level in policy_metadata.enforcement_level on each policy_result message, and reports an engine that failed to start, such as a missing tfpolicy-plugin, as SetupErrorResult:

set -euo pipefail

terraform plan -json -policies=./policies -out=tfplan > plan.jsonl

blocking=$(jq -s '[.[] | select(
    (.type == "policy_result"
      and .result == "DenyResult"
      and .policy_metadata.enforcement_level != "advisory")
    or .result == "SetupErrorResult"
    or .result == "PolicyErrorResult"
  )] | length' plan.jsonl)

if [ "$blocking" -gt 0 ]; then
  echo "Terraform policy: ${blocking} blocking result(s), see plan.jsonl"
  exit 1
fi

A CLI pipeline has no override flow, so the script treats mandatory_overridable as blocking. Counting SetupErrorResult makes the job fail closed when the plugin is missing, whatever the exit code says. PolicyErrorResult is another failure value defined in Terraform's source, and the gate counts it for the same reason. Apply the saved tfplan only in a later job that runs after this one passes.

We help teams plan this kind of policy migration, and if you want a second opinion on yours, get in touch. We would start with two lists: the policies that read tfrun, and every hard-mandatory policy someone has overridden in the last quarter. Together they show how much of the estate can move and which policies need a decision from their owners before they do.

Tags: sentinel to terraform policy migration, terraform policy as code, hcp terraform sentinel, terraform infrastructure as code, terraform consulting, infrastructure as code