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

terraform import fails for azure container registry #739

Open
sebastus opened this issue Jan 23, 2025 · 1 comment
Open

terraform import fails for azure container registry #739

sebastus opened this issue Jan 23, 2025 · 1 comment

Comments

@sebastus
Copy link

sebastus commented Jan 23, 2025

Steps to repro:

  1. create a container registry in the portal
  2. use this terraform script to attempt to plan/apply:
 resource "azapi_resource" "example" {
   type      = "Microsoft.ContainerRegistry/registries@2023-11-01-preview"
   name      = "goliveregistry1"
   parent_id = module.support_resource_group.resource_id

   location = var.location

   body = {
     sku = {
       name = "Standard"
     }
     properties = {
       adminUserEnabled = true
     }
   }

   response_export_values = ["properties.loginServer", "properties.policies.quarantinePolicy.status"]
 }
  1. When you get Error: Resource already exists, import it:
terraform import azapi_resource.example "/subscriptions/xxx/resourceGroups/rg-support-resources-avm/providers/Microsoft.ContainerRegistry/registries/goliveregistry1"
  1. Get output similar to this:
│ Error: Failed to retrieve resource
│
│ reading Resource: (ResourceId
│ "/subscriptions/xxx/resourceGroups/rg-support-resources-avm/providers/Microsoft.ContainerRegistry/registries/goliveregistry1"
│ / Api Version "2024-11-01-preview"): GET
│ https://management.azure.com/subscriptions/xxxx/resourceGroups/rg-support-resources-avm/providers/Microsoft.ContainerRegistry/registries/goliveregistry1
  1. Note the api version year in the output: 2024. But in the tf above, the api version is 2023.
@ms-henglu
Copy link
Member

Hi @sebastus ,

Thank you for taking time to report this issue.

When importing a resource into azapi_resource, you can specify the api-version like

 # It also supports specifying API version by using the resource id with api-version as a query parameter, e.g.
 terraform import azapi_resource.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.MachineLearningServices/workspaces/workspace1/computes/cluster1?api-version=2021-07-01

Doc: https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/resource#import

Would you please also share the error message in step 4? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants