Open MohnJadden opened 11 months ago
@MohnJadden I believe this should be fixed in the main branch.
@magodo, I'm seeing the same issue on the latest version (aztfexport 0.14.0).
Running aztfexport rg -n -f MyRG
, ran into the same error as the OP. Created a new API Management resource with default configurations.
Error: parsing scope into product/ api id "/subscriptions/0000-0000-0000-0000-0000/resourceGroups/MyRG/providers/Microsoft.ApiManagement/service/my-api-management/": parsing "/subscriptions/0000-0000-0000-0000-0000/resourceGroups/MyRG/providers/Microsoft.ApiManagement/service/my-api-management/": parsing the Api ID: the number of segments didn't match
Expected a Api ID that matched (containing 10 segments):
> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ApiManagement/service/serviceValue/apis/apiIdValue
However this value was provided (which was parsed into 0 segments):
> /subscriptions/0000-0000-0000-0000-0000/resourceGroups/MyRG/providers/Microsoft.ApiManagement/service/my-api-management/
The following Segments are expected:
* Segment 0 - this should be the literal value "subscriptions"
* Segment 1 - this should be the UUID of the Azure Subscription
* Segment 2 - this should be the literal value "resourceGroups"
* Segment 3 - this should be the name of the Resource Group
* Segment 4 - this should be the literal value "providers"
* Segment 5 - this should be the name of the Resource Provider [for example 'Microsoft.ApiManagement']
* Segment 6 - this should be the literal value "service"
* Segment 7 - this should be the user specified value for this service [for example "serviceValue"]
* Segment 8 - this should be the literal value "apis"
* Segment 9 - this should be the user specified value for this apiId [for example "apiIdValue"]
The following Segments were parsed:
* Segment 0 - not found
* Segment 1 - not found
* Segment 2 - not found
* Segment 3 - not found
* Segment 4 - not found
* Segment 5 - not found
* Segment 6 - not found
* Segment 7 - not found
* Segment 8 - not found
* Segment 9 - not found
@daniel-michael38
This is either a provider issue, or by design should not be imported. The issue only occurs for the master subscription, e.g. /subscriptions/xxxx/resourceGroups/xz3apim/providers/Microsoft.ApiManagement/service/xxx/subscriptions/master
.
You can verify it by simply terraform import
it, which returns the same error. This is because the azurerm_api_management_subscription
's implementation assumes the scope of the subscription is either a product or api id: https://github.com/hashicorp/terraform-provider-azurerm/blob/039a00a3f097e927ea0bec3d16619ddd32cc6ddb/internal/services/apimanagement/api_management_subscription_resource.go#L247-L260.
My suggestion is to submit an issue to the upstream provider repo.
I created a series of resources in my Test-SnowflakeIntegration resource group via the portal. I wanted to export them via aztfexport and ran the following command:
./aztfexport rg --use-azure-cli-cred --non-interactive --hcl-only -o Snowflake Test-SnowflakeIntegration
The command starts and begins to export resources, but it eventually fails with the following error:
Error: parsing scope into product/ api id "/subscriptions/aaa-bbb-ccc-ddd/resourceGroups/Test-SnowflakeIntegration/providers/Microsoft.ApiManagement/service/test-snowflakeintegration-apim/": ID was missing the
apiselement
I tried logging back in via az login and re-running, but the issue still persists. The terraform.tf file generated by aztfexport just has the backend and required providers; no resources are present.I enabled trace logging and observed the following error in the logs, right before the log I posted above:
2023-10-02T16:02:20.474-0400 [ERROR] aztfexport: aztfexport ends with error: Failed to import /subscriptions/aaa-bbb-ccc-ddd/resourceGroups/Test-SnowflakeIntegration/providers/Microsoft.ApiManagement/service/test-snowflakeintegration-apim/subscriptions/master as azurerm_api_management_subscription.res-65: exit status 1
The gist with the full trace log is at https://gist.github.com/MohnJadden/4db90e496771df6e3f23949408bdc207
Anything I can do to fix?