1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

パラメータと変数をBicepテンプレートに追加する

Posted at

はじめに

前回の続きです。

Microsoftのチュートリアルに沿ってBicepの使用感を確かめていきます。

Bicepテンプレートに変数を追加

サンプルコードを以下に示します。

param location string = 'westus3'
param storageAccountName string = 'toylaunch${uniqueString(resourceGroup().id)}'
param appServiceAppName string = 'toylaunch${uniqueString(resourceGroup().id)}'

@allowed([
  'nonprod'
  'prod'
])
param environmentType string

var appServicePlanName = 'toy-product-launch-plan'
var storageAccountSkuName = (environmentType == 'prod') ? 'Standard_GRS' : 'Standard_LRS'
var appServicePlanSkuName = (environmentType == 'prod') ? 'P2v3' : 'F1'

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
  name: storageAccountName
  location: location
  sku: {
    name: storageAccountSkuName
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}

resource appServicePlan 'Microsoft.Web/serverFarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSkuName
  }
}

resource appServiceApp 'Microsoft.Web/sites@2022-03-01' = {
  name: appServiceAppName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    httpsOnly: true
  }
}

コード上部に変数とデフォルト値を設定しています。リソース名称にはuniqueString()関数が含まれており一意の値が設定されます。environmentalTypeprodnonprodの値をセットできる変数として宣言されていますが、デフォルト値は設定されていません。実行時に明示的に指定が必要です。もし指定しなかった場合は確認されます。
Bicep3.png

こちらのコマンドで実行します。

New-AzResourceGroupDeployment `
  -TemplateFile main.bicep `
  -environmentType nonprod

デプロイが完了したことが無事に確認できました。
Bicep4.png
Bicep5.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?