fix(terraform): create pr only if workflow files content is different… #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Apply new changes to SolEng repositories | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- terraform-plans/** | |
push: | |
branches: | |
- main | |
paths: | |
- terraform-plans/** | |
jobs: | |
terraform: | |
name: Run Terraform | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
repository: | |
- soleng-tf-test-repo | |
steps: | |
- name: Checkout branch | |
uses: actions/checkout@v4 | |
- name: Install Terraform | |
run: sudo snap install terraform --classic | |
- name: Terraform init | |
working-directory: ./terraform-plans | |
run: terraform init | |
- name: Terraform validate | |
working-directory: ./terraform-plans | |
env: | |
GITHUB_APP_ID: ${{ secrets.SOLENG_APP_ID }} | |
GITHUB_APP_INSTALLATION_ID: ${{ secrets.SOLENG_APP_INSTALLATION_ID }} | |
GITHUB_APP_PEM_FILE: ${{ secrets.SOLENG_APP_PEM_FILE }} | |
run: terraform validate -no-color | |
- name: Terraform plan | |
working-directory: ./terraform-plans | |
env: | |
GITHUB_APP_ID: ${{ secrets.SOLENG_APP_ID }} | |
GITHUB_APP_INSTALLATION_ID: ${{ secrets.SOLENG_APP_INSTALLATION_ID }} | |
GITHUB_APP_PEM_FILE: ${{ secrets.SOLENG_APP_PEM_FILE }} | |
run: | | |
terraform plan -no-color \ | |
-var-file=configs/github.tfvars \ | |
-var-file=configs/${{ matrix.repository }}.tfvars \ | |
-out ./tf.plan | |
- name: Terraform Apply only on merge to main | |
if: ${{ github.event_name == 'push' }} | |
working-directory: ./terraform-plans | |
env: | |
GITHUB_APP_ID: ${{ secrets.SOLENG_APP_ID }} | |
GITHUB_APP_INSTALLATION_ID: ${{ secrets.SOLENG_APP_INSTALLATION_ID }} | |
GITHUB_APP_PEM_FILE: ${{ secrets.SOLENG_APP_PEM_FILE }} | |
run: | | |
terraform apply ./tf.plan -no-color |