{
  "slug": "opentofu-dynamic-prevent-destroy-lifecycle-setting-855276222c2a",
  "title": "OpenTofu dynamic `prevent_destroy` lifecycle setting",
  "tools": [
    "opentofu"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-05-14T11:57:20.000Z",
  "announced_at": "2026-05-14T11:57:20.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When a managed resource’s destroy protection should follow a module value, set `lifecycle.prevent_destroy` to a same-module expression such as `var.prevent_destroy_database` (available in OpenTofu v1.12.0).",
    "examples": [
      "variable \"prevent_destroy_database\" {\n  type    = bool\n  default = true\n}\n\nresource \"example_database\" \"example\" {\n  # ...\n  lifecycle {\n    prevent_destroy = var.prevent_destroy_database\n  }\n}"
    ],
    "gotchas": [
      "Version: v1.12.0",
      "lifecycle.prevent_destroy: Boolean lifecycle argument; when true, OpenTofu errors on plans that destroy the associated object. In v1.12.0 it can be set dynamically from same-module values.",
      "prevent_destroy_database: Example input variable of type `bool`; its default is true, making it optional to callers. Child-module callers pass its value in the module block.",
      "Prerequisite: Use OpenTofu v1.12.0 or later for dynamically defined `prevent_destroy`.",
      "Prerequisite: Declare any referenced input variable in the same module; the example uses `type = bool`.",
      "The referenced values must be available elsewhere in the same module."
    ]
  },
  "why_it_matters": "Configure a managed resource so its destroy protection follows a module value.",
  "sources": [
    "https://github.com/opentofu/opentofu/releases/tag/v1.12.0",
    "https://opentofu.org/docs/v1.12/language/resources/behavior/",
    "https://opentofu.org/docs/v1.12/language/values/variables/"
  ],
  "rank": 0.99049,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v2+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "wave1-20261014",
    "verdict_id": "wave1-20261014:wave1-20261014-706671206177687f-0:gate",
    "evidence_hash": "7d0b40010546492ab4129a2df72b64a1b24fae86b2d3c825928d33af914be87f"
  },
  "review": {
    "draft_hash": "d9de68a44406183e9bf346d06f8d39a230af4a68c880143b25f52cbb6ad95901",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "wave1-20261014:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.99 >= 0.9; 2 needed) and Jev gave 0.64 (>= 0.6 needed)."
  }
}
