From 334002b4e7a2f93d9def5cd6892b1b9ad99dfde0 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Tue, 22 Aug 2023 17:03:30 -0400 Subject: [PATCH 01/14] Update Subscription.yaml --- mmv1/products/pubsub/Subscription.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/products/pubsub/Subscription.yaml b/mmv1/products/pubsub/Subscription.yaml index 9f53faa1c286..d9f4dd5b7fcd 100644 --- a/mmv1/products/pubsub/Subscription.yaml +++ b/mmv1/products/pubsub/Subscription.yaml @@ -269,6 +269,7 @@ properties: - !ruby/object:Api::Type::Boolean name: 'writeMetadata' required: true + send_empty_value: true description: | When true, writes the Pub/Sub message metadata to `x-goog-pubsub-:` headers of the HTTP request. Writes the From 0647d0a50fed4d3b86e051725e2500f8f52c0da7 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Tue, 22 Aug 2023 17:27:53 -0400 Subject: [PATCH 02/14] Update resource_pubsub_subscription_test.go --- .../resource_pubsub_subscription_test.go | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go b/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go index ddaceecd7bb7..5ac29b2b44b3 100644 --- a/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go +++ b/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go @@ -143,6 +143,31 @@ func TestAccPubsubSubscription_pushNoWrapper(t *testing.T) { }) } +func TestAccPubsubSubscription_pushNoWrapperEmpty(t *testing.T) { + t.Parallel() + + topicFoo := fmt.Sprintf("tf-test-topic-foo-%s", acctest.RandString(t, 10)) + subscription := fmt.Sprintf("tf-test-sub-foo-%s", acctest.RandString(t, 10)) + saAccount := fmt.Sprintf("tf-test-pubsub-%s", acctest.RandString(t, 10)) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccPubsubSubscription_pushNoWrapperEmpty(topicFoo, saAccount, subscription), + }, + { + ResourceName: "google_pubsub_subscription.foo", + ImportStateId: subscription, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + // Context: hashicorp/terraform-provider-google#4993 // This test makes a call to GET an subscription before it is actually created. // The PubSub API negative-caches responses so this tests we are @@ -277,6 +302,45 @@ resource "google_pubsub_subscription" "foo" { `, saAccount, topicFoo, subscription) } +func testAccPubsubSubscription_pushNoWrapperEmpty(topicFoo, saAccount, subscription string) string { + return fmt.Sprintf(` +data "google_project" "project" { } + +resource "google_service_account" "pub_sub_service_account" { + account_id = "%s" +} + +data "google_iam_policy" "admin" { + binding { + role = "roles/projects.topics.publish" + + members = [ + "serviceAccount:${google_service_account.pub_sub_service_account.email}", + ] + } +} + +resource "google_pubsub_topic" "foo" { + name = "%s" +} + +resource "google_pubsub_subscription" "foo" { + name = "%s" + topic = google_pubsub_topic.foo.name + ack_deadline_seconds = 10 + push_config { + push_endpoint = "https://${data.google_project.project.project_id}.appspot.com" + oidc_token { + service_account_email = google_service_account.pub_sub_service_account.email + } + no_wrapper { + write_metadata = false + } + } +} +`, saAccount, topicFoo, subscription) +} + func testAccPubsubSubscription_basic(topic, subscription, label string, deadline int, exactlyOnceDelivery bool) string { return fmt.Sprintf(` resource "google_pubsub_topic" "foo" { From 275f5f3d512a459800d88ccb608b8339a9fbe9bd Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Wed, 23 Aug 2023 12:41:31 -0400 Subject: [PATCH 03/14] Update Subscription.yaml --- mmv1/products/pubsub/Subscription.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/products/pubsub/Subscription.yaml b/mmv1/products/pubsub/Subscription.yaml index d9f4dd5b7fcd..32358e452349 100644 --- a/mmv1/products/pubsub/Subscription.yaml +++ b/mmv1/products/pubsub/Subscription.yaml @@ -262,6 +262,7 @@ properties: diff_suppress_func: 'tpgresource.IgnoreMissingKeyInMap("x-goog-version")' - !ruby/object:Api::Type::NestedObject name: 'noWrapper' + send_empty_value: true description: | When set, the payload to the push endpoint is not wrapped.Sets the `data` field as the HTTP body for delivery. From c89ed20e3b4a5e740d9f7cad270decf8b4da72d7 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Wed, 23 Aug 2023 12:53:55 -0400 Subject: [PATCH 04/14] Update Subscription.yaml --- mmv1/products/pubsub/Subscription.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/mmv1/products/pubsub/Subscription.yaml b/mmv1/products/pubsub/Subscription.yaml index 32358e452349..d9f4dd5b7fcd 100644 --- a/mmv1/products/pubsub/Subscription.yaml +++ b/mmv1/products/pubsub/Subscription.yaml @@ -262,7 +262,6 @@ properties: diff_suppress_func: 'tpgresource.IgnoreMissingKeyInMap("x-goog-version")' - !ruby/object:Api::Type::NestedObject name: 'noWrapper' - send_empty_value: true description: | When set, the payload to the push endpoint is not wrapped.Sets the `data` field as the HTTP body for delivery. From 2a17b1e822ed52be61fb76c12a01e09aa02966b5 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Fri, 25 Aug 2023 11:49:22 -0400 Subject: [PATCH 05/14] Create pubsub_no_wrapper_write_metadata_flatten.go.erb --- ...b_no_wrapper_write_metadata_flatten.go.erb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb new file mode 100644 index 000000000000..e7211a524bc8 --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -0,0 +1,20 @@ +<%# The license inside this block applies to this file. + # Copyright 2023 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return False + } + return v +} From 2538e979899e8db449d3941aece4b04eef6c5715 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Fri, 25 Aug 2023 11:49:29 -0400 Subject: [PATCH 06/14] Update Subscription.yaml --- mmv1/products/pubsub/Subscription.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/products/pubsub/Subscription.yaml b/mmv1/products/pubsub/Subscription.yaml index d9f4dd5b7fcd..34f2e5432926 100644 --- a/mmv1/products/pubsub/Subscription.yaml +++ b/mmv1/products/pubsub/Subscription.yaml @@ -270,6 +270,7 @@ properties: name: 'writeMetadata' required: true send_empty_value: true + custom_flatten: 'templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb' description: | When true, writes the Pub/Sub message metadata to `x-goog-pubsub-:` headers of the HTTP request. Writes the From d6ca3d6805c465e37db00ac0e48361c47e027390 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Fri, 25 Aug 2023 12:37:52 -0400 Subject: [PATCH 07/14] Update pubsub_no_wrapper_write_metadata_flatten.go.erb --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index e7211a524bc8..bc084597d81b 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -16,5 +16,5 @@ func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d if v == nil { return False } - return v + return v } From adba98ed1109ca82fa00962139908600d73bc9fe Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Tue, 5 Sep 2023 17:25:10 -0400 Subject: [PATCH 08/14] Update pubsub_no_wrapper_write_metadata_flatten.go.erb --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index bc084597d81b..b1c0db0b98f3 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -%> -func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return False } From 25c5217a9b28f3191a4703bb467e5adf1d0d73ec Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Tue, 5 Sep 2023 17:49:25 -0400 Subject: [PATCH 09/14] Update pubsub_no_wrapper_write_metadata_flatten.go.erb --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index b1c0db0b98f3..c9e8c15dcb21 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -14,7 +14,7 @@ -%> func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { - return False + return false } return v } From a642704268f482d956f57001d08e3ee20ad4dc5f Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Wed, 6 Sep 2023 11:38:54 -0400 Subject: [PATCH 10/14] Update pubsub_no_wrapper_write_metadata_flatten.go.erb --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index c9e8c15dcb21..d8a807d4f7f1 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -14,7 +14,15 @@ -%> func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { - return false + return nil } - return v + + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + + if original["writeMetadata"] == nil { + transformed["writeMetadata"] = false + } + + return []interface{}{transformed} } From 166685ec0fc9fa0d63eb327ffab8e6e69f8fe512 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Wed, 6 Sep 2023 11:39:00 -0400 Subject: [PATCH 11/14] Update Subscription.yaml --- mmv1/products/pubsub/Subscription.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/products/pubsub/Subscription.yaml b/mmv1/products/pubsub/Subscription.yaml index 34f2e5432926..2f40689d689c 100644 --- a/mmv1/products/pubsub/Subscription.yaml +++ b/mmv1/products/pubsub/Subscription.yaml @@ -262,6 +262,7 @@ properties: diff_suppress_func: 'tpgresource.IgnoreMissingKeyInMap("x-goog-version")' - !ruby/object:Api::Type::NestedObject name: 'noWrapper' + custom_flatten: 'templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb' description: | When set, the payload to the push endpoint is not wrapped.Sets the `data` field as the HTTP body for delivery. @@ -270,7 +271,6 @@ properties: name: 'writeMetadata' required: true send_empty_value: true - custom_flatten: 'templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb' description: | When true, writes the Pub/Sub message metadata to `x-goog-pubsub-:` headers of the HTTP request. Writes the From 912b956e7c98c103d70b2812d40eb9a6cb7eea14 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Wed, 6 Sep 2023 14:48:27 -0400 Subject: [PATCH 12/14] Update pubsub_no_wrapper_write_metadata_flatten.go.erb --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index d8a807d4f7f1..8c0e2cdd35c1 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -21,7 +21,7 @@ func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d transformed := make(map[string]interface{}) if original["writeMetadata"] == nil { - transformed["writeMetadata"] = false + transformed["write_metadata"] = false } return []interface{}{transformed} From 2cb67a66038e6365efb7a3933fa0785539c103f3 Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Thu, 7 Sep 2023 10:33:09 -0400 Subject: [PATCH 13/14] Update mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb Co-authored-by: Scott Suarez --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index 8c0e2cdd35c1..2631906b0d7e 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -22,6 +22,8 @@ func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d if original["writeMetadata"] == nil { transformed["write_metadata"] = false + } else { + transformed["write_metadata"] = original["writeMetadata"] } return []interface{}{transformed} From 345e9715ee6bceb9eedb4572b56e23244e4d4daa Mon Sep 17 00:00:00 2001 From: Casey O'Hare Date: Thu, 7 Sep 2023 10:48:34 -0400 Subject: [PATCH 14/14] Update pubsub_no_wrapper_write_metadata_flatten.go.erb --- .../pubsub_no_wrapper_write_metadata_flatten.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb index 2631906b0d7e..19f0d71ab1b6 100644 --- a/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb +++ b/mmv1/templates/terraform/custom_flatten/pubsub_no_wrapper_write_metadata_flatten.go.erb @@ -23,7 +23,7 @@ func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d if original["writeMetadata"] == nil { transformed["write_metadata"] = false } else { - transformed["write_metadata"] = original["writeMetadata"] + transformed["write_metadata"] = original["writeMetadata"] } return []interface{}{transformed}