-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Pub/Sub Schema support for changing definitions via revisio…
…ns (#8079) (#14857) * Add support for Pub/Sub schema evolution * Add example for Pub/Sub schema evolution * Remove changes not to be made in a single PR * Remove changes not to be made in a single PR * Remove changes not to be made in a single PR * Fix spacing * Test update, import * Reduce flakiness Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
f86079e
commit d898bd8
Showing
5 changed files
with
184 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
pubsub: Allowed `definition` of `google_pubsub_schema` to change without deleting and recreating the resource by using schema revisions (https://cloud.google.com/pubsub/docs/schemas#commit-schema-revision) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestAccPubsubSchema_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
schema := fmt.Sprintf("tf-test-schema-%s", RandString(t, 10)) | ||
|
||
VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), | ||
ExternalProviders: map[string]resource.ExternalProvider{ | ||
"time": {}, | ||
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccPubsubSchema_basic(schema), | ||
}, | ||
{ | ||
ResourceName: "google_pubsub_schema.foo", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccPubsubSchema_updated(schema), | ||
}, | ||
{ | ||
ResourceName: "google_pubsub_schema.foo", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccPubsubSchema_basic(schema string) string { | ||
return fmt.Sprintf(` | ||
resource "google_pubsub_schema" "foo" { | ||
name = "%s" | ||
type = "PROTOCOL_BUFFER" | ||
definition = "syntax = \"proto3\";\nmessage Results {\nstring message_request = 1;\nstring message_response = 2;\n}" | ||
} | ||
# Need to introduce delay for updates in order for tests to complete | ||
# successfully due to caching effects. | ||
resource "time_sleep" "wait_121_seconds" { | ||
create_duration = "121s" | ||
lifecycle { | ||
replace_triggered_by = [ | ||
google_pubsub_schema.foo | ||
] | ||
} | ||
} | ||
`, schema) | ||
} | ||
|
||
func testAccPubsubSchema_updated(schema string) string { | ||
return fmt.Sprintf(` | ||
resource "google_pubsub_schema" "foo" { | ||
name = "%s" | ||
type = "PROTOCOL_BUFFER" | ||
definition = "syntax = \"proto3\";\nmessage Results {\nstring message_request = 1;\nstring message_response = 2;\nstring timestamp_request = 3;\n}" | ||
} | ||
# Need to introduce delay for updates in order for tests to complete | ||
# successfully due to caching effects. | ||
resource "time_sleep" "wait_121_seconds" { | ||
create_duration = "121s" | ||
lifecycle { | ||
replace_triggered_by = [ | ||
google_pubsub_schema.foo | ||
] | ||
} | ||
} | ||
`, schema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters