Microsoft Visual Studio でクラウド リソースをプロビジョニングする

TeamsFx は Azure と Microsoft 365 クラウドと統合されており、1 つのコマンドでアプリを Azure に配置できます。 TeamsFx は Azure Resource Manager (ARM) と統合され、アプリケーションでコード アプローチに必要な Azure リソースをプロビジョニングできます。

Azure アカウントにサインインする

  1. Visual Studio を開きます。

  2. Microsoft Teams App プロジェクトを開きます。

  3. クラウドで [Project>Teams Toolkit>Provision] を選択します

    Azure アカウントへのサインインを示すスクリーンショット。

  4. [ サインイン...] を選択します

    Azure アカウントへのサインインを示すスクリーンショット。

    注:

    既にサインインしている場合は、ユーザー名が表示されるか、[ アカウントの追加] オプションが表示されます。

    資格情報を使用して Azure アカウントにサインインすると、ブラウザーは自動的に閉じます。

クラウド リソースをプロビジョニングする

Visual Studio でプロジェクトを開いた後、クラウド リソースをプロビジョニングするには、次の手順に従います。

  1. Cloud...で [Project>Teams Toolkit>Provision] を選択します

    クラウドでプロビジョニングする方法を示すスクリーンショット。

    [ プロビジョニング] ウィンドウが表示されます。

  2. リソースをプロビジョニングするには、次の詳細を入力します。

    1. ドロップダウン メニューから サブスクリプション名 を選択します。
    2. ドロップダウン メニューからリソース グループを選択するか、[新規作成]を選択して新しいリソース グループを作成できます。
    3. ドロップダウン メニューから [リージョン ] を選択します。
    4. [プロビジョニング] を選択します。

    リソース グループの選択を示すスクリーンショット。

  3. 表示されるポップアップ ウィンドウで、[プロビジョニング] を選択 します

    プロビジョニングの警告を示すスクリーンショット。

    プロビジョニング プロセスでは、Azure クラウドにリソースが作成されます。 [ツールキットの出力] ウィンドウMicrosoft Teams監視することで、進行状況を監視できます。

  4. 表示されるポップアップ ウィンドウで、プロビジョニングされているすべてのリソースを表示するには、[ プロビジョニングされたリソースの表示] を選択します。

    プロビジョニングされたリソースを示すスクリーンショット。

プロビジョニング アクション

次のアクションは、プロビジョニング用に設計されています。

teamsApp/create

Teams アプリ ID を格納する環境変数が空であるか、アプリ ID が Teams 開発者ポータルから見つからない場合、 teamsApp/create アクションによって新しい Teams アプリが作成されます。 これは、Teams 開発者ポータルの Teams アプリで動作します。

  - uses: teamsApp/create
    with: 
      # #required. Name of Teams app
      name: <your-preferred-app-name>
      # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The id for Teams app
      teamsAppId: <your-preferred-env-var-name>

teamsApp/update

Teams 開発者ポータルで Teams アプリ マニフェストを既存の Teams アプリに適用する場合。 teamsApp/update action は、manifest.json ファイル内のアプリ ID を使用して、更新する Teams アプリを決定します。 これは、Teams 開発者ポータルの Teams アプリで動作します。

- uses: teamsApp/update
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/validateManifest

teamsApp/validateManifest アクションは、環境変数を使用して Teams アプリ マニフェスト テンプレートをレンダリングし、そのスキーマを使用して Teams アプリ マニフェスト ファイルを検証します。

- uses: teamsApp/validateManifest
    with:
      # Required. Relative path to the yaml file. Path to Teams app manifest file
    manifestPath: <path-to-manifest-file>

teamsApp/validateAppPackage

teamsApp/validateAppPackage アクションは、検証ルールを使用して Teams アプリ パッケージを検証します。

  - uses: teamsApp/validateAppPackage
      with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
    appPackagePath: <path-to-teams-app-package-file>

teamsApp/zipAppPackage

teamsApp/zipAppPackage アクションは、環境変数を含む Teams アプリ マニフェスト テンプレートをレンダリングし、2 つのアイコンを含むマニフェスト ファイルを zip ファイルに圧縮します。

- uses: teamsApp/zipAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for Teams app manifest file. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
    manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml file. This is the path for built zip file.
    outputZipPath: <path-to-generated-zip-file>
      # Required. Relative path to the yaml file. This is the path for built manifest json file.
    outputJsonPath: <path-to-generated-json-file>

teamsApp/publishAppPackage

teamsApp/publishAppPackage アクションは、ビルドされた Teams アプリ zip ファイルをテナント アプリ カタログに発行します。 Microsoft 365 テナント アプリ カタログで動作します。

- uses: teamsApp/publishAppPackage
    with:
      # Required. Relative path to this file. This is the path for built zip file.
    appPackagePath: <path-to-teams-app-package>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The Teams app id in tenant app catalog.
    publishedAppId: <your-preferred-env-var-name>

aadApp/create

aadApp/create アクションは、clientIdを格納する環境変数が空の場合にユーザーを認証する新しい Microsoft Entra アプリケーションを作成します。 Microsoft 365 テナントの Microsoft Entra ID で動作します。

- uses: aadApp/create
    with:
      # Required. The Microsoft Entra app's display name. When you run aadApp/update, the Microsoft Entra app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in Microsoft Entra app manifest is the same with the name defined here.
      name: <your-application-name>
      # Required. If the value is false, the action will not generate client secret for you
      generateClientSecret: true
      # Required. Specifies what Microsoft accounts are supported for the current application. Supported values are: `AzureADMyOrg`, `AzureADMultipleOrgs`, `AzureADandPersonalMicrosoftAccount`, `PersonalMicrosoftAccount`.
      signInAudience: "AzureADMyOrg"
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # Required. The client (application) ID of Microsoft Entra application. The action will refer the environment variable defined here to determine whether to create a new Microsoft Entra app.
      clientId: <your-preferred-env-var-name>
      # Required when `generateClientSecret` is `true`. The action will refer the environment variable defined here to determine whether to create a new client secret. It's recommended to add `SECRET_` prefix to the environment variable name so it will be stored to the .env.{envName}.user environment file.
      clientSecret: <your-preferred-env-var-name>
      # Required. The object ID of Microsoft Entra application
      objectId: <your-preferred-env-var-name>
      # Optional. The tenant ID of Microsoft Entra tenant
      tenantId: <your-preferred-env-var-name>
      # Optional. The Microsoft Entra authority
      authority: <your-preferred-env-var-name>
      # Optional. The host name of Microsoft Entra authority
      authorityHost: <your-preferred-env-var-name>

aadApp/update

aadApp/update action は、Microsoft Entra アプリ マニフェストに基づいて Microsoft Entra アプリケーションを更新します。 これは、Microsoft Entra アプリ マニフェストの ID プロパティを参照して、更新する Microsoft Entra アプリを決定します。 aadApp/update は、Microsoft 365 テナントの Microsoft Entra ID で動作します。

- uses: aadApp/update
    with:
      # Required. Relative path to the yaml file. Path to the Microsoft Entra app manifest. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml folder. This action will output the final Microsoft Entra app manifest used to update Microsoft Entra app to this path.
      outputFilePath : <path-to-output-file>

botAadApp/create

botAadApp/create アクションは、ボット用に新しい Microsoft Entra アプリケーションを作成するか、既存の Microsoft Entra アプリケーションを再利用します。 Microsoft 365 テナントの Microsoft Entra ID で動作します。

- uses: botAadApp/create
    with:
      # Required. The Microsoft Entra app's display name
      name: <your-app-name>
    writeToEnvironmentFile:
      # The The Microsoft Entra app's client id created for bot.
      botId: <your-preferred-env-var-name>
      # The The Microsoft Entra app's client secret created for bot. 
      botPassword: <your-preferred-env-var-name>

arm/deploy

arm/deploy アクションは、指定された ARM テンプレートを並列にデプロイします。 Azure サブスクリプションで動作します。

- uses: arm/deploy
    with:
      # Required. You can use built-in environment variable `AZURE_SUBSCRIPTION_ID` here. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select subscription if it's empty in this case.
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      # Required. You can use built-in environment variable `AZURE_RESOURCE_GROUP_NAME` here. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select or create resource group if it's empty in this case.
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      # Required. The ARM templates to be deployed.
      templates:
        # Required. Relative path to the yaml file.
      - path: <path-to-arm-template>
        # Optional. Relative path to the yaml file. TeamsFx will replace the environment variable reference with real value before deploy ARM template.
        parameters: <path-to-arm-template-parameter>
        # Required. Name of the ARM template deployment.
        deploymentName: <arm-deployment-name>
      # Optional. Teams Toolkit will download this bicep CLI version from github for you, will use bicep CLI in PATH if you remove this config.
      bicepCliVersion: v0.9.1

azureStorage/enableStaticWebsite

azureStorage/enableStaticWebsite アクションを使用すると、Azure Storage で静的 Web サイト設定が有効になります。 Azure Storage で動作します。

- uses: azureStorage/enableStaticWebsite
    with:
      # Required. The resource id of Azure Storage
      storageResourceId: ${{<env-name-of-azure-storage-resource-id>}}
      # Required. The path to index page.
      indexPage: <path-to-index-page>
      # Required. The path to error page.
      errorPage: <path-to-error-page>

スクリプト

script アクションは、ユーザー定義スクリプトを実行します。

- uses: script
    with:
     # Required. Command to run or path to the script. Succeeds if exit code is 0. '::set-teamsfx-env key=value' is a special command to generate output variables into .env file, in this case, "mykey=abc" will be added the output in the corresponding .env file.
     run: $my_key="abc"; echo "::set-teamsfx-env mykey=${my_key}"
     # Optional. Available values are: bash, sh, powershell(Powershell Desktop), pwsh(powershell core), cmd. If omitted, it defaults to bash on Linux/MacOS, defaults to pwsh on windows.
     shell: <shell-name>
     # Optional. Current working directory. Defaults to the directory of this file.
     workingDirectory: <working-directory>
     # Optional. Timeout in ms.
     timeout: <timeout-in-ms>
     # Optional. Redirect stdout and stderr to a file.
     redirectTo: <path-to-output-file>

リソースのプロビジョニングをカスタマイズする

プロビジョニング手順は、provision プロパティのteamsapp.yml ファイルで定義されます。 provision プロパティにアクションを追加、削除、または更新して、プロビジョニング中に実行する必要があるアクションを定義できます。

パラメーター ファイル内の参照環境変数

Teams Toolkit では、 teamsapp.yml ファイル、Teams アプリ マニフェスト、Microsoft Entra アプリ マニフェスト、Azure パラメーター ファイル内の環境変数からの値の参照がサポートされています。 構文 ${{ENV_VARIABLE_NAME}} を使用して環境変数を参照できます。

次の例では、環境変数 MY_AZURE_SUBSCRIPTION_ID の値を subscriptionId に設定します。

subscriptionId: ${{MY_AZURE_SUBSCRIPTION_ID}}

ARM テンプレート ファイルをカスタマイズする

定義済みのテンプレートがアプリの要件を満たしていない場合は、独自の ARM テンプレートを作成するか、既存の ARM テンプレートを更新し、 arm/deploy アクションへのパスを次のように指定します。

- uses: arm/deploy
    with:
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      templates:
      - path: <path-to-your-arm-template>
        parameters: <path-to-your-parameter-file>
        deploymentName: <arm-deployment-name>
      bicepCliVersion: <bicep-cli-version>

arm/deploy アクションでは、bicep 形式と json 形式で記述された ARM テンプレートがサポートされています。 json 形式を使用する場合は、 bicepCliVersion パラメーターを省略できます。 Azure Resource Manager に関する基本的な知識が必要です。 詳細については、 Azure Resource Manager のドキュメントを参照してください

リソースを管理する

Azure portal にサインインし、Teams Toolkit を使用して作成されたすべてのリソースを管理できます。

  • 既存の一覧または作成した新しいリソース グループからリソース グループを選択できます。
  • 選択したリソース グループの詳細は、目次の概要セクションで確認できます。

Teams アプリをカスタマイズする

作成した Microsoft Entra アプリを使用するように環境変数を追加することで、ボットまたは Teams アプリをカスタマイズできます。 Teams アプリは、次の方法でカスタマイズできます。

Teams アプリに既存の Microsoft Entra アプリを使用する

Teams アプリ用に作成された Microsoft Entra アプリを使用し、環境変数を .env ファイルに追加するには、次の手順に従います。

  1. teamsapp.yml ファイルを開き、aadApp/create アクションを見つけます。

  2. microsoft Entra アプリの情報を格納する環境変数名を writeToEnvironmentFile プロパティで見つけます。 Teams Toolkit を使用してプロジェクトを作成する場合、既定の writeToenvironmentFile プロパティ定義は次のようになります。

     writeToEnvironmentFile:
      clientId: AAD_APP_CLIENT_ID
      clientSecret: SECRET_AAD_APP_CLIENT_SECRET
      objectId: AAD_APP_OBJECT_ID
      tenantId: AAD_APP_TENANT_ID
      authority: AAD_APP_OAUTH_AUTHORITY
      authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST
    
  3. 手順 2. から各環境変数の値を追加します。

    1. ファイルに次の環境変数とその値 env\.env.{env} 追加します。 例:

       AAD_APP_CLIENT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OBJECT_ID=<value of Microsoft Entra application's object id> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_TENANT_ID=<value of Microsoft Entra's (tenant) id>> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OAUTH_AUTHORITY=<value of Microsoft Entra's authority> # example: https://login.microsoftonline.com/<Directory (tenant) ID>
       AAD_APP_OAUTH_AUTHORITY_HOST=<host of Microsoft Entra's authority> # example: https://login.microsoftonline.com
       AAD_APP_ACCESS_AS_USER_PERMISSION_ID=<id of access_as_user permission> # example: 00000000-0000-0000-0000-000000000000
      
    2. アプリケーションで Microsoft Entra アプリ クライアント シークレットが必要な場合は、次の環境変数とその値をファイル env\.env.{env}.user 追加します。 例:

      SECRET_AAD_APP_CLIENT_SECRET=<value of Microsoft Entra application's client secret>
      

Microsoft Entra アプリがまだない場合、または Microsoft Entra アプリを持っていても、正しい値を見つける場所がわからない場合は、「 TeamsFx プロジェクトで既存の Microsoft Entra アプリを使用する」を参照してください。

注:

  • writeToEnvironmentFileで異なる名前を使用する場合は、例の環境変数の名前を必ず更新してください。
  • aadApp/createアクションを使用して Microsoft Entra アプリケーションを作成しない場合は、上記の手順に従わずに、任意の名前で必要な環境変数を追加できます。
  • 複数の環境で同じ Microsoft Entra アプリを共有しないようにします。

ボットに既存の Microsoft Entra アプリを使用する

次の手順に従って、環境変数を .env ファイルに追加して、Teams アプリ用に作成された Microsoft Entra アプリを使用できます。

  1. teamsapp.yml ファイルを開き、botAadApp/create アクションを見つけます。

  2. microsoft Entra アプリの情報を格納する環境変数名を writeToEnvironmentFile プロパティで見つけます。 Teams Toolkit を使用してプロジェクトを作成する場合の既定の writeToEnvironmentFile 定義は次のとおりです。

     writeToEnvironmentFile:
       botId: BOT_ID
       botPassword: SECRET_BOT_PASSWORD
    
  3. 手順 2. から各環境変数の値を追加します。

    1. 環境変数とその値をファイルに追加 env\.env.{env} 。 例:

      BOT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000    
      
    2. 環境変数とその値をファイルに追加 env\.env.{env}.user 。 例:

      SECRET_BOT_PASSWORD=<value of Microsoft Entra application's client secret>
      

ボット用の Microsoft Entra アプリがまだない場合や、適切な値を見つける場所がわからない場合は、「 TeamsFx プロジェクトで既存の Microsoft Entra アプリを使用する」を参照してください。

注:

  • writeToEnvironmentFileで異なる名前を使用する場合は、例の環境変数の名前を必ず更新してください。
  • botAadApp/createアクションを使用して Microsoft Entra アプリケーションを作成しない場合は、上記の手順に従わずに、任意の名前で必要な環境変数を追加できます。
  • 複数の環境で同じ Microsoft Entra アプリを共有しないようにします。

関連項目