Bicep | Use parameters optionally in template

Alok Maheshwari 1 Reputation point
2021-11-10T13:57:07.927+00:00

Hi team,

I create a bicep template for backup policy, the template i have created has all 4 types of retention configured (daily, weekly, monthly, yearly). all of the required inputs for all 4 retentions are parameterized (i.e. backup retention, schedule etc. ).

now if i want to use the same template to only configure a policy that has daily backups or Weekly backups how can i use the same template?

I tried using existing template and it was obvious that i didnt provide inputs for monthly and yearly retention, i got an error.

if i want to do the same with powershell, i can mark those parameters optional. that way i dont have to provide an input for those.

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,244 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,361 Reputation points
    2021-11-15T09:53:39.45+00:00

    Hi @Alok Maheshwari ,

    Welcome to Microsoft Q&A! Thanks for posting the question.

    You may use a combination of following features of Bicep to add conditional logic to your template:
    1. Deploy Conditon - This helps you to conditionally deploy resource.
    2. Default Values of Parameters - The default value is used when a value is not provided during deployment.

    Here are some Microsoft learn modules to help you understand it in detail:

    1. Build flexible Bicep templates by using conditions and loops
    2. Add flexibility by using parameters and variables

    ---
    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


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.