1

I am trying to create a PowerShell script that would deploy an instance of Azure DevTest lab, create an environment there, and such resources as databricks, azure data factory, etc. This is part of my lab template responsible for that.

       "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",
               "location":"[parameters('location')]",
               "dependsOn":[
                  "[resourceId('Microsoft.DevTestLab/labs', parameters('labResourceName'))]"
               ]
            },
            {
               "apiVersion":"2018-09-15",
               "name":"Public Environment Repo",
               "type":"artifactSources",
               "location":"[parameters('location')]",
               "dependsOn":[
                  "[resourceId('Microsoft.DevTestLab/labs', parameters('labResourceName'))]"
               ],
               "properties":{
                  "status":"Enabled"
               }
            },
            {
               "apiVersion":"2018-09-15",
               "name":"[parameters('repositoryName')]",
               "type":"artifactSources",
               "dependsOn":[
                  "[resourceId('Microsoft.DevTestLab/labs', parameters('labResourceName'))]"
               ],
               "properties":{
                  "uri":"MY_URL",
                  "armTemplateFolderPath":"MY_PATH",
                  "displayName":"DevTestLab",
                  "branchRef":"features/devops-development",
                  "securityToken":"MY_TOKEN",
                  "sourceType":"VsoGit",
                  "status":"Enabled"
               }
            },
            {
               "apiVersion":"2018-09-15",
               "name":"[parameters('userId')]",
               "type":"users",
               "location":"[parameters('location')]",
               "dependsOn":[
                  "[resourceId('Microsoft.DevTestLab/labs', parameters('labResourceName'))]"
               ],
               "properties":{
                  "status":"Enabled"
               },
               "resources":[
                  {
                     "name":"devtestlaab",
                     "type":"environments",
                     "apiVersion":"2018-09-15",
                     "location":"[parameters('location')]",
                     "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('labResourceName'), parameters('userId'))]"
                     ]
                  }
               ]
            }
         ]
      }
   ]

It works fine for the most part. However, I am not able to pass parameters for my inner templates. It just takes whatever is hardcoded inside of those templates on my ref_branch at a given moment and deploys it.

enter image description here

I have tried to follow the following template and add the parameters part but it's being completely ignored.

{
  "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"
  }
}

So to summarize, I am able to deploy:

  • Lab
  • Environment
  • Resources inside of this lab.

I am not able to:

  • Pass any parameters to the resources within my lab environment.

The documentation is very scarce and so I am not really sure what the problem could be.

Hi guy
  • 35
  • 1
Grevioos
  • 355
  • 5
  • 30

2 Answers2

0

AFAI understand, your template looks wrong. Pls check out A quick guide on writing your Azure Resource Manager (ARM) Templates for understanding how to use parameters.

And, for PowerShell script deployment, you can use below command to deploy ARM template with parameters:

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

OR

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

Let me know if this helps.

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
  • Hi, thank you, although it's a bit different. I use the way you have described to deploy the lab resource itself. But I also want to create an environment within this lab and deploy different resources to this environment. So my 'outer' template is supposed to call the 'inner' artifact template and deploy all of the resources specified there to my environment. I find this devtest lab a bit confusing, so I hope I have explained it better this time. – Grevioos Apr 01 '21 at 10:31
0

Generally in TFS pipelines, you would define variables and pass them to the scripts as arguments. See examples here.

However since you are dealing specifically with ARM templates and thinking about control flow (outer/inner loops, etc.) you can look at a couple of other options as well