LoginSignup
0
0

More than 1 year has passed since last update.

Azure Bicep_ユニークな名前でストレージアカウントを作成する

Last updated at Posted at 2021-11-19

Bicepでストレージアカウントを作成する際にユニーク値を付与する

Bicepコード

ユニーク値を出力するために uniqueString を使用する。

リソースグループのスコープで一意にするために ${uniqueString(resourceGroup().id)}とする。
※ユニーク値とは言うが、実際は引数のハッシュ値となるので注意。
参考:https://docs.microsoft.com/ja-jp/azure/azure-resource-manager/templates/template-functions-string#uniquestring

storageaccount-parameters.bicep
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "storageAccountName": {
        "value": "examplesa"
      }
  }
}
storageaccount.bicep
param storageAccountName string
param location string = resourceGroup().location

resource storageAccountName_resource 'Microsoft.Storage/storageAccounts@2019-06-01' = {
  name: '${storageAccountName}_${uniqueString(resourceGroup().id)}'
  location: location
  sku: {
    name: 'Standard_LRS'
    tier: 'Standard'
  }
  kind: 'StorageV2'
  properties: {
    supportsHttpsTrafficOnly: true
    encryption: {
      services: {
        file: {
          keyType: 'Account'
          enabled: true
        }
        blob: {
          keyType: 'Account'
          enabled: true
        }
      }
      keySource: 'Microsoft.Storage'
    }
    accessTier: 'Cool'
  }
}

作成されるストレージアカウント名(例)
examplesa_tcvhiyu5h2o5o

デプロイ

az deployment group create --resource-group examplerg --template-file storageaccount.bicep --parameters storageaccount-parameters.json
0
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
0
0