iac_modules/.github/workflows/iac-pipeline-aws-global-account-matrix.yaml
Workflow config file is invalid. Please check your config file: yaml: line 55: could not find expected ':'
Haitao Pan d30672446a Rename AWS workflow pipelines
Rename terraform-standard AWS workflow files to iac-pipeline naming.
2025-12-24 11:28:00 +08:00

102 lines
2.8 KiB
YAML

name: AWS Cloud IAC Pipeline (Account/VPC Matrix)
on:
push:
pull_request:
paths:
- '.github/workflows/iac-pipeline-aws-account-matrix.yaml'
- 'iac-template/terraform-hcl-standard/aws-cloud/component/vpc/**'
- 'iac-template/terraform-hcl-standard/aws-cloud/component/role/**'
workflow_dispatch:
inputs:
deploy_action:
type: choice
options: [plan, apply, destroy]
default: plan
permissions:
id-token: write
contents: read
env:
BASE_DIR: iac-template/terraform-hcl-standard/aws-cloud/component/
DEPLOY_ACTION: ${{ github.event.inputs.deploy_action || 'plan' }}
CONFIG_FILES: |
config/xzerolab/sit/aws-cloud/account/accounts.yaml
config/xzerolab/sit/aws-cloud/resources/vpc.yaml
jobs:
terraform:
name: "${{ matrix.component }} :: pipeline (action=${{ inputs.deploy_action }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
component:
- vpc
- role
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.5
- uses: terraform-linters/setup-tflint@v4
with:
tflint_version: v0.51.0
- name: Load AWS config
run: |
ACCOUNT_FILE=$(printf "%s\n" "${CONFIG_FILES}" | head -n 1)
python - <<'PY'
import os
import sys
from pathlib import Path
utils_dir = Path("iac-template/terraform-hcl-standard/utils").resolve()
sys.path.insert(0, str(utils_dir))
from config_loader import load_account_credentials
region, role_arn = load_account_credentials(os.environ["ACCOUNT_FILE"])
with Path(os.environ["GITHUB_ENV"]).open("a", encoding="utf-8") as handle:
handle.write(f"AWS_REGION={region}\n")
handle.write(f"AWS_ROLE_ARN={role_arn}\n")
PY
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
- name: Init
working-directory: ${{ env.BASE_DIR }}/${{ matrix.component }}
run: make init
- name: Plan
working-directory: ${{ env.BASE_DIR }}/${{ matrix.component }}
run: make plan
- name: Apply
working-directory: ${{ env.BASE_DIR }}/${{ matrix.component }}
if: ${{ env.DEPLOY_ACTION == 'apply' }}
run: make apply
- name: Destroy
working-directory: ${{ env.BASE_DIR }}/${{ matrix.component }}
if: ${{ env.DEPLOY_ACTION == 'destroy' }}
run: make destroy
- name: Skip Apply/Destroy
if: ${{ env.DEPLOY_ACTION != 'apply' && env.DEPLOY_ACTION != 'destroy' }}
run: echo "Action set to plan → skipping apply/destroy steps."
- name: Output
working-directory: ${{ env.BASE_DIR }}/${{ matrix.component }}
if: ${{ env.DEPLOY_ACTION == 'apply' }}
run: terraform output -json