Skip to content

Commit 4a84afe

Browse files
Replace "Pubsub Subscription Different Project" example with making all examples cross-project-friendly (#9637) (#16806)
* 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 #11642. Fixes #6024. * Make all examples cross-project-friendly and update topic description * Fix typo --------- [upstream:b3ae8dcd7e476f796a8b1ba67ce63cea711be127] Signed-off-by: Modular Magician <[email protected]>
1 parent 2c889cb commit 4a84afe

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

.changelog/9637.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google/services/pubsub/resource_pubsub_subscription.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ func ResourcePubsubSubscription() *schema.Resource {
7878
Required: true,
7979
ForceNew: true,
8080
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
81-
Description: `A reference to a Topic resource.`,
81+
Description: `A reference to a Topic resource, of the form projects/{project}/topics/{{name}}
82+
(as in the id property of a google_pubsub_topic), or just a topic name if
83+
the topic is in the same project as the subscription.`,
8284
},
8385
"ack_deadline_seconds": {
8486
Type: schema.TypeInt,

google/services/pubsub/resource_pubsub_subscription_generated_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ resource "google_pubsub_topic" "example" {
6363
6464
resource "google_pubsub_subscription" "example" {
6565
name = "tf-test-example-subscription%{random_suffix}"
66-
topic = google_pubsub_topic.example.name
66+
topic = google_pubsub_topic.example.id
6767
6868
ack_deadline_seconds = 20
6969
@@ -115,7 +115,7 @@ resource "google_pubsub_topic" "example" {
115115
116116
resource "google_pubsub_subscription" "example" {
117117
name = "tf-test-example-subscription%{random_suffix}"
118-
topic = google_pubsub_topic.example.name
118+
topic = google_pubsub_topic.example.id
119119
120120
labels = {
121121
foo = "bar"
@@ -176,7 +176,7 @@ resource "google_pubsub_topic" "example_dead_letter" {
176176
177177
resource "google_pubsub_subscription" "example" {
178178
name = "tf-test-example-subscription%{random_suffix}"
179-
topic = google_pubsub_topic.example.name
179+
topic = google_pubsub_topic.example.id
180180
181181
dead_letter_policy {
182182
dead_letter_topic = google_pubsub_topic.example_dead_letter.id
@@ -219,7 +219,7 @@ resource "google_pubsub_topic" "example" {
219219
220220
resource "google_pubsub_subscription" "example" {
221221
name = "tf-test-example-subscription%{random_suffix}"
222-
topic = google_pubsub_topic.example.name
222+
topic = google_pubsub_topic.example.id
223223
224224
bigquery_config {
225225
table = "${google_bigquery_table.test.project}.${google_bigquery_table.test.dataset_id}.${google_bigquery_table.test.table_id}"
@@ -305,7 +305,7 @@ resource "google_pubsub_topic" "example" {
305305
306306
resource "google_pubsub_subscription" "example" {
307307
name = "tf-test-example-subscription%{random_suffix}"
308-
topic = google_pubsub_topic.example.name
308+
topic = google_pubsub_topic.example.id
309309
310310
cloud_storage_config {
311311
bucket = google_storage_bucket.example.name
@@ -372,7 +372,7 @@ resource "google_pubsub_topic" "example" {
372372
373373
resource "google_pubsub_subscription" "example" {
374374
name = "tf-test-example-subscription%{random_suffix}"
375-
topic = google_pubsub_topic.example.name
375+
topic = google_pubsub_topic.example.id
376376
377377
cloud_storage_config {
378378
bucket = google_storage_bucket.example.name

website/docs/r/pubsub_subscription.html.markdown

+9-22
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "google_pubsub_topic" "example" {
4848
4949
resource "google_pubsub_subscription" "example" {
5050
name = "example-subscription"
51-
topic = google_pubsub_topic.example.name
51+
topic = google_pubsub_topic.example.id
5252
5353
ack_deadline_seconds = 20
5454
@@ -80,7 +80,7 @@ resource "google_pubsub_topic" "example" {
8080
8181
resource "google_pubsub_subscription" "example" {
8282
name = "example-subscription"
83-
topic = google_pubsub_topic.example.name
83+
topic = google_pubsub_topic.example.id
8484
8585
labels = {
8686
foo = "bar"
@@ -102,21 +102,6 @@ resource "google_pubsub_subscription" "example" {
102102
enable_message_ordering = false
103103
}
104104
```
105-
## Example Usage - Pubsub Subscription Different Project
106-
107-
108-
```hcl
109-
resource "google_pubsub_topic" "example" {
110-
project = "topic-project"
111-
name = "example-topic"
112-
}
113-
114-
resource "google_pubsub_subscription" "example" {
115-
project = "subscription-project"
116-
name = "example-subscription"
117-
topic = google_pubsub_topic.example.name
118-
}
119-
```
120105
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
121106
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%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">
122107
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -136,7 +121,7 @@ resource "google_pubsub_topic" "example_dead_letter" {
136121
137122
resource "google_pubsub_subscription" "example" {
138123
name = "example-subscription"
139-
topic = google_pubsub_topic.example.name
124+
topic = google_pubsub_topic.example.id
140125
141126
dead_letter_policy {
142127
dead_letter_topic = google_pubsub_topic.example_dead_letter.id
@@ -159,7 +144,7 @@ resource "google_pubsub_topic" "example" {
159144
160145
resource "google_pubsub_subscription" "example" {
161146
name = "example-subscription"
162-
topic = google_pubsub_topic.example.name
147+
topic = google_pubsub_topic.example.id
163148
164149
bigquery_config {
165150
table = "${google_bigquery_table.test.project}.${google_bigquery_table.test.dataset_id}.${google_bigquery_table.test.table_id}"
@@ -225,7 +210,7 @@ resource "google_pubsub_topic" "example" {
225210
226211
resource "google_pubsub_subscription" "example" {
227212
name = "example-subscription"
228-
topic = google_pubsub_topic.example.name
213+
topic = google_pubsub_topic.example.id
229214
230215
cloud_storage_config {
231216
bucket = google_storage_bucket.example.name
@@ -272,7 +257,7 @@ resource "google_pubsub_topic" "example" {
272257
273258
resource "google_pubsub_subscription" "example" {
274259
name = "example-subscription"
275-
topic = google_pubsub_topic.example.name
260+
topic = google_pubsub_topic.example.id
276261
277262
cloud_storage_config {
278263
bucket = google_storage_bucket.example.name
@@ -314,7 +299,9 @@ The following arguments are supported:
314299

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

319306

320307
- - -

0 commit comments

Comments
 (0)