Hackathon instructions

Welcome hackathoners!

Rules

  • Use a private repo!
    You don't want to risk having anyone out there create merge requests that create stuff in your gcp project.
  • No secrets in the code!

Intro to this repo

This repo is used to quickly get you up to speed with deploying to your gcp project from github. If you're up to the task with also working with Terraform you can use this repo as a starting pointfor that as well.

The terraform module creates:

  • pubsub topic
  • service account
  • permission for the service acount to publish to the pubsub topic

Mirror this repo to your own private repo

  1. Create a private repo in GitHub under your user name called terraform-google-cloud-build
  2. Mirror the supersmo/terraform-google-cloud-build repo to your new private repo by following these instructions:

Open Git Bash Create a variable for your username:

github_user=<your-github_user>

Change directory to where you want to create your repo (/c is c: if you're on windows) e.g.:

cd /c/ws/github.com

Create a bare clone of the repository:

git clone --bare https://github.com/supersmo/terraform-google-cloud-build.git

Mirror-push to the new repository:

git push --bare https://github.com/${github_user}/terraform-google-cloud-build.git

Remove the temporary local repository you created earlier.

cd ..
rm -rf terraform-google-cloud-build.git

Clone the repository:

git clone https://github.com/${github_user}/terraform-google-cloud-build.git

Git will use the username and e-mail stored in the git global config which probably already is configured to be your work e-mail. If you wish to change the commit username and email only for this repo:

cd terraform-google-cloud-build
git config user.name <your name>
git config user.email <your e-mail>

Set up Github to Cloud Build integration

  1. Log in to gcp and go to your gcp project: https://console.google.com

  2. Go to Cloud Build –> Triggers and click Connect Repository

  3. Select source:

  4. Log in to your GitHub account if you're not already logged in

  5. Approve OAuth request to your GitHub account

  6. Click install Google Cloud Build

  7. Install the cloud build app on your private repo

  8. Select the google project to connect to

  9. Connect your repository

  10. Create a default push trigger

Modify default trigger

  1. Edit the default push trigger to:
  • support different triggers for main and feature branches
  • add an environment variable

Create a trigger for the main branch

  1. Create a trigger for the main branch by duplicating the trigger

  2. Edit the duplicate trigger to only trigger on the main branch

  3. Make a branch and push the branch to trigger a terraform plan

  4. Inspect the plan in cloud build

  5. If you are satisfied with the plan create a pull request to merge the branch to main.

  6. Check the terraform apply log in cloud build

  7. Navigate in your gcp project to see that the resources were created.