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.