Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for google_cloudfunctions_function runtime #2340

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions google/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ func resourceCloudFunctionsFunction() *schema.Resource {
Optional: true,
},

"runtime": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"environment_variables": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -293,6 +299,7 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro

function := &cloudfunctions.CloudFunction{
Name: cloudFuncId.cloudFunctionId(),
Runtime: d.Get("runtime").(string),
ForceSendFields: []string{},
}

Expand Down Expand Up @@ -376,6 +383,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)
Expand Down Expand Up @@ -458,6 +466,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")
Expand Down
11 changes: 11 additions & 0 deletions google/resource_cloudfunctions_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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(
Expand All @@ -124,6 +129,11 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
"new-env-variable-value", &function),
),
},
{
ResourceName: funcResourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -394,6 +404,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ 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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of function that will be executed*

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks for the feedback! GoogleCloudPlatform/magic-modules#915

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to help! Awaiting this feature in the next release 🙃

* `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.
* `trigger_bucket` - If function is triggered by bucket, bucket name is set here. Deprecated. Use `event_trigger` instead.
* `trigger_topic` - If function is triggered by Pub/Sub topic, name of topic is set here. Deprecated. Use `event_trigger` instead.
* `https_trigger_url` - If function is triggered by HTTP, trigger URL is set here.
* `labels` - A map of labels applied to this function.

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cloudfunctions_function.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down