aztfexport
aztfexport copied to clipboard
Tool can't parse the Service level scope defined in Azure API Management
I am trying this tool to import configuration for a vanilla Azure API Management instance. When I try to import it into Terraform code it throws an error. This error is related to the built-in subscription for Service scope called "Built-in all-access subscription". Seems like the tool is not able to interpret this scope.
Failed to import /subscriptions/0000-0000-0000-0000-0000/resourceGroups/resource-group-name/providers/Microsoft.ApiManagement/service/apim-instance-name/subscriptions/master as azurerm_api_management_subscription.res-33: exit status 1
Error: parsing scope into product/ api id "/subscriptions/0000-0000-0000-0000-0000/resourceGroups/resource-group-name/providers/Microsoft.ApiManagement/service/apim-instance-name/": ID was missing the
apis element
@mirzos The error seems derive from the provider: https://github.com/hashicorp/terraform-provider-azurerm/blob/8f356e27d0daad612a75308e801c5ba9374d525e/internal/services/apimanagement/api_management_subscription_resource.go#L247-L260
// check if the subscription is for all apis or a specific product/ api
if props.Scope != "" && !strings.HasSuffix(props.Scope, "/apis") {
// the scope is either a product or api id
parseId, err := product.ParseProductIDInsensitively(props.Scope)
if err == nil {
productId = parseId.ID()
} else {
parsedApiId, err := api.ParseApiIDInsensitively(props.Scope)
if err != nil {
return fmt.Errorf("parsing scope into product/ api id %q: %+v", props.Scope, err)
}
apiId = parsedApiId.ID()
}
}
Would you mind to manually run terraform import
on this resource. If the error remains, then you'd want to create an upstream issue in https://github.com/hashicorp/terraform-provider-azurerm and link it here.
@magodo Thanks for your reply and I tried with Terraform directly to import the configs and I was able to do so.
Hi @mirzos, just to be sure you are importing the exact same resource: /subscriptions/0000-0000-0000-0000-0000/resourceGroups/resource-group-name/providers/Microsoft.ApiManagement/service/apim-instance-name/subscriptions/master
?
Hi @magodo yes, this is the exact resource I am trying to import
Hi @magodo, could you find the issue?
I've tried to run terraform import
against the built-in master
subscription on my side, failed with the same error, while the other subscriptions (named by uuid) are successfully imported. The reason is the scope
returned is not of the form that the provider expected. This is mostly like a provider bug, or either an API bug.
Since there is nothing we can do here, I prefer to skip this resource for now.
Hi @magodo thanks for your answer. I will skip this resource for now (y)
@magodo do you have any updates to this issue?