Skip to content

Commit

Permalink
Replace "Pubsub Subscription Different Project" example with making a…
Browse files Browse the repository at this point in the history
…ll examples cross-project-friendly (#9637) (#6758)

* Fix "Pubsub Subscription Different Project" example

PR #2342 changed this example from using `id` to `name`, which removed the project ID from the topic. However, the point of this example is to show how to set up a cross-project subscription, so the example no longer works. This change reverts that change from PR #2342.

Fixes hashicorp/terraform-provider-google#11642.
Fixes hashicorp/terraform-provider-google#6024.

* Make all examples cross-project-friendly and update topic description

* Fix typo

---------


[upstream:b3ae8dcd7e476f796a8b1ba67ce63cea711be127]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 14, 2023
1 parent e54d3b4 commit 0b512e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .changelog/9637.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
4 changes: 3 additions & 1 deletion google-beta/services/pubsub/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func ResourcePubsubSubscription() *schema.Resource {
Required: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `A reference to a Topic resource.`,
Description: `A reference to a Topic resource, of the form projects/{project}/topics/{{name}}
(as in the id property of a google_pubsub_topic), or just a topic name if
the topic is in the same project as the subscription.`,
},
"ack_deadline_seconds": {
Type: schema.TypeInt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
ack_deadline_seconds = 20
Expand Down Expand Up @@ -115,7 +115,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
labels = {
foo = "bar"
Expand Down Expand Up @@ -176,7 +176,7 @@ resource "google_pubsub_topic" "example_dead_letter" {
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
dead_letter_policy {
dead_letter_topic = google_pubsub_topic.example_dead_letter.id
Expand Down Expand Up @@ -219,7 +219,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
bigquery_config {
table = "${google_bigquery_table.test.project}.${google_bigquery_table.test.dataset_id}.${google_bigquery_table.test.table_id}"
Expand Down Expand Up @@ -305,7 +305,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
cloud_storage_config {
bucket = google_storage_bucket.example.name
Expand Down Expand Up @@ -372,7 +372,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "tf-test-example-subscription%{random_suffix}"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
cloud_storage_config {
bucket = google_storage_bucket.example.name
Expand Down
31 changes: 9 additions & 22 deletions website/docs/r/pubsub_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
ack_deadline_seconds = 20
Expand Down Expand Up @@ -80,7 +80,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
labels = {
foo = "bar"
Expand All @@ -102,21 +102,6 @@ resource "google_pubsub_subscription" "example" {
enable_message_ordering = false
}
```
## Example Usage - Pubsub Subscription Different Project


```hcl
resource "google_pubsub_topic" "example" {
project = "topic-project"
name = "example-topic"
}
resource "google_pubsub_subscription" "example" {
project = "subscription-project"
name = "example-subscription"
topic = google_pubsub_topic.example.name
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=pubsub_subscription_dead_letter&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand All @@ -136,7 +121,7 @@ resource "google_pubsub_topic" "example_dead_letter" {
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
dead_letter_policy {
dead_letter_topic = google_pubsub_topic.example_dead_letter.id
Expand All @@ -159,7 +144,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
bigquery_config {
table = "${google_bigquery_table.test.project}.${google_bigquery_table.test.dataset_id}.${google_bigquery_table.test.table_id}"
Expand Down Expand Up @@ -225,7 +210,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
cloud_storage_config {
bucket = google_storage_bucket.example.name
Expand Down Expand Up @@ -272,7 +257,7 @@ resource "google_pubsub_topic" "example" {
resource "google_pubsub_subscription" "example" {
name = "example-subscription"
topic = google_pubsub_topic.example.name
topic = google_pubsub_topic.example.id
cloud_storage_config {
bucket = google_storage_bucket.example.name
Expand Down Expand Up @@ -314,7 +299,9 @@ The following arguments are supported:

* `topic` -
(Required)
A reference to a Topic resource.
A reference to a Topic resource, of the form projects/{project}/topics/{{name}}
(as in the id property of a google_pubsub_topic), or just a topic name if
the topic is in the same project as the subscription.


- - -
Expand Down

0 comments on commit 0b512e4

Please sign in to comment.