Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.ApiManagement Error: unexpected segment "policies/policy" in 3.92.0 on Import #25190

Closed
1 task done
ron-foreman opened this issue Mar 8, 2024 · 2 comments
Closed
1 task done

Comments

@ron-foreman
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.7.0

AzureRM Provider Version

3.92.0

Affected Resource(s)/Data Source(s)

azurerm_api_management_api_policy

Terraform Configuration Files

resource "azurerm_api_management_api_policy" "api_policies" {
  count               = length(var.apis_arguments)
  api_name            = var.apis_arguments[count.index].name
  resource_group_name = data.azurerm_api_management.apim.resource_group_name
  api_management_name = data.azurerm_api_management.apim.name

  xml_content = file(abspath(var.apis_arguments[count.index].policy_content))

 depends_on = [
    azurerm_api_management_api.apis,
    azurerm_api_management_named_value.named_values
  ]
}

Debug Output/Panic Output

╷
│ Error: parsing "/subscriptions/.../resourceGroups/.../providers/Microsoft.ApiManagement/service/.../apis/.../policies/papi/apis/.../policies/policy")
│
│
╵

Expected Behaviour

module.apim.azurerm_api_management_api_policy.apim_api_policy: Import prepared!

Prepared azurerm_api_management_api_operation for import

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Actual Behaviour


│ Error: parsing "/subscriptions/.../resourceGroups/.../providers/Microsoft.ApiManagement/service/.../apis/.../policies/papi/apis/.../policies/policy")


Steps to Reproduce

terraform import azurerm_api_management_api_policy.apim_api_policy

Important Factoids

No response

References

This error keeps coming up

Issue 23095

Issue 23036

@sinbai
Copy link
Contributor

sinbai commented Mar 11, 2024

Hi @ron-foreman thanks for opening this issue. Unfortunately, I could not reproduce the issue with tf config and repro steps below. Please let me know if I missed anything crucial.

Step1: Create a azurerm_api_management_api with the following tf config.

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


provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-0311"
  location = "eastus"
}

resource "azurerm_api_management" "test" {
  name                = "acctestAM-0311"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name
  publisher_name      = "pub1"
  publisher_email     = "[email protected]"
  sku_name            = "Consumption_0"
}

resource "azurerm_api_management_api" "test" {
  name                = "acctestapi-0311"
  resource_group_name = azurerm_resource_group.test.name
  api_management_name = azurerm_api_management.test.name
  display_name        = "api1"
  path                = "api1"
  protocols           = ["https"]
  revision            = "1"
}

resource "azurerm_api_management_api_policy" "api_policies" {
  api_name            =  azurerm_api_management_api.test.name
  resource_group_name = azurerm_api_management.test.resource_group_name
  api_management_name =azurerm_api_management.test.name

 xml_content = <<XML
<policies>
  <inbound>
    <find-and-replace from="xyz" to="abc" />
  </inbound>
</policies>
XML
}


Step2: Import the azurerm_api_management_api_policy created by the above config with command terraform import azurerm_api_management_api_policy.api_policies /subscriptions/xxx/resourceGroups/acctestRG-0311/providers/Microsoft.ApiManagement/service/acctestAM-0311/apis/acctestapi-0311

Actual:
image

It is worth mentioning that per the Terraform documentation, the command to import azurerm_api_management_api_policy does not include /policies/policy.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants