From abf53cd91a18611ff3903b4985c58dcdc0240ff5 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 25 Oct 2018 17:34:41 -0700 Subject: [PATCH] Add support for google_cloudfunctions_function runtime (#2340) /cc @rileykarson --- google/resource_cloudfunctions_function.go | 13 +++++++++++++ google/resource_cloudfunctions_function_test.go | 11 +++++++++++ ...datasource_cloudfunctions_function.html.markdown | 1 + .../docs/r/cloudfunctions_function.html.markdown | 2 ++ 4 files changed, 27 insertions(+) diff --git a/google/resource_cloudfunctions_function.go b/google/resource_cloudfunctions_function.go index 41c87766..7ee4f7ab 100644 --- a/google/resource_cloudfunctions_function.go +++ b/google/resource_cloudfunctions_function.go @@ -170,6 +170,12 @@ func resourceCloudFunctionsFunction() *schema.Resource { Optional: true, }, + "runtime": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "environment_variables": { Type: schema.TypeMap, Optional: true, @@ -316,6 +322,7 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro function := &cloudfunctions.CloudFunction{ Name: cloudFuncId.cloudFunctionId(), + Runtime: d.Get("runtime").(string), ForceSendFields: []string{}, } @@ -426,6 +433,7 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error } d.Set("timeout", timeout) d.Set("labels", function.Labels) + d.Set("runtime", function.Runtime) d.Set("environment_variables", function.EnvironmentVariables) if function.SourceArchiveUrl != "" { // sourceArchiveUrl should always be a Google Cloud Storage URL (e.g. gs://bucket/object) @@ -519,6 +527,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro updateMaskArr = append(updateMaskArr, "labels") } + if d.HasChange("runtime") { + function.Runtime = d.Get("runtime").(string) + updateMaskArr = append(updateMaskArr, "runtime") + } + if d.HasChange("environment_variables") { function.EnvironmentVariables = expandEnvironmentVariables(d) updateMaskArr = append(updateMaskArr, "environment_variables") diff --git a/google/resource_cloudfunctions_function_test.go b/google/resource_cloudfunctions_function_test.go index 9ca8ed00..96f99d68 100644 --- a/google/resource_cloudfunctions_function_test.go +++ b/google/resource_cloudfunctions_function_test.go @@ -108,6 +108,11 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) { testAccCloudFunctionsFunctionHasLabel("my-label", "my-label-value", &function), ), }, + { + ResourceName: funcResourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCloudFunctionsFunction_updated(functionName, bucketName, zipFileUpdatePath), Check: resource.ComposeTestCheckFunc( @@ -127,6 +132,11 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) { "new-env-variable-value", &function), ), }, + { + ResourceName: funcResourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -529,6 +539,7 @@ resource "google_cloudfunctions_function" "function" { source_archive_bucket = "${google_storage_bucket.bucket.name}" source_archive_object = "${google_storage_bucket_object.archive.name}" trigger_http = true + runtime = "nodejs8" timeout = 91 entry_point = "helloGET" labels { diff --git a/website/docs/d/datasource_cloudfunctions_function.html.markdown b/website/docs/d/datasource_cloudfunctions_function.html.markdown index d455f77a..af3862d0 100644 --- a/website/docs/d/datasource_cloudfunctions_function.html.markdown +++ b/website/docs/d/datasource_cloudfunctions_function.html.markdown @@ -45,6 +45,7 @@ exported: * `description` - Description of the function. * `available_memory_mb` - Available memory (in MB) to the function. * `timeout` - Function execution timeout (in seconds). +* `runtime` - The runtime in which the function is running. * `entry_point` - Name of a JavaScript function that will be executed when the Google Cloud Function is triggered. * `trigger_http` - If function is triggered by HTTP, this boolean is set. * `event_trigger` - A source that fires events in response to a condition in another service. Structure is documented below. diff --git a/website/docs/r/cloudfunctions_function.html.markdown b/website/docs/r/cloudfunctions_function.html.markdown index 84fe0b9f..d7334084 100644 --- a/website/docs/r/cloudfunctions_function.html.markdown +++ b/website/docs/r/cloudfunctions_function.html.markdown @@ -76,6 +76,8 @@ Deprecated. Use `event_trigger` instead. * `labels` - (Optional) A set of key/value label pairs to assign to the function. +* `runtime` - (Optional) The runtime in which the function is going to run. If empty, defaults to `"nodejs6"`. + * `environment_variables` - (Optional) A set of key/value environment variable pairs to assign to the function. * `retry_on_failure` - (Optional) Whether the function should be retried on failure. This only applies to bucket and topic triggers, not HTTPS triggers.