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 https_trigger_security_level to cloudfunction_function #6007

Merged
merged 2 commits into from
May 9, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ func resourceCloudFunctionsFunction() *schema.Resource {
Description: `URL which triggers function execution. Returned only if trigger_http is used.`,
},

"https_trigger_security_level": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The security level for the function. Defaults to SECURE_OPTIONAL. Valid only if trigger_http is used.`,
},

"max_instances": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -481,6 +488,7 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro
function.EventTrigger = expandEventTrigger(v.([]interface{}), project)
} else if v, ok := d.GetOk("trigger_http"); ok && v.(bool) {
function.HttpsTrigger = &cloudfunctions.HttpsTrigger{}
function.HttpsTrigger.SecurityLevel = d.Get("https_trigger_security_level").(string)
} else {
return fmt.Errorf("One of `event_trigger` or `trigger_http` is required: " +
"You must specify a trigger when deploying a new function.")
Expand Down Expand Up @@ -644,6 +652,9 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("https_trigger_url", function.HttpsTrigger.Url); err != nil {
return fmt.Errorf("Error setting https_trigger_url: %s", err)
}
if err := d.Set("https_trigger_security_level", function.HttpsTrigger.SecurityLevel); err != nil {
return fmt.Errorf("Error setting https_trigger_security_level: %s", err)
}
}

if err := d.Set("event_trigger", flattenEventTrigger(function.EventTrigger)); err != nil {
Expand Down Expand Up @@ -780,6 +791,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro
updateMaskArr = append(updateMaskArr, "eventTrigger", "eventTrigger.failurePolicy.retry")
}

if d.HasChange("https_trigger_security_level") {
function.HttpsTrigger.SecurityLevel = d.Get("https_trigger_security_level").(string)
updateMaskArr = append(updateMaskArr, "httpsTrigger", "httpsTrigger.securityLevel")
}

if d.HasChange("docker_repository") {
function.Runtime = d.Get("docker_repository").(string)
updateMaskArr = append(updateMaskArr, "dockerRepository")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,16 +791,17 @@ resource "google_storage_bucket_object" "archive" {
}

resource "google_cloudfunctions_function" "function" {
name = "%s"
description = "test function updated"
available_memory_mb = 256
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
trigger_http = true
runtime = "nodejs10"
timeout = 91
entry_point = "helloGET"
ingress_settings = "ALLOW_ALL"
name = "%s"
description = "test function updated"
available_memory_mb = 256
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
trigger_http = true
https_trigger_security_level = "SECURE_ALWAYS"
runtime = "nodejs10"
timeout = 91
entry_point = "helloGET"
ingress_settings = "ALLOW_ALL"
labels = {
my-label = "my-updated-label-value"
a-new-label = "a-new-label-value"
Expand Down