0
votes

I have this code in TF for creating App Insight Resource. The name for creating the App Insight is being done by our internal names module. The output of the name for App Insight is of the format --> (Resource Group Name)-(Your own custom value)-dev-cus-001 Now we have 3 resources for App Insight with 3 custom values defined in the Locals block as shown below:

locals {
  application-insights = [
    "masterdata",
    "inboundintegration",
    "intgr-func",
  ]
}


module "names-application-insights" {
  version              = "~> 1.0"
  source               = "My Module URL"
  for_each             = toset(local.application-insights)
  resource_type        = "application-insights"
  resource_location    = var.resource_group_location
  resource_environment = var.resource_group_environment
  resource_name        = format("%s-%s", var.resource_group_name, each.value)
  resource_count       = var.resource_group_count
}


resource "azurerm_application_insights" "default" {
  for_each            = toset(local.application-insights)
  location            = data.azurerm_resource_group.default.location
  resource_group_name = data.azurerm_resource_group.default.name
  name                = module.names-application-insights[each.value].results
  application_type    = "web"
}

Now i have been asked to remove the custom value "masterdata" from the name of the first App Insight resource : (rg)-masterdata-dev-cus-001 So how do i remove the "masterdata" value from just one App Insights and ensure the other two App Insights that are created with two Locals : "inboundintegration" & "intgr-func" are not affected If i remove the first custom value "masterdata" from the Locals block, it will throw error right if i run the code after removing that value from Locals? How to edit this resource name then.

1

1 Answers

0
votes

As I see you use for_each to create the application insights. Then the only thing you can do is to remove the custom value masterdata from the Locals and it won't affect the other two resources. It means you will only create two application insights with the names "inboundintegration" & "intgr-func".