This project shows you how to connect your GCP project to GitHub Actions & run Terraform to spin up your infra from code instead of using the console or gcloud CLI.
Table of Contents
- This project shows you how to connect your GCP project to GitHub Actions & run Terraform to spin up your infra from code instead of using the console or gcloud CLI.
- In this instance, we're using spinning up a bucket, adding an object to it, and creating a cloud function that references the object.
- Make sure you keep your repo private, don't ecpose your service account private key, don't allow anyone who merges to your repo to run actions.
- You're ultimately responsible for your own security. If you don't know something, google it before you do it!
- Create a new service acount in GCP & add the desied roles to the new service account
- Open the service account you just made and create a new key. Open the JSON, copy the private key.
- Open GitHub, go to your Repo's settings, and add a secret called "GOOGLE_CREDENTIALS". Your repo will use this to connect to GCP and run the terraform scripts. You need storage access, terraform needs to save it's states in a bucket. This prevents it from running into issues by attempting to create objests that already exist.
- Edit your terraform.tfvars file variables to match your project_id, your tf state bucket's name, and the name you want for your infra bucket. Create a Google Cloud Storage Bucket to hold your terraform state. Make sure it's named with the same name as your tfvars "tf_state_bucket" variable.
- Edit a tf file and push the changes to your branch. Merging to your branch should kick off github action to run your workflow.yaml file. This will run the terraform in gcp using the service acount credentials. The terraform will create a google storage buket, add your zipped python code as a bucket object, and create a cloud function using the object. Make sure the action runs and that check that the infra bucket, object, and google function were created.
Jared Fiacco - jaredfiacco2@gmail.com
A GCP Project of Mine: Pull and Store and Server Clash of Clans API Data
Another GCP Project of Mine: Publish Computer Statistics to Pub/Sub, Use Cloud Functions to Store in BigQuery