opentofu/opentofu

Create a plan with `resource` `lifecycle { destroy = false}`

Open

#4324 aperta il 30 giu 2026

Vedi su GitHub
 (6 commenti) (0 reazioni) (1 assegnatario)Go (1237 fork)batch import
acceptedbuggood first issue

Metriche repository

Star
 (28.648 star)
Metriche merge PR
 (Merge medio 3g 5h) (79 PR mergiate in 30 g)

Descrizione

Community note

[!TIP] 👋 Hi there, OpenTofu community! The OpenTofu team prioritizes issues based on upvotes. Please make sure to upvote this issue and describe how it affects you in detail in the comments to show your support.

OpenTofu Version

OpenTofu v1.12.3

OpenTofu Configuration Files

  terraform {
    required_version = ">= 1.12"
  }

  variable "v" {
    type    = string
    default = "a"
  }

  resource "terraform_data" "example" {
    triggers_replace = [var.v]

    lifecycle {
      destroy = false
    }
  }

Debug Output

Failure is deterministic and reproducible from the config files.

Expected Behavior

tofu plan -out=tfplan writes a plan file containing the ForgetThenCreate change, apply able via tofu apply tfplan

Actual Behavior

tofu plan -out=otplan -var 'v=b'

runs into the error

│ Error: Failed to write plan file
│ 
│ The plan file could not be written: failed to write plan: failed to serialize resource terraform_data.example change: invalid change action ForgetThenCreate.

Steps to Reproduce

  1. tofu init && tofu apply -auto-approve
  2. tofu plan -out=otplan var 'v=b'

Additional Context

running tofu apply var 'v=b' -auto-approve gives no errors and changes the data without any complains

looking at internal/plans/planfile/tfplan.go, there seems to be now case in changeFromTfplan() for FORGET_THEN_CREATE.

References

No response

Guida contributor