1111 name : ' Terraform'
1212 runs-on : ubuntu-latest
1313 env :
14- TF_VAR_project_id : ${{ secrets.GCP_PROJECT_ID }} # Make sure to set this secret in your repository
14+ TF_VAR_project_id : ${{ secrets.GCP_PROJECT_ID }}
15+ TF_VAR_region : ${{ secrets.GCP_REGION }}
16+ TF_VAR_environment : ${{ secrets.GCP_ENVIRONMENT }}
1517
1618 steps :
1719 - name : ' Checkout'
@@ -20,17 +22,20 @@ jobs:
2022 - name : ' Authenticate to Google Cloud'
2123 uses : ' google-github-actions/auth@v2'
2224 with :
23- credentials_json : ' ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}' # Make sure to set this secret in your repository
25+ credentials_json : ' ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}'
26+
27+ - name : ' Set up Google Cloud SDK'
28+ uses : ' google-github-actions/setup-gcloud@v2'
2429
2530 - name : ' Set up Terraform'
2631 uses : hashicorp/setup-terraform@v3
2732 with :
28- terraform_version : latest # Or specify a version e.g., 1.0.0
33+ terraform_version : latest
2934
3035 - name : ' Terraform Init'
3136 id : init
3237 run : terraform init
33- working-directory : ./terraform # Assuming your Terraform files are in a 'terraform' subdirectory
38+ working-directory : ./terraform
3439
3540 - name : ' Terraform Validate'
3641 id : validate
@@ -41,14 +46,12 @@ jobs:
4146 id : plan
4247 run : terraform plan -no-color -input=false -out=tfplan
4348 working-directory : ./terraform
44- # Only run on pull requests or direct pushes to main (not on merges)
4549 if : github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
4650
4751 - name : ' Terraform Apply'
4852 id : apply
4953 run : terraform apply -auto-approve -input=false tfplan
5054 working-directory : ./terraform
51- # Only run on pushes to the main branch (e.g., after a PR is merged)
5255 if : github.ref == 'refs/heads/main' && github.event_name == 'push'
5356
5457 - name : ' Check BigQuery Dataset and Load Titanic Data'
5760 chmod +x ../scripts/check_and_load_titanic_data.sh
5861 ../scripts/check_and_load_titanic_data.sh ${{ secrets.GCP_PROJECT_ID }}
5962 working-directory : ./terraform
60- # Only run on pushes to the main branch (after terraform apply)
6163 if : github.ref == 'refs/heads/main' && github.event_name == 'push'
0 commit comments