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

pubsub: fix permadiff with configuring an empty retry_policy. #11834

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions mmv1/products/pubsub/Subscription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ properties:
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
default_from_api: true
diff_suppress_func: 'tpgresource.DurationDiffSuppress'
send_empty_value: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want allow_empty_object here as well, though it looks like the tests are passing, so maybe it's fine? Did you happen to try that out?

Suggested change
send_empty_value: true
send_empty_value: true
allow_empty_object: true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the earlier BQ-related test failures seem unrelated and are passing now. Thanks for opening hashicorp/terraform-provider-google#19683.

Those tests pass locally as well:

$ make testacc TEST=./google-beta/services/pubsub TESTARGS='-run=TestAccPubsubSubscription_pubsubSubscriptionPushBqExample'
==> Checking that code complies with gofmt requirements...
go vet
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google-beta/services/pubsub -v -run=TestAccPubsubSubscription_pubsubSubscriptionPushBqExample -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc"
=== RUN   TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
=== PAUSE TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
=== CONT  TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
--- PASS: TestAccPubsubSubscription_pubsubSubscriptionPushBqExample (30.70s)
PASS
ok      github.com/hashicorp/terraform-provider-google-beta/google-beta/services/pubsub 31.317s

$ make testacc TEST=./google-beta/services/pubsub TESTARGS='-run=TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample'
==> Checking that code complies with gofmt requirements...
go vet
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google-beta/services/pubsub -v -run=TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc"
=== RUN   TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
=== PAUSE TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
=== CONT  TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
--- PASS: TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample (30.34s)
PASS
ok      github.com/hashicorp/terraform-provider-google-beta/google-beta/services/pubsub 30.958s

Similarly, the "VCR-test" was flaky as well but is passing now. However, the terraform-google-conversion-build-and-unit-tests failures show a permadiff with "retryPolicy": nil, (example test case and test code throwing the error). I think that I'd need to submit a separate PR to fix those tests since they are in a different repo.

I think you'll want allow_empty_object here as well, though it looks like the tests are passing, so maybe it's fine? Did you happen to try that out?

I didn't see that in the field reference but I see it here and used elsewhere in Subscription.yaml. But yeah, the tests are passing with or without allow_empty_object and I'm not sure why, but it doesn't seem like adding allow_empty_object will hurt so I've added it.

allow_empty_object: true
- name: 'enableMessageOrdering'
type: Boolean
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ func TestAccPubsubSubscription_emptyTTL(t *testing.T) {
})
}

func TestAccPubsubSubscription_emptyRetryPolicy(t *testing.T) {
t.Parallel()

topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(t, 10))
subscription := fmt.Sprintf("tf-test-sub-%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_emptyRetryPolicy(topic, subscription),
},
{
ResourceName: "google_pubsub_subscription.foo",
ImportStateId: subscription,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccPubsubSubscription_basic(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -494,6 +518,22 @@ resource "google_pubsub_subscription" "foo" {
`, topic, subscription)
}

func testAccPubsubSubscription_emptyRetryPolicy(topic, subscription string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"
}

resource "google_pubsub_subscription" "foo" {
name = "%s"
topic = google_pubsub_topic.foo.id

retry_policy {
}
}
`, topic, subscription)
}

func testAccPubsubSubscription_push(topicFoo, saAccount, subscription string) string {
return fmt.Sprintf(`
data "google_project" "project" { }
Expand Down