Terraform - Github Action


name: 'Terraform Plan'
on:
  push:
    branches: [main]
    paths:
      - '.infras/**'

env:
  TF_CLOUD_ORGANIZATION: 'agora-marketplace'
  TF_API_TOKEN: '${{ secrets.TF_API_TOKEN }}'
  TF_WORKSPACE: 'may'
  CONFIG_DIRECTORY: '.infras'

jobs:
  terraform:
    name: 'Terraform Plan'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - name: Upload Configuration
        uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.0.0
        id: plan-upload
        with:
          workspace: ${{ env.TF_WORKSPACE }}
          directory: ${{ env.CONFIG_DIRECTORY }}
          speculative: true
      - name: Create Plan Run
        uses: hashicorp/tfc-workflows-github/actions/create-run@v1.0.0
        id: plan-run
        with:
          workspace: ${{ env.TF_WORKSPACE }}
          configuration_version: ${{ steps.plan-upload.outputs.configuration_version_id }}
          plan_only: true
      - name: Get Plan Output
        uses: hashicorp/tfc-workflows-github/actions/plan-output@v1.0.0
        id: plan-output
        with:
          plan: ${{ fromJSON(steps.plan-run.outputs.payload).data.relationships.plan.data.id }}