Go support for google cloud functions has just ben released top beta.
I have been searching for any examples / tutorials on using Google CloudFunctions (for golang specifically) with Terraform and the required workflow including using CloudBuild to build, test and deploy to GCP.
Does anyone know of such an example / blog on this and can share a link? I know go is newly beta so unlikely. Im a newbie to GCP toolchain (coming from AWS CloudFormation, Code Pipeline/Build and Lambda/Go) so keen to see the best practice setup for end to end workflow on GCP. Would be a great post if someone with the experience was keen!!
Thanks
I work at GCP and on Cloud Functions for Go.
I haven't tested this full flow yet, but hopefully this points you in the right direction before getting a full walkthrough/blog post.
You can create a Cloud Build trigger with the following snippet, from https://www.terraform.io/docs/providers/google/r/cloudbuild_trigger.html:
resource "google_cloudbuild_trigger" "build_trigger" {
project = "my-project"
trigger_template {
branch_name = "master"
project = "my-project"
repo_name = "some-repo"
}
filename = "cloudbuild.yaml"
}
From that trigger, you can use this cloudbuild.yaml adapted from the example in https://cloud.google.com/functions/docs/bestpractices/testing#continuous_testing_and_deployment:
steps:
- name: 'gcr.io/cloud-builders/go:latest'
args: ['test', '[YOUR_FUNCTION_PACKAGE]']
env: 'GOPATH=.'
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', '[YOUR_DEPLOYED_FUNCTION_NAME]', '[YOUR_FUNCTION_TRIGGER]', '--runtime', 'go111', '--entry-point', '[YOUR_FUNCTION_NAME_IN_CODE]']
dir: 'functions/autodeploy'
See https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/go for examples of configuring Cloud Build for Go. This setup would deploy the function from Cloud Build rather than using google_cloudfunctions_function
with Terraform.