AZ-104 Question 117
Single answerYou are reviewing a Bicep file that deploys several resources to an existing resource group. The file includes a parameter named 'location' but does not set a default value for it. During deployment, you notice repeated errors indicating that the 'location' parameter is not provided. You want to ensure that all resources are automatically deployed to the same location as the resource group without requiring user input. Which method best achieves this goal?
- A
Add a default value referencing resourceGroup().location in the existing 'location' parameter so it doesn't require user input.
- B
Remove the 'location' parameter and use the resourceGroup() function directly in the resource's location property.
- C
In the deployment command, specify --location [resourceGroup().location] so that the location parameter is automatically filled.
- D
Use an inline variable to store the region name and pass it to the location property of each resource definition.
Show answer and explanation
Correct answer: B
Explanation
When deploying resources in the same location as the resource group, it is best to reference resourceGroup().location directly. This approach means you do not need to pass a parameter for location, and you avoid potential mismatches or user errors in specifying a separate location.
- A. Incorrect.
Setting a default value referencing resourceGroup().location helps, but you still have a parameter that could be overridden or cause confusion if a user attempts to supply a separate location.
- B. Correct.
Using resourceGroup().location directly in each resource eliminates the need for a location parameter and ensures the resource location always matches the resource group.
- C. Incorrect.
Specifying --location [resourceGroup().location] at deployment time is not valid syntax and, even if corrected, would still require user input rather than automatically matching the resource group location.
- D. Incorrect.
Using an inline variable for the region name is possible, but it still relies on you defining the location somewhere. It does not inherently guarantee matching the resource group location unless you explicitly call resourceGroup().location.