title: How to parameterize prevent_destroy lifecycle configuration in Terraform?
body: <p>I have a variable defined locally, called <code>local.protect</code>, and defined in <code>variables.tf</code> with <code>default = true</code> and <code>type = bool</code>.  How do I get around the use of variables constraint on the <code>prevent_destroy</code> argument? I thought I could <code>local</code>.ize it (eg, <code>locals {protect = var.protect}</code>) but that doesn't work, either.</p>
  <pre><code>│ Error: Variables not allowed
  │ 
  │   on main.tf line 105, in resource &quot;aws_eip&quot; &quot;backend_eip&quot;:
  │  105:     prevent_destroy = local.protect
  │ 
  │ Variables may not be used here.
  ╵
  ╷
  │ Error: Unsuitable value type
  │ 
  │   on main.tf line 105, in resource &quot;aws_eip&quot; &quot;backend_eip&quot;:
  │  105:     prevent_destroy = local.protect
  │ 
  │ Unsuitable value: value must be known
  </code></pre>
  <p>In <code>main.tf</code>:</p>
  <pre><code>resource &quot;aws_eip&quot; &quot;backend_eip&quot; {
    vpc        = true
    depends_on = [module.vpc.igw_id]
    lifecycle {
      prevent_destroy = local.protect # line 105
    }
  }
  </code></pre>
  <p>In <code>variables.tf</code>:</p>
  <pre><code>variable &quot;protect&quot; {
    type = bool
    description = &quot;Whether (true) or not (false) to protect EIP from deletion via `terraform destroy`.&quot;
    default = true
  }
  </code></pre>
  <p>Use case here is being able to set this flag at runtime, for a set of resources (like five EIP), all at once.</p>