Skip to content

Shows how to connect GCP with GitHub actions and use Terraform to deploy cloud infra.

Notifications You must be signed in to change notification settings

jaredfiacco2/gcp-github-actions-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkedIn


Use GitHub Actions & Terraform to Automatically Spin up Resources in GCP.

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
  1. About The Project
  2. Instructions
  3. Contact

About The Project

  • 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.

Process Map

WARNING

  • 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!

Instructions

  1. Create a new service acount in GCP & add the desied roles to the new service account

  1. Open the service account you just made and create a new key. Open the JSON, copy the private key.

  1. 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.

  1. 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.

  1. 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.

Contact

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

About

Shows how to connect GCP with GitHub actions and use Terraform to deploy cloud infra.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages