AZ-104 Question 121
Single answerYou have an existing Bicep file that deploys an Azure Storage Account resource named 'stgAccount'. You need to modify this file so that the resource ID of 'stgAccount' can be referenced in subsequent deployments. Which approach should you use?
- A
Add an output property at the top level that sets its value to stgAccount.id.
- B
Declare a new parameter in the same Bicep file that uses the resourceId() function to retrieve stgAccount’s ID.
- C
Wrap the existing resource definition in a new module and declare an output inside that module for the storage account’s name.
- D
Create a variable assigning stgAccount’s location and pass that variable as an output for subsequent deployments.
Show answer and explanation
Correct answer: A
Explanation
In Bicep, you can directly reference the resource symbol’s .id property in an output declaration. This is the simplest and most efficient way to expose the resource ID for future deployments or references.
- A. Correct.
By defining an output at the root level of the Bicep file referencing stgAccount.id, you can easily pass the resource ID to other deployments.
- B. Incorrect.
Simply declaring a parameter won’t provide the actual resource ID unless it’s passed in during deployment. This approach is unnecessary when the resource is already defined.
- C. Incorrect.
Wrapping the resource in a separate module adds unnecessary complexity if you only need to expose the resource ID. You can directly reference stgAccount at the root file level.
- D. Incorrect.
Referencing the storage account’s location property does not help in returning the resource ID, which is required for subsequent resource references.