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 issue #15555: Set send_empty_value for noWrapper.writeMetadata #6219

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/8739.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pubsub: fixed issue where setting `no_wrapper.write_metadata` to false wasn't passed to the API for `google_pubsub_subscription`
```
18 changes: 9 additions & 9 deletions google-beta/services/pubsub/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,18 +1167,18 @@ func flattenPubsubSubscriptionPushConfigNoWrapper(v interface{}, d *schema.Resou
if v == nil {
return nil
}

original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["write_metadata"] =
flattenPubsubSubscriptionPushConfigNoWrapperWriteMetadata(original["writeMetadata"], d, config)

if original["writeMetadata"] == nil {
transformed["write_metadata"] = false
} else {
transformed["write_metadata"] = original["writeMetadata"]
}

return []interface{}{transformed}
}
func flattenPubsubSubscriptionPushConfigNoWrapperWriteMetadata(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubSubscriptionAckDeadlineSeconds(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
Expand Down Expand Up @@ -1592,7 +1592,7 @@ func expandPubsubSubscriptionPushConfigNoWrapper(v interface{}, d tpgresource.Te
transformedWriteMetadata, err := expandPubsubSubscriptionPushConfigNoWrapperWriteMetadata(original["write_metadata"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedWriteMetadata); val.IsValid() && !tpgresource.IsEmptyValue(val) {
} else {
transformed["writeMetadata"] = transformedWriteMetadata
}

Expand Down
64 changes: 64 additions & 0 deletions google-beta/services/pubsub/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,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
Expand Down Expand Up @@ -279,6 +304,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" {
Expand Down
Loading