This is a demo project to use Terraform to manage BigQuery scheduled queries. All the CI/CD tasks are run on Google Cloud Build.
Dev
name: tf-dev-plan
description: Run Terraform plan for Dev environment
filename: .cloudbuild/dev-plan.yaml
github:
name: terraform-bq-scheduled-queries
owner: derrickqin
push:
branch: .*
Prod
name: tf-prod-plan
description: Run Terraform plan for Prod environment
filename: .cloudbuild/prod-plan.yaml
github:
name: terraform-bq-scheduled-queries
owner: derrickqin
push:
branch: .*
Any new code commit will trigger a Cloud Build build to run the CI process. It contains two steps:
- Validate BigQuery SQL query using bq cli with dry-run parameters.
- Terraform plan to validate and show new changes.
Dev
name: tf-dev-apply
description: Run Terraform apply for Dev environment
filename: .cloudbuild/dev-apply.yaml
github:
name: terraform-bq-scheduled-queries
owner: derrickqin
push:
tag: dev.*
Prod
name: tf-prod-apply
description: Run Terraform apply for Dev environment
filename: .cloudbuild/prod-apply.yaml
github:
name: terraform-bq-scheduled-queries
owner: derrickqin
push:
tag: prod.*
Any tag pushed to Github that matches the regexes will trigger a CloudBuild task to run Terraform apply
To create a tag and push to Github:
For Dev: git tag dev-1.0 && git push origin --tags
For Prod: git tag prod-1.0 && git push origin --tags
- Update GCP project IDs in
dev.tfvars
andprod.tfvars
- Initialize TF states by running
ENV=dev make init
ENV=prod make init
- Fork this repo on Github
- Connect Github repo on Cloud Build follow this guide
- Create CloudBuild triggers as per information in #CI and #CD sessions
- Trigger the CI process with
git commit --allow-empty -m "Trigger Build" && git push
- Trigger the CD process with
git tag dev-1.0 && git push origin --tags