@@ -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