hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.52k stars 4.6k forks source link

Unable to import azurerm_app_configuration_key which contains slashes e.g. "my/super/key" #27172

Open tasiorek27 opened 3 weeks ago

tasiorek27 commented 3 weeks ago

Is there an existing issue for this?

Community Note

Terraform Version

1.8.5

AzureRM Provider Version

4.0.0

Affected Resource(s)/Data Source(s)

hashicorp/azurerm

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.0.0"
    }
}

resource "azurerm_app_configuration_key" "test" {
  configuration_store_id = azurerm_app_configuration.app_config.id
  key                    = "mm/test/abcz"
  value                  = "abc"

}

### Debug Output/Panic Output

```shell
Debug not needed.

Expected Behaviour

The azurerm_app_configuration_key should be imported.

Actual Behaviour

terraform import azurerm_app_configuration_key.test  "https://some-app-config.azconfig.io/kv/mm/test/abcz?label="
╷
│ Error: parsing "https://some-app-config.azconfig.io/kv/mm/test/abcz?label=": AppConfiguration Nested Item should contain 2 segments, got 4 from "kv/mm/test/abcz"
│ 
│ 

If I will replace slashes with http encoded %2F then it will proceed but will fail as there is no such key in App Conf.

Steps to Reproduce

No response

Important Factoids

No response

References

No response

teowa commented 2 weeks ago

Hi @tasiorek27 , thanks for submitting this! I can successfully import by replacing the / to %2F using the latest 4.0.1 version of the provider, so could it be the App Configuration Key doesn't exist on Azure ?

resource "azurerm_app_configuration_key" "test" {
  configuration_store_id = azurerm_app_configuration.appconf.id
  key                    = "app/b/c"
  value                  = "a test"
}

image

tasiorek27 commented 2 weeks ago

Yeah, it does work with this workaround. What's interesting is that slashes are supported in labels but not in key name. Are you going to work on it?

teowa commented 2 weeks ago

Hi @tasiorek27 , the key and label need to be escaped otherwise in some special case we are unable to parse the ID. In particular, key is escaped with Golang url.PathEscape, and label is escaped with url.QueryEscape. Below app config key is also valid:

resource "azurerm_app_configuration_key" "test" {
  configuration_store_id = azurerm_app_configuration.appconf.id
  key                    = "?label="
  label                  = "?label="
  value                  = "a test"
}

If we escape the key and value the ID looks like: https://appconf1test.azconfig.io/kv/%3Flabel=?label=%3Flabel%3D. But if we escape the key and value the ID looks like: https://appconf1test.azconfig.io/kv/?label=?label=?label=, which is ambiguous.