æ¬ã¨ã³ããªã¯ãã³ããã Advent Calendar 2024ã9æ¥ç®ã®è¨äºã§ãï¼
adventar.org
ããã«ã¡ã¯ãã¤ããã®åå¼ã£è¶ããããã®ã§ãããèªå®
ããå¯å£«å±±ãçºãããããã¨ã«æè¿æ°ã¥ããã³ã·ã§ã³ãä¸ãã£ã¦ãã @sasashuuu ã§ãã
æ¬æ¥ã¯ä»¥åè¡ã£ã CI/CD æ§ç¯ ã«ã¤ãã¦ã®ããã°ãçºä¿¡ãã¾ãã
èæ¯
å¼ç¤¾ã®ã¤ã³ãã©ã«é¢ãã¦ã¯ä¸»ã« AWS ã使ç¨ãã¦ãã¾ããããã¼ã¿åºç¤çã®ã·ã¹ãã 㯠Google Cloud ã§ç®¡çãããªã©ãã«ãã¯ã©ã¦ãã®æ§æãåã£ã¦ãã¾ãã
AWS ã«é¢ãã¦ã¯ IaC 管çã®ããã®åºç¤ãåå¨ãã¦ãããã®ã®ãGoogle Cloud ã«ã¯æãåã£ã¦ãããã»ã¼ç®¡çã§ãã¦ããªãç¶æ
ã§ããã
ãã㧠IaC ã®ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ãã¼ã«ã§ãã Terramate ã OIDC ãªã©ã®èªè¨¼ãå®ç¾ããããã® Google Cloud ã® Workload Identity é£æºã使ç¨ããGoogle Cloud å´ã® IaC 管çåºç¤ããã³ CI/CD ã GitHub Actions ã«ã¦ã¼ããã¼ã¹ã§æ§ç¯ãã¾ããã
æ¬ã¨ã³ããªã§ã¯ãç¹ã« CI/CD ã«ãã©ã¼ã«ã¹ããå½¢ã§å
容ãçºä¿¡ãããã¨æãã¾ããæ§ç¯æ¹æ³ã使ã£ã¦è¦ãææãªã©ãã¤ãã¤ãã¨ã¾ã¨ããå½¢ã«ã¯ãªãã¾ãããæè¡ã¹ã¿ãã¯ã¨ãã¦ãããã£ããã¼ã«ããµã¼ãã¹ã§ã®æ§æãããã¨ããå¼ãåºãã«ã¤ãªããä¸å©ã«ãªãã°å¹¸ãã§ãã
Terramate ã¨ã¯
IaC 管çã®ããã®ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ãã¼ã«ã§ããTerraformãOpenTofuãTerragrunt ã管ç対象ã«ãã¹ã¿ãã¯ãã¨å¼ã°ããç¬èªã®åä½ï¼Terraform ã§ããã°ãªã½ã¼ã¹ãã®ãã®ãè¨å®ã管çãã *.tf ãã¡ã¤ã«ã state ãªã©ã®çµã¿åãããã¨ã«æ§æãããåä½ï¼ããã¨ã«ããããããªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ãããã¨ãã§ãã¾ããå
·ä½ã®ã¦ã¼ã¹ã±ã¼ã¹ã«ã¤ãã¦ã¯å¾è¿°ãã¾ãããä¾ã¨ãã¦ä»¥ä¸ã®ãããªãã¨ãå¯è½ã§ãã
- ã¹ã¿ãã¯ã«å¯¾ãã¦ä¸æ¬ã§ã®ã³ãã³ãå®è¡
- ãã¡ã¤ã«ã®å¤æ´ããã£ãã¹ã¿ãã¯ã®ã¿ã対象ã¨ããã³ãã³ãå®è¡
terramate-io/terramate
Workload Identity é£æºã¨ã¯
å¾æ¥ã®ããæ¹ã§ãããµã¼ãã¹ã¢ã«ã¦ã³ãï¼ãµã¼ãã¹ã¢ã«ã¦ã³ããã¼ï¼ã使ã£ãèªè¨¼ã¨ç°ãªããID ãã§ãã¬ã¼ã·ã§ã³ã使ç¨ããã»ãã¥ã¢ãªèªè¨¼æ¹æ³ã§ãã
ãã®æ¹æ³ã«ãããã¯ã¬ãã³ã·ã£ã«æ
å ±ã®ã管çã³ã¹ããããæµåºã«ããã»ãã¥ãªãã£ãªã¹ã¯ããæ¸ãããã¨ãå¯è½ã§ããæ¬ã¨ã³ããªã§ã¯ GitHub Actions ãã Google Cloud ã¸ã¢ã¯ã»ã¹ããéã® OIDC èªè¨¼ã®ããã«ä½¿ç¨ãã¾ãã
Workload Identity é£æº
Terramate ã®å°å
¥
å§ãã«CI/CD ãçµã¿è¾¼ãã 対象ãªãã¸ããªã®å
¨ä½åãæ¸ãã¦ããã¨ä»¥ä¸ã®ãããªã¤ã¡ã¼ã¸ã§ãã
GitHub Actions ç¨ã¯ã¼ã¯ããã¼ãã¡ã¤ã«ã¯ .github/workflows ã«ãconfig.tm.hcl ãé¤ã Terramate ã Terraform é¢é£ã®ãã¡ã¤ã«ã¯ããã¸ã§ã¯ããã¨ã®ãã£ã¬ã¯ããªï¼ä¾ï¼projectAï¼ã«ä½æãã¦ãã¾ãã
.
âââ .github
â  âââ workflows
â  âââ projectA-pull-request.yaml
â  âââ projectA-push-tag.yaml
â  âââ template-pull-request.yaml
â  âââ template-push-tag.yaml
âââ config.tm.hcl
âââ projectA
â âââ terraform
â âââ backend.tf
â âââ iam.tf
â âââ monitoring.tf
â âââ provider.tf
â âââ stack.tm.hcl
â âââ version.tf
âââ projectB
...
Terramate ã«ããã¦ãã¤ã³ãã¨ãªãã®ã¯ã次ã®2ãã¡ã¤ã«ã§ãã
config.tm.hcl
- Terramate ã§èªåçã«çæããããã®å種 tf ãã¡ã¤ã«ï¼backend.tfãprovider.tfãversion.tf çï¼ã®å
容ãå®ç¾©ãã¦ããã
stack.tm.hcl
- Terramate ã«ãã£ã¦èªåçæããããã®ã§ãã¹ã¿ãã¯ã®ç®¡çã«å©ç¨ããã¾ããåºæ¬çã«æåã§ç·¨éãããã¨ã¯ãªããã¡ã¤ã«ã
config.tm.hcl ã®å
容
globals {
terraform_version = "x.x.x"
provider_version = "x.x.x"
}
generate_hcl "backend.tf" {
content {
terraform {
backend "gcs" {
bucket = "projectA-tfstate"
prefix = "hoge/terraform/${terramate.stack.tags[0]}"
}
}
}
}
generate_hcl "provider.tf" {
content {
provider "google" {
project = terramate.stack.tags[0]
}
}
}
generate_hcl "version.tf" {
content {
terraform {
required_version = global.terraform_version
required_providers {
google = {
source = "hashicorp/google"
version = global.provider_version
}
}
}
}
}
globals ã¯å¤æ°ãgenerate_hcl ã¯ãã¡ã¤ã«çæã®ããã® block ã¨ãã£ãå
·åã§ãã
stack.tm.hcl 㯠Terramate ã«ãã£ã¦èªåçæããããã®ã§ãã¹ã¿ãã¯ã®ç®¡çã«å©ç¨ããã¾ããåºæ¬çã«æåã§ç·¨éãããã¨ã¯ãªããã¡ã¤ã«ã§ãã
stack.tm.hcl ã®å
容
stack {
name = "terraform"
description = "terraform"
tags = ["projectA"]
id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
tags 㯠å¾ã«è§£èª¬ãã¾ãããterramate ã³ãã³ãã§ç¹å®ã®ã¹ã¿ãã¯ã対象ã«å®è¡ããéã«ä¾¿å©ãªæ©è½ã§ãã
ããããã¯å®éã®å°å
¥æ¹æ³ã«ã¤ãã¦è§£èª¬ãã¾ããä»åã¯ä½ããªãç¶æ
ã®ãªãã¸ããªã§ä¸ããä½æãããã¿ã¼ã³ã¨ãã¦ãã¾ãã
ã¾ãã¯å¯¾è±¡ã®ãã£ã¬ã¯ããªã§ git init ãå®è¡ãã¾ãã
git init
åè¿°ãã config.tm.hcl ãä½æãã¾ãï¼â»å
容ã¯åè¿°ããå®ç¾©ãåç
§ï¼ã
.
âââ config.tm.hcl
ãã®ç¶æ
㧠terramate create ãå®è¡ãã¾ãã
terramate create projectA/terraform --tags=projectA
Created stack /projectA/terraform
以ä¸ã®ããã« stack.tm.hcl å«ãé¢é£ãã¡ã¤ã«ãèªåçæããã¾ãã
.
âââ projectA
â  âââ terraform
â  âââ backend.tf
â  âââ provider.tf
â  âââ stack.tm.hcl
â  âââ version.tf
âââ config.tm.hcl
ããããåºæ¥ä¸ãã£ããã¡ã¤ã«ã®ä¸èº«ã¯ä»¥ä¸ã®ãããªå
容ã§ããè£è¶³ã§ãããstate ãã¡ã¤ã«ã®ä¿åå ´æ 㯠Cloud Strage ãæå®ãã¦ãã¾ããterraform ã®å®è¡åã«ã¯ããããã Cloud Storage ã« state ãã¡ã¤ã«ã管çããããã®ãã±ããã¯ä½æãã¦ããã¦ãã ããã
backend.tf
terraform {
backend "gcs" {
bucket = "projectA-tfstate"
prefix = "hoge/terraform/projectA"
}
}
provider.tf
provider "google" {
project = "projectA"
}
version.tf
terraform {
required_version = "x.x.x"
required_providers {
google = {
source = "hashicorp/google"
version = "x.x.x"
}
}
}
ä¸è¨ã§çæããããã¡ã¤ã«ã¯åºæ¬çã«ã¯æåã§ç·¨éãããã¨ã¯ãªãã試ãã«ãã¡ã¤ã«å
ãè¦ã¦ãããã¨ãããããã«ãDO NOT EDITãã®å®ç¾©ãåå¨ãã¦ãã¾ãã
...
ããããã Terraform ã® lock ãã¡ã¤ã«ã®çæãè¡ã£ã¦ããã¾ããstack ãä½æãããã£ã¬ã¯ããªã«ä½ãããããå®è¡ãã¾ãã
terraform -chdir=projectA/terraform providers lock \
-platform=linux_amd64 \
-platform=linux_arm64 \
-platform=darwin_amd64 \
-platform=darwin_arm64 \
-platform=windows_amd64
å¾ã«å®è¡ãã terramate run ã«ã¤ãã¦ãgit ä¸ã§ã³ããããã¦ããªããã¡ã¤ã«ã®å¤æ´ãããã¨å®è¡ã§ããªãã¨ããå¶ç´ããããããã®å¯¾å¿ãè¡ãªã£ã¦ãã¾ããGitHub Actions ä¸ã®ãã¹ãããã©ã³ãã¼ã§å®è¡ãã terraform init ã«ãã lock ãã¡ã¤ã«ã«å¤æ´ããããããã¡ã¤ã«å·®åãçºçããã¾ã¾å¾ç¶ãã terraform plan ãå®è¡ã§ããªãã¨ããäºæ
ãé²ãç®çã§è¡ãã¾ãï¼ã¾ããå¹
åºããã©ãããã©ã¼ã ã¸ã®å¯¾å¿ãå
¼ãä¸è¨ã®ããã«å®è¡ï¼ã
ããã¾ã§ã§çæãããå種ãã¡ã¤ã«ã¯ä¸åº¦ã³ããããã¦ããã¦ãã ããï¼åè¿°ããããã«ã³ããããã¦ããªããã¡ã¤ã«ããã㨠terramate run ãå®è¡ã§ããªãããã§ãï¼ã
ãã®å¾ã¯ã¹ã¿ãã¯ãããé層ï¼ããã§ã¯ projectA/terraform é
ä¸ï¼ã« ec2.tf çãªã©ã®ãªã½ã¼ã¹ä½æç¨ã® terraform å®ç¾©ãè¨è¼ãã tf ãã¡ã¤ã«ãé
ç½®ãã¦ããã°ãterraform å´ã®æºåã¯å®äºã§ãã
ç¶ã㦠GitHub Actions å´ã®å®è£
ãè¦ã¦ããã¾ãã
å度 GitHub Actions ã«é¢ãããã¡ã¤ã«ãç½®ããã¦ãããã£ã¬ã¯ããªæ§æãè¦ã¦ããã¨ä»¥ä¸ã®ããã«ãªã£ã¦ããã¾ãã
âââ .github
â  âââ workflows
â  âââ projectA-pull-request.yaml
â  âââ projectA-push-tag.yaml
â  âââ template-pull-request.yaml
â  âââ template-push-tag.yaml
ãã£ããã¨ãããã¡ã¤ã«ã®å½¹å²ã«ã¤ãã¦è§¦ãã¦ããã¨ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã
- template-pull-request.yaml
- projectA-pull-request.yaml
- åå©ç¨å¯è½ãªã¯ã¼ã¯ããã¼ã®ãã³ãã¬ã¼ãï¼template-pull-request.yamlï¼ãå¼ã³åºããã¡ã¤ã«ï¼â»ä»åã®ä¾ã§ã¯ããã¸ã§ã¯ããã¨ã«ä½æï¼
- template-push-tag.yaml
- template-pull-request.yaml åæ§ã«åå©ç¨å¯è½ãªã¯ã¼ã¯ããã¼ã®ãã³ãã¬ã¼ããã¡ã¤ã«
- tags ã®ã¤ãã³ã㧠terraform apply ãå®è¡ããã
- projectA-push-tag.yaml
- åå©ç¨å¯è½ãªã¯ã¼ã¯ããã¼ã®ãã³ãã¬ã¼ãï¼template-push-tag.yamlï¼ãå¼ã³åºããã¡ã¤ã«ï¼â»ä»åã®ä¾ã§ã¯ããã¸ã§ã¯ããã¨ã«ä½æï¼
ä¸èº«ãè¦ã¦ããã¾ããã¾ãã¯ãã³ãã¬ã¼ãã¨ãªã template-pull-request.yaml ã§ãã
on:
workflow_call:
inputs:
workload_identity_provider:
description: '使ç¨ãã Workload Identity Provider'
required: true
type: string
service_account:
description: 'Workload Identity çµç±ã§èªè¨¼ãããµã¼ãã¹ã¢ã«ã¦ã³ã'
required: true
type: string
terraform_version:
description: 'Terraform ã®ãã¼ã¸ã§ã³'
required: true
type: string
tag_name:
description: 'Terramate ã§ä½¿ãã¿ã°åï¼Google Cloud ã®ããã¸ã§ã¯ãåï¼'
required: true
type: string
permissions:
id-token: write
contents: read
pull-requests: read
checks: read
jobs:
terraform-plan:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Terramate
uses: terramate-io/terramate-action@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: ${{ inputs.terraform_version }}
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: ${{ inputs.workload_identity_provider }}
service_account: ${{ inputs.service_account }}
- name: Initialize Terraform
run: terramate run --tags=${{ inputs.tag_name }} -- terraform init
- name: Plan Terraform
run: terramate run --tags=${{ inputs.tag_name }} --changed -- terraform plan
ãã¤ã³ãã¯ä»¥ä¸ã§ãã
- terraform_wrapper ã®ç¡å¹å
- google-github-actions/auth ã®å©ç¨
- terramate run ã®å®è¡
- terraform_wrapper ã®ç¡å¹å
Terramate ã®ããã¥ã¡ã³ãã«ãè¨è¼ãããã¾ãããHashiCorp ã® Terraform Setup GitHub Action ã使ãå ´å㯠terraform_wrapper ãç¡å¹åããå¿
è¦ãããã¾ãã
terraform_wrapper: false
Terramate - Automating Terramate in GitHub Actions
- google-github-actions/auth ã®å©ç¨
google-github-actions/auth ã¨ããå°ç¨ã®ã¢ã¯ã·ã§ã³ã使ã£ã¦ãã¾ãã
workload_identity_provider 㨠service_account 㯠inputs çµç±ã§æ¸¡ãã¦ãã¾ãããå¾è¿°ãã Workload Identity é£æºã®ããã«ä½æãããããã¤ãã¼ã¨ãµã¼ãã¹ã¢ã«ã¦ã³ããæå®ããå¿
è¦ãããã¾ãã
workload_identity_provider: ${{ inputs.workload_identity_provider }}
service_account: ${{ inputs.service_account }}
terramate run 㯠Terramate ãå©ç¨ããä¸ã§ãã¢ã¨ãªãã³ãã³ãå®è¡ã§ãã
- name: Plan Terraform
run: terramate run --tags=${{ inputs.tag_name }} --changed -- terraform plan
åºæ¬çã«ã¯ terramate run -- <å®è¡ãããã³ãã³ã>
ã§ç®¡çãã¦ããå
¨ã¹ã¿ãã¯ã«å¯¾ãã¦ãä¸æ¬ã§<å®è¡ãããã³ãã³ã>ãå®è¡ãããã¨ããä»æ§ã§ããããã§ã¯ä½µã㦠--tags 㨠--changed ã®ãªãã·ã§ã³ãã¤ãã¦ãã¾ãã--tags ã¯å®è¡å¯¾è±¡ã¨ãªãã¹ã¿ãã¯ãå¶éããããã®ãªãã·ã§ã³ã--changed 㯠git ããã¨ã«ãã¡ã¤ã«ã®å¤æ´ã®ãã£ãã¹ã¿ãã¯ã®ã¿ã対象ã«å®è¡ãã¦ããããªãã·ã§ã³ã§ãã
ããã§ç´¹ä»ãã¦ãããªãã·ã§ã³ã terramate ã³ãã³ãã®ä½¿ãæ¹ã¯ã»ãã®ä¸é¨ã«éããä»ã«ã便å©ãªæ©è½ï¼parallel çï¼ãããã®ã§ã詳ããã¯å
¬å¼ã®ããã¥ã¡ã³ãããåç
§ãã ããã
Terramate - Orchestration
ããã¦åå©ç¨å¯è½ãªã¯ã¼ã¯ããã¼ã®å¼ã³åºãå´ã§ãã projectA-pull-request.yaml ã¯ä»¥ä¸ã®ãããªå
容ã§ãã
name: Create Pull Request
on:
pull_request:
jobs:
terraform-plan:
uses: ./.github/workflows/template-pull-request.yaml
with:
workload_identity_provider: '<å¾ã»ã©ä½æãã Workload Identity ãããã¤ãã¼å>'
service_account: '<å¾ã»ã©ä½æãããµã¼ãã¹ã¢ã«ã¦ã³ãå>'
terraform_version: 'x.x.x'
tag_name: 'projectA'
åºæ¬çã«ã¯ãã³ãã¬ã¼ãã®å¼ã³åºãããã³ãã¬ã¼ãã¸ã®å¤æ°åã渡ããå®ç¾©ãã¦ãããããªå
容ã§ãã
template-push-tag.yaml ã projectA-push-tag.yaml ã®å
容ãä¸å¿è¨è¼ãã¦ããã¾ãããåºæ¬çã«ã¯åãè¦é ã§å®è£
ãã¦ãããã解説ã¯å²æãã¾ãã
template-push-tag.yaml
on:
workflow_call:
inputs:
workload_identity_provider:
description: '使ç¨ãã Workload Identity Provider'
required: true
type: string
service_account:
description: 'Workload Identity çµç±ã§èªè¨¼ãããµã¼ãã¹ã¢ã«ã¦ã³ã'
required: true
type: string
terraform_version:
description: 'Terraform ã®ãã¼ã¸ã§ã³'
required: true
type: string
tag_name:
description: 'Terramate ã§ä½¿ãã¿ã°åï¼Google Cloud ã®ããã¸ã§ã¯ãåï¼'
required: true
type: string
permissions:
id-token: write
contents: read
pull-requests: read
checks: read
jobs:
terraform-apply:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Terramate
uses: terramate-io/terramate-action@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: ${{ inputs.terraform_version }}
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: ${{ inputs.workload_identity_provider }}
service_account: ${{ inputs.service_account }}
- name: Initialize Terraform
run: terramate run --tags=${{ inputs.tag_name }} -- terraform init
- name: Apply Terraform
run: terramate run --tags=${{ inputs.tag_name }} --changed -- terraform apply -auto-approve
projectA-push-tag.yaml
name: Push Tag
on:
push:
tags:
- "*"
jobs:
terraform-apply:
uses: ./.github/workflows/template-push-tag.yaml
with:
workload_identity_provider: '<å¾ã»ã©ä½æãã Workload Identity ãããã¤ãã¼å>'
service_account: '<å¾ã»ã©ä½æãããµã¼ãã¹ã¢ã«ã¦ã³ãå>'
terraform_version: 'x.x.x'
tag_name: 'projectA'
Workload Identity é£æºç¨ãªã½ã¼ã¹ã®æ§ç¯
ç¶ã㦠Workload Identity é£æºç¨ãªã½ã¼ã¹ãæ§ç¯ãã¦ããã¾ãã
ã¾ã Workload Identity é£æºã§ä½¿ç¨ãããµã¼ãã¹ã¢ã«ã¦ã³ããä½æãã¦ããã¦ãã ããã
ãµã¼ãã¹ã¢ã«ã¦ã³ããã¼ã¯ä½¿ç¨ãã¾ããããWorkload Identity é£æºãçµç±ã㦠Google Cloud ãªã½ã¼ã¹ãæä½ããããã® IAM ãã®ãã®ã¯å¿
è¦ã¨ãªãã¾ãï¼ã¾ãã1ã¤æ³¨æã¨ã㦠roles/iam.workloadIdentityUser ã®ãã¼ã«ãæã¤ãµã¼ãã¹ã¢ã«ã¦ã³ããå¿
è¦ã¨ãªãã¾ãã§å¿
è¦æ¨©éãä»ä¸ãã¦ããã¦ãã ããï¼ã
Workload Identity é£æºã®ã³ã¢ã¨ãªããªã½ã¼ã¹ãä½æãã¦ããã¾ãã
Google Cloud Console ã«ãã°ã¤ã³ãããIAM ã¨ç®¡çã>ãWorkload Identity é£æºãã¸ç§»åãã¾ãã
ãããã¤ãã®è¿½å ã»ãã¼ã«ã®ä½æããã¦ããã¾ãã
è¨å®é
ç®ãè¦ã¦ããã¾ãã
ååããã¼ã«ã«ã¤ãã¦ã¯ãªãã§ãè¯ãã§ããããã§ã¯ãgithubãã¨ãã¦ããã¾ãã
ãããã¤ãè¨å®ã¯ä»¥ä¸ã®ããã«è¡ãã¾ãã
次㫠OIDC ãããã¤ãã¼ããéããããã¼ã¯ã³ã Google Cloud å
ã§æ±ããããã«ããããã®ãããã³ã°ãè¡ãã¾ããä»åã¯ç¹å®ã®ãªãã¸ããªããã®ã¿ã®ã¢ã¯ã»ã¹ã«éå®ãããããrepository æ
å ±ãæ±ãããããªãããã³ã°ã«ãã¾ãã
Googleå´ |
OIDCå´ï¼GitHubï¼ |
google.subject |
assertion.sub |
attribute.repository |
assertion.repository |
google.subject ã¯å¿
é è¨å®ã¨ããä»æ§ã®ãããassertion.sub ã§ãããã³ã°ãã¦ãã¾ãã
attribute.repository 㯠assertion.repository ã§ãããã³ã°ããå¾è¿°ããç¹å®ã®ãªãã¸ããªã¢ã¯ã»ã¹ã®å¶å¾¡ã«ä½¿ãã¾ãã
æ¡ä»¶ CEL 㯠ãããã³ã°ããå±æ§å¤ã使ãå½¢ã§ä»¥ä¸ã®ããã«ãã¾ãï¼OWNER ã REPO ã®å¤ã¯æ¸ãæãã¦ãã ããï¼ãCEL ã¨ãã è¨èªã使ç¨ãã¾ãã
assertion.repository == "<OWNER>/<REPO>"
ãããã³ã°ããã¦ããã®ã§ãCEL ã§ã¯ attribute ã使ç¨ããã¨æãããããã§ã¯ assertion ã使ç¨ãããã¨ã«ãªããã注æãå¿
è¦ã§ãï¼ã¨è¨ãã¤ã¤ attribute ã§ãåé¡ãªãã®ãã¯è©¦ãã¦ãã¾ããï¼ã
ãããã³ã°ã«é¢ããããã¥ã¡ã³ãã¯ä»¥ä¸ãåèã«ãªãã¾ãã
Google Cloud - Workload Identity é£æº
OpenID Connect ã使ã£ãã»ãã¥ãªãã£å¼·åã«ã¤ãã¦
ä¸è¨è¨å®ã§ãããã¤ãã®è¿½å ã¨ãã¼ã«ã®ä½æãé²ãã¦ãã ããã
ãã®å¾ããã¼ã«ã§ä½¿ç¨ãããµã¼ãã¹ã¢ã«ã¦ã³ãã®ç´ä»ããè¡ãã¾ãï¼ãã¼ã«ã®ç»é¢ã«æ»ãã¨ãã¢ã¯ã»ã¹ã許å¯ããããã®ã§ãã¡ãããè¨å®ãã¾ãï¼ã
使ç¨ãããµã¼ãã¹ã¢ã«ã¦ã³ããé¸æãããããã³ã°ããå±æ§ã使ãå½¢ã§ãµã¼ãã¹ã¢ã«ã¦ã³ãã¸ã®å¶å¾¡ãããã¾ããããã§ã¯ attribute ã使ç¨ãã¦ãã¾ãï¼ãã¡ãã§ã OWNER ã REPO ã®å¤ã¯æ¸ãæãã¦ãã ããï¼ã
ããã¾ã§ã®æé ãçµããããPull Request ã®æ´æ°ã tag ã® push 㧠GitHub Actions ã® CI/CD ãåãããã«ãªã£ã¦ããã¯ãã§ãã
ææ³
Terramate ã¯ç°¡åã«ã³ãã³ãã®ä¸æ¬å®è¡ãå·®åæ¤åºã«ãããã£ã«ã¿ã¼ãªã© Terraform ã®ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ãè¡ããããéå®ãããã§ãï¼åè¿°ããããã« OpenTofuãTerragrunt ãªã©ãï¼ãå¤æ´ããã£ããã¡ã¤ã«ã対象㫠Terraform ãå®è¡ããã¨ããå¶å¾¡ã®ããã«ç¬èªã®ã¹ã¯ãªãããªã©ãå®è£
ããå¿
è¦ããªãããªãã·ã§ã³1ã¤ã§å¶å¾¡ã§ããã®ã¯å¤§ããªé
åã§ããå°å
¥ãç°¡å㧠CI/CD ãã·ã³ãã«ãªæ§æã«ãªãã®ã§ãã¨ã¦ãè¯ããªã¨æã£ã¦ãã¾ãã
å¼ç¤¾ã«ããã¦ã¯æ£ç´ãªã¨ãã Google Cloud åãã® IaC 管çåºç¤ã¯å°å
¥ããã°ããã§ãã¾ã ã¾ã IaC åèªä½ãæ¨é²ã§ãã¦ããªããã Terramate ã®å¤§ããªæ©æµã¯ããã»ã©å®æã§ãã¦ãã¾ããããä»å¾ã® IaC åã®æ¨é²ã§ããã«å½¹ç«ã£ã¦ãããããªæ°é
ãæãã¦ãã¾ãï¼ã¾ã å©ç¨ãã¦ããªã parallel ããã®ä»æ©è½ãªã©ï¼ã
ã¾ããWorkload Identity é£æºã«ã¤ãã¦ããµã¼ãã¹ã¢ã«ã¦ã³ããã¼ã®ç®¡çãçºçããªãã¨ããã®ã¯ã»ãã¥ãªãã£é¢ã§å¤§ããªé
åã§ããå°ç¨ã® action ãåå¨ããã®ã§ CI/CD ã¸ã®çµã¿è¾¼ã¿ã容æã§ããã
ãããã«
ä»å㯠Terramate 㨠Workload Identity é£æºã使ã£ã GitHub Actions ã® CI/CD ã®æ§ç¯æ¹æ³ã«ã¤ãã¦æ¸ãã¾ãããã¨ã¦ã便å©ã§ã»ãã¥ã¢ã§ãã®ã§è¯ããã°ã¿ãªãããåè£ã®1ã¤ã«å
¥ãã¦ã¿ã¦ãã ããã