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

Tool can't parse the Service level scope defined in Azure API Management #444

Open
mirzos opened this issue Aug 15, 2023 · 8 comments
Open
Labels
bug Something isn't working upstream-provider

Comments

@mirzos
Copy link

mirzos commented Aug 15, 2023

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

@magodo
Copy link
Collaborator

magodo commented Aug 16, 2023

@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 magodo added bug Something isn't working upstream-provider labels Aug 16, 2023
@mirzos
Copy link
Author

mirzos commented Aug 17, 2023

@magodo Thanks for your reply and I tried with Terraform directly to import the configs and I was able to do so.

@magodo
Copy link
Collaborator

magodo commented Aug 18, 2023

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?

@mirzos
Copy link
Author

mirzos commented Aug 21, 2023

Hi @magodo yes, this is the exact resource I am trying to import

@mirzos
Copy link
Author

mirzos commented Aug 24, 2023

Hi @magodo, could you find the issue?

@magodo
Copy link
Collaborator

magodo commented Aug 25, 2023

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.

@mirzos
Copy link
Author

mirzos commented Aug 25, 2023

Hi @magodo thanks for your answer. I will skip this resource for now (y)

@stemaMSFT
Copy link
Member

@magodo do you have any updates to this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream-provider
Projects
None yet
Development

No branches or pull requests

3 participants