2
1

Bicepを使ってAzureDevOpsのパイプラインからリソースをデプロイしたメモ

Posted at

概要

前回は、Bicepを使ってのリソース構築を行った。
今回は、AzureDevOpsのパイプラインからのデプロイを行う。

ファイル構成

毎回動く必要はないので、infrastructureフォルダ以下のファイルに変更があったときのみ動作するトリガー設定をした。

- azure-dev-ops
  - app-deploy-pipelines.yaml
  - iac-pipelines.yaml
- infrastructure
  - bin
    - create.bash
  - biceps
    - resourceGrop.bicep
    - staticWebApp.bicep

パイプライン

azure-dev-ops/iac-pipelines.yaml
trigger:
  branches:
    include:
      - main
  paths:
    include:
      - infrastructure/*
      - azure-dev-ops/iac-pipelines.yaml
pool:
  vmImage: ubuntu-latest
steps:
- task: AzureCLI@2
  inputs:
    azureSubscription: 'azure-dev-hobby'
    scriptType: 'bash'
    scriptLocation: 'scriptPath'
    scriptPath : 'infrastructure/bin/create.bash'

azureSubscription の設定

Create an Azure Resource Manager service connection that uses workload identity federation

  1. Azure DevOps のプロジェクトに移動
  2. 左側のメニューから "Project settings" を選択
  3. "Service connections" を選択
  4. "New service connection" をクリック

image.png

Azure Resource Managerの設定を行う

image.png

image.png

Service connectin nameにazure-dev-hobbyを設定。
(パイプラインに記載したazureSubscription: 'azure-dev-hobby')

image.png

これで追加は完了

image.png

パイプラインを作成して実行

前々回と同様、既存のリポジトリに含まれるファイルをパイプラインに設定する。(azure-dev-ops/iac-pipelines.yaml)

このとき、初回実行では許可を求められるので許可する。

image.png

image.png

これで、デプロイできた。

デプロイしたアプリ

2
1
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
2
1