diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 1964ea1..23bfc7b 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -1,43 +1,40 @@ -name: Terraform CI/CD +name: Terraform on: push: - pull_request: + branches: [ main ] jobs: terraform: runs-on: ssot - container: - image: hashicorp/terraform:1.6.6 + defaults: + run: + working-directory: terraform steps: - - name: Install dependencies - run: apk add --no-cache nodejs npm git - - name: Checkout repository uses: actions/checkout@v4 + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + - name: Terraform Init - run: terraform -chdir=terraform init -input=false + run: terraform init -input=false - name: Terraform Validate - run: terraform -chdir=terraform validate + run: terraform validate - name: Terraform Plan - run: terraform -chdir=terraform plan -input=false -out=tfplan + run: terraform plan -input=false -out=tfplan - - name: Show plan - run: terraform -chdir=terraform show -no-color tfplan > terraform/plan.txt - - - name: Upload plan artifact + - name: Upload plan uses: actions/upload-artifact@v3 with: name: terraform-plan - path: | - terraform/tfplan - terraform/plan.txt + path: terraform/tfplan + # Optional: apply only on main - name: Terraform Apply if: github.ref == 'refs/heads/main' - run: terraform -chdir=terraform apply -input=false -auto-approve tfplan + run: terraform apply -input=false -auto-approve tfplan