Azure资源管理器无法下载模板

时间:2020-10-22 08:30:27

标签: azure-resource-manager arm-template

出于测试目的,我们有PS脚本将我们的ARM模板部署到测试资源组。

$ctx = New-AzStorageContext -StorageAccountName $storageAccountName -UseConnectedAccount
$sasToken = New-AzStorageContainerSASToken -Context $ctx  -Name $containerName -Permission r -ExpiryTime (Get-Date).AddHours(1)

$toDeploy = "app1", "app2"
foreach ($template in $toDeploy) {
    $templateUri = "${containerUrl}/${template}.json${sasToken}"
    $templateParameterUri = "${containerUrl}/${template}.parameters.Integration.json${sasToken}"
    $templatePostUri = "${containerUrl}/${template}.Post.json${sasToken}"
    
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroup `
        -TemplateUri $templateUri `
        -TemplateParameterUri $templateParameterUri `
        -Mode Incremental `
        -DeploymentDebugLogLevel All `
        -Name "TestDeployment" `
        -Verbose

    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroup `
        -TemplateUri $templatePostUri `
        -Mode Incremental `
        -DeploymentDebugLogLevel All `
        -Name "TestDeploymentPost" `
        -Verbose

它适用于三分之二的开发人员。当我们中的一个人执行此操作时,将显示一条错误消息,指出指向模板的链接无效。 ARM无法下载它。

Error: Code=InvalidContentLink; Message=Unable to download deployment content from
     | 'https://ourstorage.blob.core.windows.net/user-testing/app1.json?SAS_TOKEN_HERE'. The tracking Id is '386e7670-1863-4c85-9484-8a27d2dd0760'.

但是,当我们将其复制到浏览器时,我们可以下载它。我们三个由于某些原因,只有ARM无法下载它。当存储帐户配置有公共访问权限,并且我们从链接中删除SAS令牌后,该令牌就可以在该开发者的计算机上使用。因此,看起来好像是在一台计算机上生成SAS令牌的问题。但是为什么这个SAS令牌对我们(3个开发人员)来说可以,但对ARM无效?

2 个答案:

答案 0 :(得分:1)

检查存储帐户上的防火墙设置。它需要允许来自All networks的访问。我已经看到了完全相同的情况和错误消息,因为我们的开发人员可以通过允许的IP访问,而ARM无法访问。在Microsoft为Key Vault之类的“用于模板部署的Azure资源管理器”启用存储帐户之前,ARM将无法访问防火墙后的存储内容,即使使用SAS令牌也是如此。

尽管以下引用是关于链接的ARM模板的,但仍适用于按URI进行部署。 “当前,您无法链接到Azure存储防火墙后面的存储帐户中的模板。” -来源:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/linked-templates#securing-an-external-template

enter image description here

在GitHub上进行讨论:https://github.com/MicrosoftDocs/azure-docs/issues/37309

答案 1 :(得分:1)

所以问题出在时钟漂移。我从另一台计算机上尝试了此操作,但收到了同样的错误消息,但是这次我什至无法使用浏览器下载模板。但这给了我错误消息-SAS令牌无效。根据ARM的说法,现在是开始时间。

解决方案是添加-StartTime (Get-Date).AddMinutes(-2)

看起来这台机器的时钟时间更短,因此我可以在浏览器中发现问题(将来还会出现更多问题)。在其他PC上,当我们将模板的链接粘贴到浏览器令牌中时,它已经很好了,因此看起来仅对于ARM是错误的。