Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Pavan
Pavan

Posted on

     

JSON Parameters in Bicep Template

Hello Techies,

I am sure you all must have heardBicep new kid around the Microsoft Block to do Infrastructure As Code (IAC) (Domain Specific Language) to manage the deployments of Azure Resources.This is great learning module from Microsoft which covers basics to advanced

One thing I like about it is there aremany ways to pass the parameters to the Bicep Template. [Check out his blog, he has got some amazing content on Azure DevOps] Long story short you can pass parameters through param files, same like the way we pass to Arm Templates, or they can be inline through az deployment group command or it can be combination.

Scenario: Lets say you want different environments to have different Storage Account Skus (Standard LRS for DEV and Standard RAGZRS for Production) Although bicep object param can do similar job but it is not as flexible as plain JSON. It is not possible to pass the Object Param through command inline (Atleast I didnt find a way). JSON string can be minified and can be managed through Azure DevOps variables.

We can acheieve this by using jsonBicep Functions

Below example is to pass normal JSON Object(Not Arm Schema based) to the Bicep Template as inline Parameter.

param storageJsonString stringparam location string = resourceGroup().location#Using Json Function to parse the Json string to json objectvar storageConfig = json(storageJsonString)resource storage_account 'Microsoft.Storage/storageAccounts@2021-09-01'= {  kind: storageConfig.kind  name: storageConfig.name  location: location  sku: {    name: storageConfig.sku  }  properties: {    allowBlobPublicAccess: true    accessTier: 'Hot'  }}
Enter fullscreen modeExit fullscreen mode

Call this from PowerShell by passing inline JSON string parameter to this template.

$stg = '{\"name\":\"pa1pocstg\",\"sku\":\"Standard_LRS\",\"kind\":\"StorageV2\"}'az deployment group create --resource-group $rg `--template-file .\Bicep101\bicep-json.bicep `--parameters storageJsonString=$stg
Enter fullscreen modeExit fullscreen mode

Let me know what you think.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
roy77 profile image
roy
  • Joined

@chintupawan hi i keep getting formatting issues. What Devops pipeline task do you use? gr roy

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromPavan

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp