Skip to content

Commit 3405efe

Browse files
modular-magicianrileykarsonc2thorn
authored
Prepared storage_pubsub_notifications snippet for inclusion on C.G.C (#6031) (#4371)
Co-authored-by: Riley Karson <[email protected]> Co-authored-by: Cameron Thornton <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Riley Karson <[email protected]> Co-authored-by: Cameron Thornton <[email protected]>
1 parent bdd4b3b commit 3405efe

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

.changelog/6031.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
```release-note:none
2+
```

google-beta/resource_cgc_snippet_generated_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,3 +1016,60 @@ resource "google_storage_bucket_iam_member" "member" {
10161016
}
10171017
`, context)
10181018
}
1019+
1020+
func TestAccCGCSnippet_storagePubsubNotificationsExample(t *testing.T) {
1021+
t.Parallel()
1022+
1023+
context := map[string]interface{}{
1024+
"random_suffix": randString(t, 10),
1025+
}
1026+
1027+
vcrTest(t, resource.TestCase{
1028+
PreCheck: func() { testAccPreCheck(t) },
1029+
Providers: testAccProvidersOiCS,
1030+
Steps: []resource.TestStep{
1031+
{
1032+
Config: testAccCGCSnippet_storagePubsubNotificationsExample(context),
1033+
},
1034+
{
1035+
ResourceName: "google_pubsub_topic.topic",
1036+
ImportState: true,
1037+
ImportStateVerify: true,
1038+
},
1039+
},
1040+
})
1041+
}
1042+
1043+
func testAccCGCSnippet_storagePubsubNotificationsExample(context map[string]interface{}) string {
1044+
return Nprintf(`
1045+
// Create a Pub/Sub notification.
1046+
resource "google_storage_notification" "notification" {
1047+
bucket = google_storage_bucket.bucket.name
1048+
payload_format = "JSON_API_V1"
1049+
topic = google_pubsub_topic.topic.id
1050+
depends_on = [google_pubsub_topic_iam_binding.binding]
1051+
}
1052+
1053+
// Enable notifications by giving the correct IAM permission to the unique service account.
1054+
data "google_storage_project_service_account" "gcs_account" {
1055+
}
1056+
1057+
// Create a Pub/Sub topic.
1058+
resource "google_pubsub_topic_iam_binding" "binding" {
1059+
topic = google_pubsub_topic.topic.id
1060+
role = "roles/pubsub.publisher"
1061+
members = ["serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"]
1062+
}
1063+
1064+
// Create a new storage bucket.
1065+
resource "google_storage_bucket" "bucket" {
1066+
name = "tf-test-example-bucket-name%{random_suffix}"
1067+
location = "US"
1068+
uniform_bucket_level_access = true
1069+
}
1070+
1071+
resource "google_pubsub_topic" "topic" {
1072+
name = "tf_test_your_topic_name%{random_suffix}"
1073+
}
1074+
`, context)
1075+
}

0 commit comments

Comments
 (0)