0
votes

I'm building a set of ARM templates to deploy all the resources I need for my app, and I'm specifying an environmentPrefix parameter in the parameter file, and prefixing all the resource names with the environment prefix. The end result is then, for example, an app service in the dev environment with a base name of service1 would get the resource name dev-service1.

The resources for a given environment should be deployed into a resource group with the same environment prefix, eg, dev-core-services.

I want to fail the template deployment if the RGs name does not start with the parameter files environmentPrefix. For example, if you to deploy a template using a parameter file that defines environmentPrefix = dev into an RG named prod-core-services, the deployment will fail.

I know I can put a condition element on individual resources that looks something like this,

"condition": "[if(startsWith(resourceGroup().name, concat(parameters('EnvironmentPrefix'), '-')), bool('true'), bool('false'))]",

But if I do that to all the resources, the template deployment will say it succeeded when it didn't actually deploy anything - because their condition elements all evaluated to false.

Any ideas how to fail the deployment on a condition like that?

(I know there are other alternatives for doing this safely, like different subscriptions for prod vs dev, or doing the deployment with different service principles that have different access permissions, etc, but this is what I have to work with at the moment :-(

1

1 Answers

1
votes

you can create a resource that will 100% fail and deploy it only when your condition fails, but I think you should be looking at ARM policies, this is something they are created to solve.

take a look at this question:
How can I create an Azure policy that validates Resource Group Names