Skip to content

Commit 9f12073

Browse files
Patch update (#6000) (#4278)
Signed-off-by: Modular Magician <[email protected]>
1 parent 2f534d5 commit 9f12073

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

.changelog/6000.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
cloudfunctions: fixed an issue where `google_cloudfunctions2_function` would not update
3+
```

google-beta/resource_cloudfunction2_function_test.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ func TestAccCloudFunctions2Function_update(t *testing.T) {
2929
ImportStateVerifyIgnore: []string{"location", "build_config.0.source.0.storage_source.0.object", "build_config.0.source.0.storage_source.0.bucket"},
3030
},
3131
{
32-
Config: testAccCloudFunctions2Function_updated(context),
32+
Config: testAccCloudFunctions2Function_test_update(context),
33+
},
34+
{
35+
ResourceName: "google_cloudfunctions2_function.terraform-test2",
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
ImportStateVerifyIgnore: []string{"location", "build_config.0.source.0.storage_source.0.object", "build_config.0.source.0.storage_source.0.bucket"},
39+
},
40+
{
41+
Config: testAccCloudFunctions2Function_test_redeploy(context),
3342
},
3443
{
3544
ResourceName: "google_cloudfunctions2_function.terraform-test2",
@@ -83,7 +92,49 @@ resource "google_cloudfunctions2_function" "terraform-test2" {
8392
`, context)
8493
}
8594

86-
func testAccCloudFunctions2Function_updated(context map[string]interface{}) string {
95+
func testAccCloudFunctions2Function_test_update(context map[string]interface{}) string {
96+
return Nprintf(`
97+
resource "google_storage_bucket" "bucket" {
98+
provider = google-beta
99+
name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}"
100+
location = "US"
101+
uniform_bucket_level_access = true
102+
}
103+
104+
resource "google_storage_bucket_object" "object" {
105+
provider = google-beta
106+
name = "function-source.zip"
107+
bucket = google_storage_bucket.bucket.name
108+
source = "%{zip_path}"
109+
}
110+
111+
resource "google_cloudfunctions2_function" "terraform-test2" {
112+
provider = google-beta
113+
name = "tf-test-test-function%{random_suffix}"
114+
location = "us-central1"
115+
description = "an updated function"
116+
117+
build_config {
118+
runtime = "nodejs12"
119+
entry_point = "helloHttp"
120+
source {
121+
storage_source {
122+
bucket = google_storage_bucket.bucket.name
123+
object = google_storage_bucket_object.object.name
124+
}
125+
}
126+
}
127+
128+
service_config {
129+
max_instance_count = 1
130+
available_memory = "1536Mi"
131+
timeout_seconds = 30
132+
}
133+
}
134+
`, context)
135+
}
136+
137+
func testAccCloudFunctions2Function_test_redeploy(context map[string]interface{}) string {
87138
return Nprintf(`
88139
resource "google_storage_bucket" "bucket" {
89140
provider = google-beta

google-beta/resource_cloudfunctions2_function.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,6 @@ func resourceCloudfunctions2functionUpdate(d *schema.ResourceData, meta interfac
549549
billingProject = project
550550

551551
obj := make(map[string]interface{})
552-
nameProp, err := expandCloudfunctions2functionName(d.Get("name"), d, config)
553-
if err != nil {
554-
return err
555-
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) {
556-
obj["name"] = nameProp
557-
}
558552
descriptionProp, err := expandCloudfunctions2functionDescription(d.Get("description"), d, config)
559553
if err != nil {
560554
return err
@@ -594,10 +588,6 @@ func resourceCloudfunctions2functionUpdate(d *schema.ResourceData, meta interfac
594588
log.Printf("[DEBUG] Updating function %q: %#v", d.Id(), obj)
595589
updateMask := []string{}
596590

597-
if d.HasChange("name") {
598-
updateMask = append(updateMask, "name")
599-
}
600-
601591
if d.HasChange("description") {
602592
updateMask = append(updateMask, "description")
603593
}
@@ -629,7 +619,7 @@ func resourceCloudfunctions2functionUpdate(d *schema.ResourceData, meta interfac
629619
billingProject = bp
630620
}
631621

632-
res, err := sendRequestWithTimeout(config, "PUT", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
622+
res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
633623

634624
if err != nil {
635625
return fmt.Errorf("Error updating function %q: %s", d.Id(), err)

0 commit comments

Comments
 (0)