From 28f340097f23ea6e84fbb53fe11e5421bce19d36 Mon Sep 17 00:00:00 2001 From: talithafrsc Date: Sun, 27 Oct 2024 14:00:04 +0700 Subject: [PATCH] fix terraform ci --- .github/workflows/terraform-ci.yml | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/terraform-ci.yml diff --git a/.github/workflows/terraform-ci.yml b/.github/workflows/terraform-ci.yml new file mode 100644 index 000000000..8b1e4626e --- /dev/null +++ b/.github/workflows/terraform-ci.yml @@ -0,0 +1,59 @@ +name: Terraform-CI +on: + push: + branches: + - dev + - master + paths: + - 'terraform/**' + +jobs: + terraform-test: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/dev' + defaults: + run: + shell: bash + working-directory: ./terraform + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.8 + - name: Validate Terraform Configuration + run: terraform init + env: + GOOGLE_CREDENTIALS: ${{ secrets.GCP_JSON }} + - name: Replace secret + run: sed -i "s/POSTGRES_PASSWORD/${{ secrets.POSTGRES_PASSWORD }}/" main.tf + - name: Dry run Terraform + run: terraform plan -var-file=variables.tfvars + env: + GOOGLE_CREDENTIALS: ${{ secrets.GCP_JSON }} + + terraform-deploy: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + defaults: + run: + shell: bash + working-directory: ./terraform + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.8 + - name: Validate Terraform Configuration + run: terraform init + env: + GOOGLE_CREDENTIALS: ${{ secrets.GCP_JSON }} + - name: Replace secret + run: sed -i "s/POSTGRES_PASSWORD/${{ secrets.POSTGRES_PASSWORD }}/" main.tf + - name: Deploy Terraform + run: terraform apply -var-file=variables.tfvars -auto-approve + env: + GOOGLE_CREDENTIALS: ${{ secrets.GCP_JSON }} \ No newline at end of file