I have terraform module where i am creating two resources based on same condition:

length(keys(var.service_name)) > 0
resource "mapping" "qsm"{
for_each = { for key, value in var.service_name : key=> value if length(keys(var.service_name)) > 0 }
    region = each.key
    service_name = each.value.name
    name = "test-qsm"
}

resource "profile" "bcp" {
  for_each = { for k, v in coalesce(merge([for profile in var.sp : profile.pc if length(keys(var.service_name)) > 0]...), {}) : k => v }
name="bg"
}

variable "service_name" {
  description = "The name of the service"
  type        = map(any)
  default = {}
}

This value of variable service_name is provided from terragrunt.hcl. When i remove this variable in terragrunt.hcl both resources are getting deleted. But i want to just delete resource mapping not profile resources. The resource profile should be deleted when i call terragrunt destroy. Is there any way to achieve it?

0

There are 0 best solutions below