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

fix two fields #12662

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
3 changes: 3 additions & 0 deletions .changelog/6601.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudfunction: fixed unable to update `docker_repository` and `kms_key_name` on `google_cloudfunctions_function`
```
4 changes: 2 additions & 2 deletions google/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
20 changes: 15 additions & 5 deletions google/resource_cloudfunctions_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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 {
Expand Down