0
votes

I have an ARM template to deploy/update the full Azure infrastructure for my application. Our build server should run the template, and add/update/delete resources that are add/changed/deleted. To make this work, I have chosen for the "Complete" deployment mode.

To test the ARM template, I have to following power shell script:

 param(
   $tenantId = "",
   $subscriptionId = ""
)
Clear-Host
Login-AzureRmAccount -TenantId $tenantId -SubscriptionId $subscriptionId 
New-AzureRmResourceGroupDeployment `
    -Name "x" `
    -ResourceGroupName "rg-test" `
    -TemplateFile $PSScriptRoot/resource-template.json `
    -TemplateParameterFile  $PSScriptRoot/parameters-test.json `
    -Mode Complete

This powershell script is only used to test the template, because a vsts release step will be responsible for the execution of the ARM template into the resource group.

We want to use 1 template to deploy everything (to keep it simple, just a Web Service plan and a web app service), but we have resources that doesn't need to be deployed in some environments. Different environments will use different pricing plans, and some of them will need a Deployment Slot, others won't (to save costs).

I have read about the nested templates, and at first it seemed to solve my problem... but it doesn't. I cannot use the nested templates in a "Complete deployment".

Does anyone know another way, to flag if a resource needs to be deployed or not, is not the "nested-template"-approach and works for the full deployment type?

1
Conditionally deploying resources isn't natively supported in ARM - you have to get creative to do this (many samples do it on github)... That said, do you need to use "complete" mode? Or could you simply delete the RG before deployment? That would allow a nested templates + parameters approach to work...bmoore-msft

1 Answers

1
votes

We could create different parameter files for different environments (dev, test, or production), and then we could customize the deployment by providing values that are tailored for a particular environment. Besides, as we know, we could use nested templates for conditional deployment, but only the root-level template is allowed Complete for the deployment mode. If you have to use Complete mode, you may need to write script to dynamically generate your templates for different environments based on your requirements and business logic.