0
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?

Bicep Tips - Bicep事始め3(App Serviceの環境変数)

Posted at

概要

前回の続き。
前回、Bicepでリソースグループの作成と、リソースグループの中にApp Serviceを作成するところまでできました。
今回は、App Serviceの環境変数の設定についてチャレンジしてみたいと思います。

環境

・MacBook Air
・Power Shell
・Azure PowerShell
・Visual Studio Code

やりたいこと

①App Serviceを常時接続ONにしておきたいと思います。

②App ServiceでホストするWebアプリは、基本的に日本国内の事業者向けSaaSが多いので、
あらかじめタイムゾーン設定をしておきたいと思います。

App Serviceのタイムゾーンの設定は、環境変数にWEBSITE_TIME_ZONEを設定します。
変数に設定する値は、下記の記事を参照。
App Service Tips - タイムゾーンの設定
→自分が書いた記事、もう5年も前なのね・・・

手順

どちらも、App Serviceの項目の「SiteConfig」の中に、プロパティ値を追加する必要があります。

常時接続ONの設定

alwaysOnプロパティをtrueで設定します。

alwaysOn: true

環境変数の設定(今回はタイムゾーン設定)

appSettingsプロパティを設定します。
このプロパティの値は、nameとvalueの組み合わせを配列のように記述するようです。

      appSettings: [
        {
          name: 'WEBSITE_TIME_ZONE'
          value: 'Asia/Tokyo'
        }
      ]

前回作成したappservice.bicepは、最終的に以下のようになります。

param webAppName string // Generate unique String for web app name
param sku string = 'B1' // The SKU of App Service Plan
param linuxFxVersion string = 'DOTNETCORE|8.0' // The runtime stack of web app
param location string = resourceGroup().location // Location for all resources
var appServicePlanName = toLower('AppServicePlan-${webAppName}')
var webSiteName = toLower('${webAppName}')

resource appServicePlan 'Microsoft.Web/serverfarms@2020-06-01' = {
  name: appServicePlanName
  location: location
  properties: {
    reserved: true
  }
  sku: {
    name: sku
  }
  kind: 'linux'
}

resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: webSiteName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: linuxFxVersion
      alwaysOn: true
      appSettings: [
        {
          name: 'WEBSITE_TIME_ZONE'
          value: 'Asia/Tokyo'
        }
      ]
    }
  }
}

実行結果

前回と同じように、Azure PowerShellで以下のコマンドを実行します。
※カレントディレクトリの移動およびAzureとの接続が完了している前提。

New-AzSubscriptionDeployment -location japanwest -TemplateFile main.bicep -resourceGroupName demoResourceGroup -resourceGroupLocation japanwest -webAppName HapikuroTestWebApp

生成されたApp Serviceの構成と環境変数をポータル上で確認します。
image.png

image.png

ちゃんと設定されることが確認できました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?