Skip to content

Commit 6e28de4

Browse files
Adding new samples for PubSub with Cloud Run tutorials (#6126) (#11930)
* feat: add in samples for pubsub tutorials for cloud run refactor: switching to erb * Update mmv1/templates/terraform/examples/cloud_run_service_pubsub.tf.erb Co-authored-by: Stephen Lewis (Burrows) <[email protected]> * Update mmv1/templates/terraform/examples/cloud_run_service_pubsub.tf.erb Co-authored-by: Stephen Lewis (Burrows) <[email protected]> * Update mmv1/templates/terraform/examples/cloud_run_service_pubsub.tf.erb Co-authored-by: Stephen Lewis (Burrows) <[email protected]> * Update mmv1/templates/terraform/examples/cloud_run_service_pubsub.tf.erb Co-authored-by: Stephen Lewis (Burrows) <[email protected]> * refactor: remove extra cloud pubsub vars * Update mmv1/templates/terraform/examples/cloud_run_service_pubsub.tf.erb Co-authored-by: Stephen Lewis (Burrows) <[email protected]> * Update mmv1/templates/terraform/examples/cloud_run_service_pubsub.tf.erb Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 1d061ea commit 6e28de4

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

.changelog/6126.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
google_cloud_run_service: added samples for pubsub tutorials
3+
```

website/docs/r/cloud_run_service.html.markdown

+55
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,61 @@ To get more information about Service, see:
4848
a Cloud Run Service on Anthos(GKE/VMWare) then you will need to create it using the kubernetes alpha provider.
4949
Have a look at the Cloud Run Anthos example below.
5050

51+
## Example Usage - Cloud Run Service Pubsub
52+
53+
54+
```hcl
55+
resource "google_cloud_run_service" "default" {
56+
name = "cloud_run_service_name"
57+
location = "us-central1"
58+
template {
59+
spec {
60+
containers {
61+
image = "gcr.io/cloudrun/hello"
62+
}
63+
}
64+
}
65+
traffic {
66+
percent = 100
67+
latest_revision = true
68+
}
69+
}
70+
71+
resource "google_service_account" "sa" {
72+
account_id = "cloud-run-pubsub-invoker"
73+
display_name = "Cloud Run Pub/Sub Invoker"
74+
}
75+
76+
resource "google_cloud_run_service_iam_binding" "binding" {
77+
location = google_cloud_run_service.default.location
78+
service = google_cloud_run_service.default.name
79+
role = "roles/run.invoker"
80+
members = ["serviceAccount:${google_service_account.sa.email}"]
81+
}
82+
83+
resource "google_project_iam_binding" "project" {
84+
role = "roles/iam.serviceAccountTokenCreator"
85+
members = ["serviceAccount:${google_service_account.sa.email}"]
86+
}
87+
88+
resource "google_pubsub_topic" "topic" {
89+
name = "pubsub_topic"
90+
}
91+
92+
resource "google_pubsub_subscription" "subscription" {
93+
name = "pubsub_subscription"
94+
topic = google_pubsub_topic.topic.name
95+
push_config {
96+
push_endpoint = google_cloud_run_service.default.status[0].url
97+
oidc_token {
98+
service_account_email = google_service_account.sa.email
99+
}
100+
attributes = {
101+
x-goog-version = "v1"
102+
}
103+
}
104+
}
105+
```
51106
## Example Usage - Cloud Run Service Basic
52107

53108

0 commit comments

Comments
 (0)