如何测试链接的ARM模板? [英] How to test linked ARM templates?

查看:97
本文介绍了如何测试链接的ARM模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ARM模板太大,因此我想使用链接的模板.我知道模板必须位于ARM可以访问的位置.但是在将它们上传到目标位置之前,我应该能够以某种方式对其进行测试.否则,存在使用无效模板覆盖以前工作的模板的风险.那我该如何还原?

My ARM template is getting too big so I would like to use linked templates. I understand that templates need to be somewhere where they are accessible to ARM. But I should be able to test them somehow before I upload them to target location. Otherwise there is a risk that I override previously working templates with invalid ones. How do I revert then?

你如何做到的?

推荐答案

所以我想到了这个脚本.每个开发人员都有一个预先创建的资源组,他将在其中部署资源和预先创建的Blob容器来存储当前正在开发中的模板.在部署模板之前,我使用azcopy将本地文件夹与Blob容器同步.不幸的是,有时候Test-AzResourceGroupDeployment在失败的情况下无法为您提供足够的详细信息,因此我无法根据其返回值来决定是否执行部署.目前,这似乎工作正常.但是它已经是第3版或第4版,并且将来可能会更改.一种想法是合并 ARM-TTK 用于模板测试.

So I came up with this script. Each developer has precreated resource group where he will deploy resources and precreated Blob container to store templates currently in development. Before deploying templates I use azcopyto synchronize my local folder with Blob container. Unfortunately sometimes Test-AzResourceGroupDeployment doesn't give you enough details in case of failure so I can't make decision based on it's return value to execute deployment or not. For now this seems to work fine. But it's already 3rd or 4th version and it will probably change in future. One idea is to incorporate ARM-TTK for template testing.

$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$resourceGroup = $currentUser.Substring($currentUser.IndexOf('\') + 1) + "-testing"
$containerName = $currentUser.Substring($currentUser.IndexOf('\') + 1) + "-testing"
$storageAccountName = "team_shared_account_here";
$containerUrl = "https://${storageAccountName}.blob.core.windows.net/${containerName}"

Write-Host "Current user: <${currentUser}>" -ForegroundColor Green
Write-Host "Deployment will use templates from <${containerName}> container" -ForegroundColor Green
Write-Host "Resources will be deployed to <${resourceGroup}> resource group" -ForegroundColor Green
Write-Host

Write-Host "Syncing templates..." -ForegroundColor Green
.\azcopy.exe sync '.' $containerUrl --include-pattern "*.json" --delete-destination true

$toDeploy = "app1", "app2"
foreach ($template in $toDeploy) {
    $templateUri = "${containerUrl}/${template}.json"
    $templateParameterUri = "${containerUrl}/${template}.parameters.DEV.json"

    Write-Host "`nDeploying:  ${templateUri}" -ForegroundColor Green
    Write-Host "Paramaters: ${templateParameterUri}" -ForegroundColor Green

    Test-AzResourceGroupDeployment -ResourceGroupName $resourceGroup `
        -TemplateUri $templateUri `
        -TemplateParameterUri $templateParameterUri `
        -Mode Incremental `
        -Verbose

    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroup `
        -TemplateUri $templateUri `
        -TemplateParameterUri $templateParameterUri `
        -Mode Incremental `
        -DeploymentDebugLogLevel All `
        -Verbose
}

这篇关于如何测试链接的ARM模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆