Deeper into the Cloud

Sometimes I'm dumb. Google Cloud Build works fine and everything is good again :)

Today was a dumb day. For me. I have Cloud Build all set up as per my previous post. This is great. I can just merge to my deployment branch and a few minutes later, the latest code is running on whatever site I want! Simple. And it's working great, and copying all of the files it should be copying, so I learned after thinking it wasn't ;)

For my altarschedule.com site, I use sendgrid to send emails. This is accompanied with code to build the email, and code to send the email, and a secret API key that tells sengrid which account is sending the account. This is great and perfect, and works fine except for the occasional email ending up in spam.

It's the API key that was causing me problems. It's a secret. And even though my git repository is not public, I don't feel comfortable putting that in a file that sites on the internet somewhere. So I use .gitignore to keep it out of git and only on my computer.

And this was working in that I would run my local build, and test email sending, and I would receive an email! Good stuff.

Enter Cloud Build.  I couldn't figure out why email stopped working? This is what I'm referring to when I say I was dumb :)  I have it there. I made sure it's not ignored in the .gcloudignore file. Explicitly include it with !sendgrid.key etc. WTF Google Cloud Build?!?

Ah yes. Google Cloud Build pulls from my repository on github, which is explicitly and with very good reason bereft of that file. It just didn't occur to me because I was dumb.

Google Cloud offers a ton of neat features. You just have to enable what you need. One such feature is the “Secret Manager”. Very useful!!

A few trip ups on which permissions should be enabled on the principle  (I enabled the main service account to have “Secret Manager Secret Accessor”), and the actual name needed to access the secret. It expects something like “projects/{{projectID}}/secrets/{{name}}/versions/1”. I'll only ever have one version.

Then it's just, create a Secret Manager client in Go, and access the secret! Simple

Happy Coding!