Skip to content

Terraform Plan2 by @takehiro1111 #43

Terraform Plan2 by @takehiro1111

Terraform Plan2 by @takehiro1111 #43

Workflow file for this run

name: Terraform Plan2
run-name: ${{ github.workflow }} by @${{ github.actor }}
on:
workflow_dispatch:
pull_request:
types:
- opened # PR新規作成時
- synchronize # PR更新時
- reopened # PR再オープン時
branches:
- main # mainブランチへのPRが対象
env:
AQUA_ROOT_DIR: /home/runner/.local/share/aquaproj-aqua
TFACTION_CONFIG: tfaction-root.yaml
AWS_REGION: ap-northeast-1
permissions:
id-token: write
contents: read
pull-requests: write
actions: read
issues: write
jobs:
setup:
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.list-targets.outputs.targets }}
timeout-minutes: 5
if: ${{ ! contains(fromJson('["renovate[bot]", "dependabot[bot]"]'), github.actor) }}
steps:
- name: Checkout to the branch
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- uses: aquaproj/aqua-installer@11dd79b4e498d471a9385aa9fb7f62bb5f52a73c # v4.0.4
with:
aqua_version: v2.53.3
# 変更のあった作業ディレクトリを取得
- uses: suzuki-shunsuke/tfaction/list-targets@4562d910bbacecf384c8aeda25332284fcf05f38 # v1.20.1
id: list-targets
terraform-apply:
needs: setup
if: join(fromJSON(needs.setup.outputs.targets), '') != ''
name: "terraform plan (${{ matrix.target.target }})"
runs-on: ubuntu-latest
timeout-minutes: 600
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.setup.outputs.targets) }}
defaults:
run:
shell: bash
env:
TFACTION_TARGET: ${{ matrix.target.target }}
TFACTION_JOB_TYPE: terraform
TFACTION_IS_APPLY: "false" # apply する場合は TFACTION_IS_APPLY を "true" に指定
steps:
- name: Checkout to the branch
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: aquas install
uses: aquaproj/aqua-installer@11dd79b4e498d471a9385aa9fb7f62bb5f52a73c # v4.0.4
with:
aqua_version: v2.53.3
- name: Generate My Github token
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2
with:
app_id: 2215622
private_key: ${{ secrets.SECRET_KEY }}
- name: Detect Terraform Version
env:
Environment: ${{ matrix.target.target }}
id: get_tf_version
run: |
cd ${{ env.Environment }} &&
TF_VERSION=$(cat .terraform-version)
echo TF_VERSION=$TF_VERSION >> $GITHUB_OUTPUT
- name: Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
id: setup_terraform
with:
terraform_version: ${{ steps.get_tf_version.outputs.TF_VERSION }}
- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5
with:
aws-region: ${{env.AWS_REGION}}
role-to-assume: arn:aws:iam::685339645368:role/deploy-github-actions
role-session-name: GithubActions_AssumeRole
- name: terraform init
working-directory: ${{ matrix.target.target }}
id: init
run: |
terraform init -no-color
- name: terraform plan
working-directory: ${{ matrix.target.target }}
if: ${{ steps.init.outcome == 'success' }}
run: |
tfcmt plan -patch -- terraform plan -no-color -input=false -var="github_token=${{ secrets.PAT_TOKEN }}"
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}