terraform
terraform copied to clipboard
Allow variables in lifecycle block
Current Terraform Version
Terraform v0.12.28
Use-cases
I have a resource that gets deployed in a module. I want to allow the lifecycle of that resource to be determined by a variable provided to the module.
Attempted Solutions
This is the original attempt
lifecycle {
prevent_destroy = var.hns_enabled == true ? true : false
}
I also tried moving this up to a local and then using the local in the lifecycle block
locals {
prevent_destroy = var.hns_enabled == true ? true : false
}
resource "" "" {
lifecycle {
prevent_destroy = local.prevent_destroy
}
}
References
This is the same request #3116 from 2015 but that issues appears to have been left open and then closed from contribution from the public. The last activity was in 2018.
I would support this request as well. Would be good to get it working within a for_each
resource "azurerm_key_vault_secret" "secret" {
for_each = try(var.keyvault.secrets, {})
name = each.value.name
value = try(each.value.is_value_filepath, false) ? base64encode(file(each.value.value)) : each.value.value
key_vault_id = azurerm_key_vault.keyvault.id
content_type = try(each.value.content_type, null)
not_before_date = try(each.value.not_before_date, null)
expiration_date = try(each.value.expiration_date, null)
tags = try(each.value.tags, null)
lifecycle {
ignore_changes = each.value.lifecycle.ignore_changes
}
}
A workaround for some use cases is to add an override.tf under certain circumstances that redefines the lifecycle block of the resource.
My variable is just a simple list, want to keep file short to read
Could you please advice my approach? seems still not working
seems still not working
Yeah. The ticket is still open.