Loading...
Loading...
### Terraform Version ```shell Terraform v1.16.6 on linux_amd64 ``` **Regression.** Works on 1.16.0; broken on every release from 1.16.1 through 1.16.6 and on `main` (9ec49e06a8). Bisected to 892eccad86. Also broken on 1.15.8 and 1.15.9, before 038c6f72 fixed it in 1.16.0. ### Terraform Configuration Files ```bash #!/usr/bin/env bash # Usage: ./repro.sh [path/to/terraform] (defaults to `terraform` on PATH) set -e TF="${1:-terraform}" cd "$(mktemp -d)" # Step 1: r2 depends on r1, so state records the dependency r2 -> r1. cat > main.tf <<'HCL' resource "terraform_data" "r1" {} resource "terraform_data" "r2" { depends_on = [terraform_data.r1] } HCL "$TF" init -input=false > /dev/null "$TF" apply -auto-approve -input=false > /dev/null # Step 2: r1 is removed from the configuration, and r2 is replaced with # create_before_destroy newly enabled. (The dependency r2 -> r1 now exists only in state.) cat > main.tf <<'HCL' resource "terraform_data" "r2" { triggers_replace = 1 lifecycle { create_before_destroy = true } } HCL "$TF" version | head -1 "$TF" plan -input=false -no-color ``` ### Debug Output https://gist.github.com/Nilsils/3947f2861ca13468aecbeb1af3e1f69b ### Expected Behavior Step 2 applies: create the new `r2`, destroy the old `r2` (its deposed object), then destroy `r1`, which only the old `r2` depended on. ``` Apply complete! Resources: 1 added, 0 changed, 2 destroyed. ``` That is what 1.16.0 does, and what every version does when `create_before_destroy` was already declared on `r2` in step 1, or when `r2` is replaced without it. The step-2 configuration is a single resource with no references; nothing in it can form a cycle. ### Actual Behavior ``` Plan: 1 to add, 0 to change, 2 to destroy. Error: Cycle: terraform_data.r2 terraform_data.r1 (destroy) terraform_data.r2 (destroy deposed 868d7490) ``` `terraform plan` prints the plan and then fails; `terraform apply` fails the same way. Deterministic: every run, on every affected version. Forcing the replacement with `-replace=terraform_data.r2` instead of `triggers_replace` gives the same result. State is unchanged by the failed run. ### Steps to Reproduce 1. Save the script above as `repro.sh`. 2. Run it: ``` $ bash repro.sh # uses `terraform` from PATH $ bash repro.sh /path/to/terraform # or name a binary ``` ### Additional Context _No response_ ### References - #39091 ### Generative AI / LLM assisted development? The configuration was not written by an LLM. It was produced by an automated metamorphic testing pipeline (an e-graph based generator of equivalent Terraform programs), then minimised to the form above. Claude was used to assist with the writing of this report, with the reduction, the bisect and the version sweep. Every claim in it was verified by running the configurations against the named binaries.
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
BugZero Plan
Streamline upgrades with automated vendor bug scrubs
BugZero Prevent
Wish you caught this bug sooner? Get proactive today.