微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure 开发测试实验室:如何参数化资源

如何解决Azure 开发测试实验室:如何参数化资源

我正在尝试创建一个 PowerShell 脚本,该脚本将部署 Azure DevTest 实验室的一个实例,在那里创建一个环境,以及诸如数据块、Azure 数据工厂等资源。这是我的实验室模板的一部分。

       "resources":[
            {
               "apiVersion":"2018-09-15","name":"LabVmsShutdown","location":"[parameters('location')]","type":"schedules","dependsOn":[
                  "[resourceId('Microsoft.DevTestLab/labs',parameters('labResourceName'))]"
               ],"properties":{
                  "status":"Enabled","timeZoneId":"GMT Standard Time","dailyRecurrence":{
                     "time":"0100"
                  },"taskType":"LabVmsShutdownTask","notificationSettings":{
                     "status":"disabled","timeInMinutes":30
                  }
               }
            },{
               "apiVersion":"2018-09-15","name":"[concat('Dtl',parameters('labResourceName'))]","type":"virtualNetworks",parameters('labResourceName'))]"
               ]
            },"name":"Public Environment Repo","type":"artifactSources","properties":{
                  "status":"Enabled"
               }
            },"name":"[parameters('repositoryName')]","properties":{
                  "uri":"MY_URL","armTemplateFolderPath":"MY_PATH","displayName":"DevTestLab","branchRef":"features/devops-development","securityToken":"MY_TOKEN","sourceType":"VsoGit","status":"Enabled"
               }
            },"name":"[parameters('userId')]","type":"users","properties":{
                  "status":"Enabled"
               },"resources":[
                  {
                     "name":"devtestlaab","type":"environments","apiVersion":"2018-09-15","properties":{
                        "deploymentProperties":{
                           "armTemplateId":"[concat(resourceId('Microsoft.DevTestLab/labs/artifactsources',parameters('labResourceName'),parameters('repositoryName')),'/armTemplates/DevTestLab')]"
                        },"armTemplatedisplayName":"DevLab Deployment Script"
                     },"dependsOn":[
                        "[resourceId('Microsoft.DevTestLab/labs/users',parameters('userId'))]"
                     ]
                  }
               ]
            }
         ]
      }
   ]

它在大多数情况下运行良好。但是,我无法为我的内部模板传递参数。它只需要在特定时刻在我的 ref_branch 上的这些模板中进行硬编码并进行部署。

enter image description here

我尝试遵循以下模板并添加参数部分,但它被完全忽略了。

{
  "name": "string","type": "Microsoft.DevTestLab/labs/users/environments","apiVersion": "2018-09-15","location": "string","tags": {},"properties": {
    "deploymentProperties": {
      "armTemplateId": "string","parameters": [
        {
          "name": "string","value": "string"
        }
      ]
    },"armTemplatedisplayName": "string"
  }
}

总而言之,我可以部署:

  • 实验室
  • 环境
  • 本实验室内的资源。

我不能:

  • 将任何参数传递给我实验室环境中的资源。

文档非常稀缺,所以我不太确定可能是什么问题。

解决方法

AFAI 明白了,你的模板看起来不对。请查看 A quick guide on writing your Azure Resource Manager (ARM) Templates 以了解如何使用参数。

并且,对于PowerShell script deployment,您可以使用以下命令来部署带参数的 ARM 模板:

New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup `
  -TemplateFile <path-to-template-or-bicep> `
  -TemplateParameterFile c:\MyTemplates\storage.parameters.json

New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup `
  -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json `
  -TemplateParameterUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.parameters.json

如果这有帮助,请告诉我。

,

通常在 TFS 管道中,您会定义变量并将它们作为参数传递给脚本。查看示例 here

但是,由于您专门处理 ARM 模板并考虑控制流(外/内循环等),因此您也可以查看其他几个选项

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。