Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I get the location from the az deployment command line in a bicep script?

Currently, I have a param in my bicep script to set the location:

targetScope = 'subscription'

@minLength(1)
param location string

@minLength(1)
param resourceGroupName string

resource myRG 'Microsoft.Resources/resourceGroups@2022-09-01' = {
  name: resourceGroupName
  location: location
}

However, since I need to pass in the location to the command line argument, that’s repetition:

# az deployment sub create --location eastus --template-file main.bicep
Please provide string value for 'location' (? for help):

I couldn’t find a way to just get the value of my --location argument into the bicep script. I know I could set it as an environment variable and change the invocation to something like az deployment sub create --location $LOCATION --template-file main.bicep --parameters location=$LOCATION, but I wonder if there is a proper way to not have to repeat the location in two different places?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Unfortunately, it’s not possible.

The --location parameter for subscription scope deployments tells ARM where to store deployment metadata.

There is no real relationship between the az argument, and your Bicep parameter. And there is no concept of a location associated with a subscription.

Not often I say it, but no. No way around it in this instance.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading