From 90199003ba7fadb24d6303853c1aa6855b583af1 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 27 Sep 2022 21:09:34 +0000 Subject: [PATCH] fix two fields (#6601) Co-authored-by: Edward Sun Signed-off-by: Modular Magician --- .changelog/6601.txt | 3 +++ google/resource_cloudfunctions_function.go | 4 ++-- .../resource_cloudfunctions_function_test.go | 20 ++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .changelog/6601.txt diff --git a/.changelog/6601.txt b/.changelog/6601.txt new file mode 100644 index 00000000000..51dc8c16e44 --- /dev/null +++ b/.changelog/6601.txt @@ -0,0 +1,3 @@ +```release-note:bug +cloudfunction: fixed unable to update `docker_repository` and `kms_key_name` on `google_cloudfunctions_function` +``` diff --git a/google/resource_cloudfunctions_function.go b/google/resource_cloudfunctions_function.go index 117823d899e..7c201816fde 100644 --- a/google/resource_cloudfunctions_function.go +++ b/google/resource_cloudfunctions_function.go @@ -834,12 +834,12 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro } if d.HasChange("docker_repository") { - function.Runtime = d.Get("docker_repository").(string) + function.DockerRepository = d.Get("docker_repository").(string) updateMaskArr = append(updateMaskArr, "dockerRepository") } if d.HasChange("kms_key_name") { - function.Runtime = d.Get("docker_repository").(string) + function.KmsKeyName = d.Get("kms_key_name").(string) updateMaskArr = append(updateMaskArr, "kmsKeyName") } diff --git a/google/resource_cloudfunctions_function_test.go b/google/resource_cloudfunctions_function_test.go index 7b56a72fbaa..c2031aea0c3 100644 --- a/google/resource_cloudfunctions_function_test.go +++ b/google/resource_cloudfunctions_function_test.go @@ -186,6 +186,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) { bucketName := fmt.Sprintf("tf-test-bucket-%d", randInt(t)) zipFilePath := createZIPArchiveForCloudFunctionSource(t, testHTTPTriggerPath) zipFileUpdatePath := createZIPArchiveForCloudFunctionSource(t, testHTTPTriggerUpdatePath) + random_suffix := randString(t, 10) defer os.Remove(zipFilePath) // clean up vcrTest(t, resource.TestCase{ @@ -209,7 +210,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) { ImportStateVerifyIgnore: []string{"build_environment_variables"}, }, { - Config: testAccCloudFunctionsFunction_updated(functionName, bucketName, zipFileUpdatePath), + Config: testAccCloudFunctionsFunction_updated(functionName, bucketName, zipFileUpdatePath, random_suffix), Check: resource.ComposeTestCheckFunc( testAccCloudFunctionsFunctionExists( t, funcResourceName, &function), @@ -218,7 +219,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) { resource.TestCheckResourceAttr(funcResourceName, "description", "test function updated"), resource.TestCheckResourceAttr(funcResourceName, - "docker_registry", "CONTAINER_REGISTRY"), + "docker_registry", "ARTIFACT_REGISTRY"), resource.TestCheckResourceAttr(funcResourceName, "timeout", "91"), resource.TestCheckResourceAttr(funcResourceName, @@ -762,7 +763,7 @@ resource "google_cloudfunctions_function" "function" { `, bucketName, zipFilePath, functionName) } -func testAccCloudFunctionsFunction_updated(functionName string, bucketName string, zipFilePath string) string { +func testAccCloudFunctionsFunction_updated(functionName string, bucketName string, zipFilePath string, randomSuffix string) string { return fmt.Sprintf(` resource "google_storage_bucket" "bucket" { name = "%s" @@ -778,7 +779,8 @@ resource "google_storage_bucket_object" "archive" { resource "google_cloudfunctions_function" "function" { name = "%s" description = "test function updated" - docker_registry = "CONTAINER_REGISTRY" + docker_registry = "ARTIFACT_REGISTRY" + docker_repository = google_artifact_registry_repository.my-repo.id available_memory_mb = 256 source_archive_bucket = google_storage_bucket.bucket.name source_archive_object = google_storage_bucket_object.archive.name @@ -802,8 +804,16 @@ resource "google_cloudfunctions_function" "function" { } max_instances = 15 min_instances = 5 + region = "us-central1" } -`, bucketName, zipFilePath, functionName) + +resource "google_artifact_registry_repository" "my-repo" { + location = "us-central1" + repository_id = "tf-test-my-repository%s" + description = "example docker repository with cmek" + format = "DOCKER" +} +`, bucketName, zipFilePath, functionName, randomSuffix) } func testAccCloudFunctionsFunction_buildworkerpool(functionName string, bucketName string, zipFilePath string, location string) string {