rkrade
June 16, 2023, 10:20pm
1
Hello folks,
Thanks for looking into this. I am not sure if I followed anywhere in provided docs (4.69.1) on how actually to implement this in terraform - committing new schema revisions without destroying and creating a new pubsub topic.
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_schema
GoogleCloudPlatform:main
← kamalaboulhosn:pubsub-schema-fixes
opened 08:10PM - 02 Jun 23 UTC
Allows schema definition to be changed by committing schema revisions. Fixes htt… ps://github.com/hashicorp/terraform-provider-google/issues/13997. This replaces https://github.com/GoogleCloudPlatform/magic-modules/pull/7981. @SarahFrench and @melinath have the most context on this.
<!--
Replace each [ ] with [X] to check it. Switch to the preview view to make it easier to click on links.
These steps will speed up the review process, and we appreciate you spending time on them before sending
your code to be reviewed.
-->
If this PR is for Terraform, I acknowledge that I have:
- [X] Searched through the [issue tracker](https://github.com/hashicorp/terraform-provider-google/issues) for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
- [X] Ensured that all new fields I added that can be set by a user appear in at least one [example](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/examples) (for generated resources) or [third_party test](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) (for handwritten resources or update tests).
- [X] [Generated Terraform providers](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/docs/content/docs/getting-started/generate-providers.md), and ran [`make test` and `make lint`](https://googlecloudplatform.github.io/magic-modules/docs/getting-started/run-provider-tests/#run-unit-tests) in the generated providers to ensure it passes unit and linter tests.
- [X] [Ran](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/docs/content/docs/getting-started/run-provider-tests.md) relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
- [X] Read the [Release Notes Guide](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/.ci/RELEASE_NOTES_GUIDE.md) before writing my release note below.
<!-- AUTOCHANGELOG for Downstream PRs.
Please select one of the following "release-note:" headings:
- release-note:enhancement
Unless you choose release-note:none, please add a release note.
See .[ci/RELEASE_NOTES_GUIDE.md](http://ci/RELEASE_NOTES_GUIDE.md) for writing good release notes.
You can add more release note blocks if you want more than one CHANGELOG
entry for this PR.
-->
**Release Note Template for Downstream PRs (will be copied)**
```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)
```
rkrade
June 21, 2023, 12:06am
3
So I believe it worked, just updating the test-topic.proto (proto file) and running terraform apply on the target did commit a new schema revision but it deleted the previous revisions and the corresponding topic so I had to recreate the topic after creating the new schema. I was wondering if you could actually commit a revision without deleting the older revisions/topics.
Summary
module “test-topic” {
source = “…/modules/pubsub_topic”
project = var.project
schema_file = “./schema/test-topic.proto”
schema_name = “test-topic-v6”
topic_name = “test-topic-v6”
}
resource “google_pubsub_schema” “schema” {
project = var.project
name = var.topic_name
type = “PROTOCOL_BUFFER”
definition = file(var.schema_file)
}
resource “google_pubsub_topic” “topic” {
project = var.project
name = var.topic_name
depends_on = [google_pubsub_schema.schema]
schema_settings {
schema = “projects/{var.project}/schemas/ {var.schema_name}”
encoding = var.schema_encoding
}
}