Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug or Feature: Dynamic or Variable-controlled Lifecycle blocks do not work #28972

Closed
geoff-reason opened this issue Jun 17, 2021 · 2 comments
Closed
Labels
enhancement new new issue not yet triaged

Comments

@geoff-reason
Copy link

Terraform 0.15.3

The following pretty much sums up what I want to do in code - protect deletion of assets in some environments but not in others

Attempt 1:

locals {
  is_prod_or_preprod = contains(["prod", "production", "preprod", "preproduction"], var.config["env"])
}

resource "aws_eip" "natgw" {
...
  "lifecycle" {
    prevent_destroy = local.is_prod_or_preprod
  }
}

│ Error: Variables not allowed
│ 
│   10:     prevent_destroy = local.is_prod_or_preprod
│ 
│ Variables may not be used here.

│ Error: Unsuitable value type
│ 
│   10:     prevent_destroy = local.is_prod_or_preprod
│ 
│ Unsuitable value: value must be known

locals {
  is_prod_or_preprod = contains(["prod", "production", "preprod", "preproduction"], var.config["env"])
  protect_eips = local.is_prod_or_preprod ? toset([1]) : toset([])
}

resource "aws_eip" "natgw" {
...
  dynamic "lifecycle" {
    for_each = local.protect_assets
    content {
      prevent_destroy = true
    }
  }
}

╷
│ Error: Unsupported block type
│ 
│ Blocks of type "lifecycle" are not expected here.

@geoff-reason geoff-reason added enhancement new new issue not yet triaged labels Jun 17, 2021
@jbardin
Copy link
Member

jbardin commented Jun 17, 2021

Thanks @geoff-reason,

We are tracking the request to have the ability to evaluate expressions in the lifecycle block in #25534 and #24188. While not directly related to expression evaluation for prevent_destroy, there are also #24658, #27035, and #3874 to name a few for other realted ideas regarding that feature.

Thanks!

@jbardin jbardin closed this as completed Jun 17, 2021
@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants