Google Cloud Functions(Golang)和Terraform [关闭]

Google Cloud Functions(Golang)和Terraform [关闭]

问题描述:

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

对Google云功能的支持刚刚发布了*Beta。 p>

我一直在搜索有关将Google CloudFunctions(特别是用于golang)与Terraform结合使用以及所需工作流程(包括使用CloudBuild来构建,测试和部署到GCP)的任何示例/教程。 p>

有人知道吗? 这样的示例/博客,可以共享链接吗? 我知道go是新的beta版,所以不太可能。 我是GCP工具链的新手(来自AWS CloudFormation,代码管道/构建和Lambda / Go),因此渴望看到GCP端到端工作流程的最佳实践设置。 如果有经验的人很热衷,那将是一个很棒的帖子! p>

谢谢 p> div>

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.