From 93c958bebcc5d5bf23069e02d58fd5d9f5c8b8c6 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 19 May 2022 15:26:23 +0000 Subject: [PATCH] Docker registry support for Cloud Functions (#6040) * Docker registry support for Cloud Functions * Resolving unintended doc update * Feedback: remove docker_registry default, change to 'computed' * Feedback: remove validation * Go formatter: extra spaces removed Co-authored-by: Rustem Bekmukhametov Signed-off-by: Modular Magician --- .changelog/6040.txt | 3 +++ ...deploy_delivery_pipeline_generated_test.go | 4 ++-- ...ource_clouddeploy_target_generated_test.go | 16 ++++++++-------- google/resource_cloudfunctions_function.go | 19 +++++++++++++++++++ .../resource_cloudfunctions_function_test.go | 6 ++++++ ...louddeploy_delivery_pipeline.html.markdown | 4 ++-- .../r/cloudfunctions_function.html.markdown | 2 ++ 7 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 .changelog/6040.txt diff --git a/.changelog/6040.txt b/.changelog/6040.txt new file mode 100644 index 00000000000..0d839120310 --- /dev/null +++ b/.changelog/6040.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +cloudfunctions: docker registry support for Cloud Functions +``` diff --git a/google/resource_clouddeploy_delivery_pipeline_generated_test.go b/google/resource_clouddeploy_delivery_pipeline_generated_test.go index 01fc5b4975d..ae92ddde784 100644 --- a/google/resource_clouddeploy_delivery_pipeline_generated_test.go +++ b/google/resource_clouddeploy_delivery_pipeline_generated_test.go @@ -67,9 +67,9 @@ resource "google_clouddeploy_delivery_pipeline" "primary" { name = "tf-test-pipeline%{random_suffix}" annotations = { - my_first_annotation = "example-annotation-1" - my_second_annotation = "example-annotation-2" + + my_first_annotation = "example-annotation-1" } description = "basic description" diff --git a/google/resource_clouddeploy_target_generated_test.go b/google/resource_clouddeploy_target_generated_test.go index 5e8173a3fe1..da4be0b0d46 100644 --- a/google/resource_clouddeploy_target_generated_test.go +++ b/google/resource_clouddeploy_target_generated_test.go @@ -136,9 +136,9 @@ resource "google_clouddeploy_target" "primary" { } labels = { - my_third_label = "example-label-3" - my_second_label = "updated-example-label-2" + + my_third_label = "example-label-3" } project = "%{project_name}" @@ -156,9 +156,9 @@ resource "google_clouddeploy_target" "primary" { name = "tf-test-target%{random_suffix}" annotations = { - my_second_annotation = "updated-example-annotation-2" - my_third_annotation = "example-annotation-3" + + my_second_annotation = "updated-example-annotation-2" } description = "updated description" @@ -241,9 +241,9 @@ resource "google_clouddeploy_target" "primary" { name = "tf-test-target%{random_suffix}" annotations = { - my_third_annotation = "example-annotation-3" - my_second_annotation = "updated-example-annotation-2" + + my_third_annotation = "example-annotation-3" } description = "updated description" @@ -267,9 +267,9 @@ resource "google_clouddeploy_target" "primary" { } labels = { - my_third_label = "example-label-3" - my_second_label = "updated-example-label-2" + + my_third_label = "example-label-3" } project = "%{project_name}" diff --git a/google/resource_cloudfunctions_function.go b/google/resource_cloudfunctions_function.go index ca7baa1a296..ea4e6520cb2 100644 --- a/google/resource_cloudfunctions_function.go +++ b/google/resource_cloudfunctions_function.go @@ -146,6 +146,13 @@ func resourceCloudFunctionsFunction() *schema.Resource { }, }, + "docker_registry": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: `Docker Registry to use for storing the function's Docker images. Allowed values are CONTAINER_REGISTRY (default) and ARTIFACT_REGISTRY.`, + }, + "docker_repository": { Type: schema.TypeString, Optional: true, @@ -518,6 +525,10 @@ func resourceCloudFunctionsCreate(d *schema.ResourceData, meta interface{}) erro function.VpcConnectorEgressSettings = v.(string) } + if v, ok := d.GetOk("docker_registry"); ok { + function.DockerRegistry = v.(string) + } + if v, ok := d.GetOk("docker_repository"); ok { function.DockerRepository = v.(string) } @@ -660,6 +671,9 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error if err := d.Set("event_trigger", flattenEventTrigger(function.EventTrigger)); err != nil { return fmt.Errorf("Error setting event_trigger: %s", err) } + if err := d.Set("docker_registry", function.DockerRegistry); err != nil { + return fmt.Errorf("Error setting docker_registry: %s", err) + } if err := d.Set("docker_repository", function.DockerRepository); err != nil { return fmt.Errorf("Error setting docker_repository: %s", err) } @@ -796,6 +810,11 @@ func resourceCloudFunctionsUpdate(d *schema.ResourceData, meta interface{}) erro updateMaskArr = append(updateMaskArr, "httpsTrigger", "httpsTrigger.securityLevel") } + if d.HasChange("docker_registry") { + function.DockerRegistry = d.Get("docker_registry").(string) + updateMaskArr = append(updateMaskArr, "dockerRegistry") + } + if d.HasChange("docker_repository") { function.Runtime = d.Get("docker_repository").(string) updateMaskArr = append(updateMaskArr, "dockerRepository") diff --git a/google/resource_cloudfunctions_function_test.go b/google/resource_cloudfunctions_function_test.go index 240d0f47f08..571ac778518 100644 --- a/google/resource_cloudfunctions_function_test.go +++ b/google/resource_cloudfunctions_function_test.go @@ -143,6 +143,8 @@ func TestAccCloudFunctionsFunction_basic(t *testing.T) { "name", functionName), resource.TestCheckResourceAttr(funcResourceName, "description", "test function"), + resource.TestCheckResourceAttr(funcResourceName, + "docker_registry", "CONTAINER_REGISTRY"), resource.TestCheckResourceAttr(funcResourceName, "available_memory_mb", "128"), resource.TestCheckResourceAttr(funcResourceName, @@ -215,6 +217,8 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) { "available_memory_mb", "256"), resource.TestCheckResourceAttr(funcResourceName, "description", "test function updated"), + resource.TestCheckResourceAttr(funcResourceName, + "docker_registry", "CONTAINER_REGISTRY"), resource.TestCheckResourceAttr(funcResourceName, "timeout", "91"), resource.TestCheckResourceAttr(funcResourceName, @@ -695,6 +699,7 @@ resource "google_cloudfunctions_function" "function" { name = "%s" runtime = "nodejs10" description = "test function" + docker_registry = "CONTAINER_REGISTRY" available_memory_mb = 128 source_archive_bucket = google_storage_bucket.bucket.name source_archive_object = google_storage_bucket_object.archive.name @@ -733,6 +738,7 @@ resource "google_storage_bucket_object" "archive" { resource "google_cloudfunctions_function" "function" { name = "%s" description = "test function updated" + docker_registry = "CONTAINER_REGISTRY" available_memory_mb = 256 source_archive_bucket = google_storage_bucket.bucket.name source_archive_object = google_storage_bucket_object.archive.name diff --git a/website/docs/r/clouddeploy_delivery_pipeline.html.markdown b/website/docs/r/clouddeploy_delivery_pipeline.html.markdown index fa7927f84f6..bc7554e36cb 100644 --- a/website/docs/r/clouddeploy_delivery_pipeline.html.markdown +++ b/website/docs/r/clouddeploy_delivery_pipeline.html.markdown @@ -33,9 +33,9 @@ resource "google_clouddeploy_delivery_pipeline" "primary" { name = "pipeline" annotations = { - my_first_annotation = "example-annotation-1" - my_second_annotation = "example-annotation-2" + + my_first_annotation = "example-annotation-1" } description = "basic description" diff --git a/website/docs/r/cloudfunctions_function.html.markdown b/website/docs/r/cloudfunctions_function.html.markdown index e3c65ec4129..256bf69c1a0 100644 --- a/website/docs/r/cloudfunctions_function.html.markdown +++ b/website/docs/r/cloudfunctions_function.html.markdown @@ -148,6 +148,8 @@ Eg. `"nodejs16"`, `"python39"`, `"dotnet3"`, `"go116"`, `"java11"`, `"ruby30"`, * `source_repository` - (Optional) Represents parameters related to source repository where a function is hosted. Cannot be set alongside `source_archive_bucket` or `source_archive_object`. Structure is [documented below](#nested_source_repository). It must match the pattern `projects/{project}/locations/{location}/repositories/{repository}`.* +* `docker_registry` - (Optional) Docker Registry to use for storing the function's Docker images. Allowed values are CONTAINER_REGISTRY (default) and ARTIFACT_REGISTRY. + * `docker_repository` - (Optional) User managed repository created in Artifact Registry optionally with a customer managed encryption key. If specified, deployments will use Artifact Registry. This is the repository to which the function docker image will be pushed after it is built by Cloud Build. If unspecified, Container Registry will be used by default, unless specified otherwise by other means. * `kms_key_name` - (Optional) Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt function resources. It must match the pattern `projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}`.