Skip to content

'az deployment group create --template-spec' does not work in certain locations #17733

@usrme

Description

@usrme

Describe the bug

Command Name
az deployment group create --template-spec

To Reproduce

  • Create a resource group in a known to be working location, France South for example, with a virtual machine that has Azure CLI installed
  • Create a resource group in a broken location, West Europe for example, with a virtual machine that has Azure CLI installed
  • Create some kind of template spec in some other resource group
    • Location does not matter for the template spec itself
  • From those virtual machines attempt a deployment against those same resource groups, or any other using template specs
  • The West Europe one fails, but the France South one succeeds
$ az deployment group create --resource-group rg-westeurope \
  --template-spec /subscriptions/<subscription ID>/resourceGroups/rg-template_specs/providers/Microsoft.Resources/templateSpecs/ts-test/versions/latest \
  --name ts-deployment \
  --debug

<output truncated>
cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
cli.azure.cli.core.util: Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 691, in _run_job
    result = cmd_copy(params)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 807, in default_command_handler
    return op(**command_args)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/command_modules/resource/custom.py", line 544, in deploy_arm_template_at_resource_group
    no_prompt=no_prompt, template_spec=template_spec, query_string=query_string)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/command_modules/resource/custom.py", line 571, in _deploy_arm_template_at_resource_group
    no_prompt=no_prompt, template_spec=template_spec, query_string=query_string)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/command_modules/resource/custom.py", line 896, in _prepare_deployment_properties_unmodified
    template_obj = show_resource(cmd=cmd, resource_ids=[template_spec]).properties['template']
KeyError: 'template'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 102, in handle_template_based_exception
    raise CLIError(ex.inner_exception.error.message)
AttributeError: 'KeyError' object has no attribute 'inner_exception'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 657, in execute
    raise ex
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 712, in _run_job
    return cmd_copy.exception_handler(ex)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 104, in handle_template_based_exception
    raise CLIError(ex)
knack.util.CLIError: 'template'

cli.azure.cli.core.azclierror: 'template'
az_command_data_logger: 'template'
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f66f225b730>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 1.039 seconds (init: 0.188, invoke: 0.851)
telemetry.save: Save telemetry record of length 2983 in cache
telemetry.check: Negative: The /root/.azure/telemetry.txt was modified at 2021-04-16 09:35:28.145237, which in less than 600.000000 s

Expected Behavior

For a valid API version to be returned for the available resource types.

Environment Summary

Linux-5.11.13-200.fc33.x86_64-x86_64-with-glibc2.32
Python 3.9.2
Installer: RPM

azure-cli 2.22.0

Additional Context

When executing from West Europe there is a KeyError, but from France South there isn't and the command finishes successfully. In both cases the only difference is the location from which the request went out. Looking at the debug output in full for both the following can be observed, which requests the registered resources providers and available API versions:

urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443
urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/<subscription ID>/providers/Microsoft.Resources?api-version=2020-10-01 HTTP/1.1" 200 2305

For West Europe the response includes:

{
    "resourceType": "templateSpecs",
    "locations": [
        "East Asia",
        "Southeast Asia",
        "Australia East",
        "Australia Central",
        "Australia Central 2",
        "Australia Southeast",
        "Brazil South",
        "Canada Central",
        "Canada East",
        "Switzerland North",
        "Germany West Central",
        "France South 2",
        "France South",
        "Central US",
        "North Central US",
        "France Central",
        "UK South",
        "UK West",
        "Central India",
        "West India",
        "South India",
        "Japan East",
        "Japan West",
        "Korea Central",
        "Korea South",
        "North Europe",
        "Norway East",
        "UAE North",
        "West Central US",
        "West Europe",
        "West US 2",
        "West US",
        "South Central US",
        "South Africa North"
    ],
    "apiVersions": [
        "2021-03-01-preview",
        "2019-06-01-preview"
    ],
    "capabilities": "CrossResourceGroupResourceMove, CrossSubscriptionResourceMove, SupportsTags, SupportsLocation"
}

For France South the 2021-03-01-preview API version is missing in the response. Thus, when the actual template spec is queried using:

urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/<subscription ID>/resourceGroups/rg-template_specs/providers/Microsoft.Resources/templateSpecs/ts-test/versions/latest?api-version=2021-03-01-preview HTTP/1.1" 200 None

Then it causes an error because that API version actually isn't valid for West Europe. This can be further confirmed here by attempting to create a template spec deployment to West Europe using that API version, which responds with 400:

Headers:

cache-control: no-cache
content-length: 726
content-type: application/json; charset=utf-8
expires: -1
pragma: no-cache
x-ms-correlation-request-id: bf6f21a9-6ce5-4699-bc00-83d48a7eae76
x-ms-failure-cause: gateway
x-ms-request-id: bf6f21a9-6ce5-4699-bc00-83d48a7eae76
x-ms-routing-request-id: FRANCESOUTH:20210416T095723Z:bf6f21a9-6ce5-4699-bc00-83d48a7eae76

Body:

{
  "error": {
    "code": "NoRegisteredProviderFound",
    "message": "No registered resource provider found for location 'westeurope' and API version '2021-03-01-preview' for type 'templateSpecs/versions'. The supported api-versions are '2019-06-01-preview'. The supported locations are 'eastasia, southeastasia, australiaeast, australiacentral, australiacentral2, australiasoutheast, brazilsouth, canadacentral, canadaeast, switzerlandnorth, germanywestcentral, eastus2, eastus, centralus, northcentralus, francecentral, uksouth, ukwest, centralindia, westindia, southindia, japaneast, japanwest, koreacentral, koreasouth, northeurope, norwayeast, uaenorth, westcentralus, westeurope, westus2, westus, southcentralus, southafricanorth'."
  }
}

Metadata

Metadata

Assignees

Labels

ARMaz resource/group/lock/tag/deployment/policy/managementapp/account management-groupService AttentionThis issue is responsible by Azure service team.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions