biceps verify current subscription id

Jan Vávra 386 Reputation points
2023-01-12T14:42:07.7766667+00:00

Hello. Can I somehow verify current subscription id in my bicep script to prevent to be run on bad subscription?
My plan is to place the subscription id in paramters.json.

Community Center | Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Roderick Bant 2,056 Reputation points
    2023-01-12T17:23:07.13+00:00

    Hi, thanks for your question at Q&A.

    You can get the ID of the current subscription as subscription().subscriptionId in your Bicep code. You could compare that to the parameters you plan to create and then conditionally deploy the resources. See this documentation on conditional deployment.

    To prevent code becoming overly complex by using this practice you could wrap resourcegroup scoped deployments as modules in a subscription scoped deployment where you conditionally deploy the modules. That way you can keep the code for the modules themselves tidy and simple.

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.