Terraform Error 'the number of path segments is not divisible by 2' creating Azure Configuration Keys

1.1k Views Asked by At

I'm trying to create an Azure App Configuration service and keys through Terraform, but when I run my Terraform through my pipeline I get an error running terraform plan. This is my tf script for creating the service and keys:

resource "azurerm_app_configuration" "appconf" {
  name                = var.name
  location            = var.location
  resource_group_name = var.resource_group_name
  tags                = var.tags
  sku                 = "standard"
}

resource "azurerm_app_configuration_key" "MainAPI" {
  configuration_store_id = azurerm_app_configuration.appconf.id
  key                    = "MainAPI"
  value                  = var.picking_api_url
  type                   = "kv"
  label                  = var.environment_name
}
# other keys omitted

This is the error I see: Error: while parsing resource ID: while parsing resource ID: the number of path segments is not divisible by 2 in "subscriptions/[SubscriptionId]/resourceGroups/[rgName]/providers/Microsoft.AppConfiguration/configurationStores/[AppConfigServiceName]/AppConfigurationKey/MainAPI/Label"

I get this error regardless of whether I explicitly include a label argument for the key in my TF script. I've bumped up my version of the Terraform ARM provider to 2.90 in case it was a bug in the provider, but still get the error.

1

There are 1 best solutions below

5
RahulKumarShaw On

resource "azurerm_app_configuration_key" depends on azurerm_role_assignment. You need to define a resource for that as well for assigning role to app_configuration.

The following code from the Hashicorp Terraform documentation for azurerm_app_configuration_key demonstrates how to do this:

resource "azurerm_role_assignment" "appconf_dataowner" {
  scope                = azurerm_app_configuration.appconf.id
  role_definition_name = "App Configuration Data Owner"
  principal_id         = data.azurerm_client_config.current.object_id
}

resource "azurerm_app_configuration_key" "test" {
  configuration_store_id = azurerm_app_configuration.appconf.id
  key                    = "appConfKey1"
  label                  = "somelabel"
  value                  = "a test"

  depends_on = [
    azurerm_role_assignment.appconf_dataowner
  ]
}