Skip to content

Conversation

@detienne20
Copy link
Contributor

""
Deploying template specs currently does not work. The API version 2021-03-01-preview returns a template spec with mainTemplate as part of properties while the code in src/azure-cli/azure/cli/command_modules/resource/custom.py tries to access key template which has been the name of the key in API version 2019-06-01-preview.

_This PR fixes #17733

The code contains other places where dict key template is being referenced but I am unsure whether this plays a role for this particular case (deploy a template spec version).

Testing Guide
See #17733 for a detailed explanation, especially this comment by @tonystz.
""
- From (#17893)

From my ongoing investigation (#17893) is not the proper fix for this. I was able to repro this issue and the key points to notice from the --debug output are :

A. { Request URL: 'https://management.azure.com/subscriptions/a1bfa635-f2bf-42f1-86b5-848c674fc321/providers/Microsoft.Resources?api-version=2020-10-01' }

B. { Request URL: 'https://management.azure.com/subscriptions/a1bfa635-f2bf-42f1-86b5-848c674fc321/resourceGroups/TemplateSpecsCLI/providers/Microsoft.Resources/templateSpecs/BugTest/versions/1.0?api-version=2021-03-01-preview' }

Azure CLI currently points to Microsoft.Resources version 2020-10-01 and Template Specs 2019-06-01-preview. It looks this PR:
( https://github.com/Azure/azure-rest-api-specs/pull/13811}
may have caused Microsoft.Resources version 2020-10-01 to be updated to use the latest (template-spec) client(s). This means that 'az deployment group create --template-spec' is now using template spec 2021-03-01-preview instead of 2019-06-01-preview as it should be.

This has caused a regression in Azure CLI. The code is CLI has not been updated for 2021-03-01 preview which has a few breaking changes for template specs; most notably the 'template' property has been replaced by 'main_template'. As a result the code in the CLI attempts to retrieve the 'template' property from the --template-spec input and fails.

Although the TemplateSpecs API will be update for CLI when a proper SDK release for Python is done (Azure/sdk-release-request#1469) , (ref: https://github.com/Azure/azure-cli/pull/17869/files) in the meantime I will send a fix for this and notify swagger team of the issue so they may prevent it in the future.

Comment on lines 894 to 896
elif template_spec:
template_link = TemplateLink(id=template_spec, mode="Incremental")
template_obj = show_resource(cmd=cmd, resource_ids=[template_spec]).properties['template']
resource = show_resource(cmd=cmd, resource_ids=[template_spec])
Copy link
Contributor

@zhoxing-ms zhoxing-ms Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this logic is only for template_spec, could we specify the api-version to ResourceType.MGMT_RESOURCE_TEMPLATESPECS here? Otherwise, it will use the latest version and may be inconsistent with ResourceType.MGMT_RESOURCE_TEMPLATESPECS
In this way, we can ensure that the api-versions of all the rest requests for template_spec are consistent in the same profile

Copy link
Contributor

@zhoxing-ms zhoxing-ms Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such as:

from azure.cli.core.profiles import get_api_version
api_version = get_api_version(cli_ctx, ResourceType.MGMT_RESOURCE_TEMPLATESPECS)
template_obj = show_resource(cmd=cmd, resource_ids=[template_spec], api_version=api_version).properties['template']

@zhoxing-ms zhoxing-ms merged commit feda9da into Azure:dev Apr 28, 2021
@zhoxing-ms zhoxing-ms changed the title {ARM} --template-specs regression fix [ARM] az deployment group create: Fix the compatibility issue of api-version for parameter --template-specs Apr 28, 2021
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

Successfully merging this pull request may close these issues.

3 participants