-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_resource_group_template_deployment
- fix delete for nested template deployment
#25466
base: main
Are you sure you want to change the base?
azurerm_resource_group_template_deployment
- fix delete for nested template deployment
#25466
Conversation
3eef97b
to
8560050
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teowa I've taken a look through and left some comments inline, but unfortunately we can't just use a fake API version here - that'd end up causing issues for Service Teams which would invariably come back to us as a bug report.
Digging into the logic for this one, I suspect the approach used won't work here since the caching key currently only supports top-level resources, which I believe is the root cause of this?
As such can we update the test to ensure it fails in main
(since I suspect this one would pass?) - and then update the caching logic to fix this issue?
Thanks!
log.Printf("[DEBUG] API version information for RP %q (%q) was not found - nestedResource=%q", parsedId.Provider, parsedId.SecondaryProvider, *nestedResource.ID) | ||
// The resource type is not returned if nested template is used, https://github.com/Azure/azure-rest-api-specs/issues/28517 | ||
// if that happens we try to send a fake version and get the usable API version from error message | ||
resourceProviderApiVersion = "2000-01-01" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would lead to some interesting logs for the Service Teams to deal with..
Instead - hitting this endpoint:
az rest --method get --url "https://management.azure.com/subscriptions/XXXX/providers/Microsoft.Insights?api-version=2024-03-01"
Returns the (truncated) JSON below, which contains the nested Resource Type defined above (activityLogAlerts
from Microsoft.Insights/activityLogAlerts
):
{
"authorizations": [],
"id": "/subscriptions/XXXX/providers/microsoft.insights",
"namespace": "microsoft.insights",
"registrationPolicy": "RegistrationRequired",
"registrationState": "Registered",
"resourceTypes": [
{
"apiProfiles": [
{
"apiVersion": "2017-04-01",
"profileVersion": "2018-06-01-profile"
}
],
"apiVersions": [
"2020-10-01",
"2017-04-01",
"2017-03-01-preview"
],
"capabilities": "SupportsTags, SupportsLocation",
"locations": [
"Global",
"West Europe",
"North Europe"
],
"resourceType": "activityLogAlerts"
}
]
}
(I've checked, the same information is returned from API Version 2022-09-01
, which is currently being called).
Digging into the code, it appears the issue is coming from here:
terraform-provider-azurerm/internal/services/resource/template_deployment_common.go
Lines 285 to 288 in 18af7d0
// NOTE: there's an enhancement in that not all RP's necessarily offer everything in every version | |
// but the majority do, so this is likely sufficient for now | |
resourceProviderApiVersions[strings.ToLower(providerId.ProviderName)] = *apiVersion | |
break |
.. and as such I don't believe this'll actually fix the issue? and I don't believe the acceptance test covers using a nested resource?
Instead I suspect that we'd need to fix this by changing the caching key to be something along the lines of lower(ResourceProvider)-lower(ResourceType)
, and then ensuring the API Version we're storing is the latest API version returned from the API (since some resources can't be modified using an earlier API Version than the one they're created using).
Hi @tombuildsstuff , thanks for the comment. Actually there are two cases:
"providers": [
{
"namespace": "Microsoft.Resources",
"resourceTypes": [
{
"resourceType": "deployments",
"locations": [
null
]
}
]
}
],
"dependencies": [],
"outputResources": [
{
"id": "/subscriptions/xxx/resourceGroups/wt-test-rgtd/providers/Microsoft.Insights/activityLogAlerts/test"
}
]
I totally agree with you to cache the resource type in key and use the correct API versions at the very begining to better solve the Thanks. |
Community Note
Description
The resource provider and types is not returned if nested template is used, Azure/azure-rest-api-specs#28517
If that happens, existing logic to retrieve API version will fail, this PR tries to send a fake ID and get the usable API version from error message.
PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_resource_group_template_deployment
- fix delete for nested template deployment [GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #25458
Note
If this PR changes meaningfully during the course of review please update the title and description as required.