Skip to content

Commit 91c21bf

Browse files
Added Cloud Storage as a PubSub subscription (#8517) (#15420)
Signed-off-by: Modular Magician <[email protected]>
1 parent 689dff2 commit 91c21bf

File tree

4 files changed

+563
-6
lines changed

4 files changed

+563
-6
lines changed

.changelog/8517.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
pubsub: added `CloudStorageConfig` field to `google_pubsub_subscription` resource
3+
```

google/resource_pubsub_subscription_generated_test.go

+138
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,144 @@ EOF
266266
`, context)
267267
}
268268

269+
func TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageExample(t *testing.T) {
270+
t.Parallel()
271+
272+
context := map[string]interface{}{
273+
"random_suffix": acctest.RandString(t, 10),
274+
}
275+
276+
acctest.VcrTest(t, resource.TestCase{
277+
PreCheck: func() { acctest.AccTestPreCheck(t) },
278+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
279+
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t),
280+
Steps: []resource.TestStep{
281+
{
282+
Config: testAccPubsubSubscription_pubsubSubscriptionPushCloudstorageExample(context),
283+
},
284+
{
285+
ResourceName: "google_pubsub_subscription.example",
286+
ImportState: true,
287+
ImportStateVerify: true,
288+
ImportStateVerifyIgnore: []string{"topic"},
289+
},
290+
},
291+
})
292+
}
293+
294+
func testAccPubsubSubscription_pubsubSubscriptionPushCloudstorageExample(context map[string]interface{}) string {
295+
return acctest.Nprintf(`
296+
resource "google_storage_bucket" "example" {
297+
name = "tf-test-example-bucket%{random_suffix}"
298+
location = "US"
299+
uniform_bucket_level_access = true
300+
}
301+
302+
resource "google_pubsub_topic" "example" {
303+
name = "tf-test-example-topic%{random_suffix}"
304+
}
305+
306+
resource "google_pubsub_subscription" "example" {
307+
name = "tf-test-example-subscription%{random_suffix}"
308+
topic = google_pubsub_topic.example.name
309+
310+
cloud_storage_config {
311+
bucket = google_storage_bucket.example.name
312+
313+
filename_prefix = "pre-"
314+
filename_suffix = "-%{random_suffix}"
315+
316+
max_bytes = 1000
317+
max_duration = "300s"
318+
}
319+
depends_on = [
320+
google_storage_bucket.example,
321+
google_storage_bucket_iam_member.admin,
322+
]
323+
}
324+
325+
data "google_project" "project" {
326+
}
327+
328+
resource "google_storage_bucket_iam_member" "admin" {
329+
bucket = google_storage_bucket.example.name
330+
role = "roles/storage.admin"
331+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
332+
}
333+
`, context)
334+
}
335+
336+
func TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageAvroExample(t *testing.T) {
337+
t.Parallel()
338+
339+
context := map[string]interface{}{
340+
"random_suffix": acctest.RandString(t, 10),
341+
}
342+
343+
acctest.VcrTest(t, resource.TestCase{
344+
PreCheck: func() { acctest.AccTestPreCheck(t) },
345+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
346+
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t),
347+
Steps: []resource.TestStep{
348+
{
349+
Config: testAccPubsubSubscription_pubsubSubscriptionPushCloudstorageAvroExample(context),
350+
},
351+
{
352+
ResourceName: "google_pubsub_subscription.example",
353+
ImportState: true,
354+
ImportStateVerify: true,
355+
ImportStateVerifyIgnore: []string{"topic"},
356+
},
357+
},
358+
})
359+
}
360+
361+
func testAccPubsubSubscription_pubsubSubscriptionPushCloudstorageAvroExample(context map[string]interface{}) string {
362+
return acctest.Nprintf(`
363+
resource "google_storage_bucket" "example" {
364+
name = "tf-test-example-bucket%{random_suffix}"
365+
location = "US"
366+
uniform_bucket_level_access = true
367+
}
368+
369+
resource "google_pubsub_topic" "example" {
370+
name = "tf-test-example-topic%{random_suffix}"
371+
}
372+
373+
resource "google_pubsub_subscription" "example" {
374+
name = "tf-test-example-subscription%{random_suffix}"
375+
topic = google_pubsub_topic.example.name
376+
377+
cloud_storage_config {
378+
bucket = google_storage_bucket.example.name
379+
380+
filename_prefix = "pre-"
381+
filename_suffix = "-%{random_suffix}"
382+
383+
max_bytes = 1000
384+
max_duration = "300s"
385+
386+
avro_config {
387+
write_metadata = true
388+
}
389+
}
390+
depends_on = [
391+
google_storage_bucket.example,
392+
google_storage_bucket_iam_member.admin,
393+
]
394+
}
395+
396+
data "google_project" "project" {
397+
}
398+
399+
resource "google_storage_bucket_iam_member" "admin" {
400+
bucket = google_storage_bucket.example.name
401+
role = "roles/storage.admin"
402+
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
403+
}
404+
`, context)
405+
}
406+
269407
func testAccCheckPubsubSubscriptionDestroyProducer(t *testing.T) func(s *terraform.State) error {
270408
return func(s *terraform.State) error {
271409
for name, rs := range s.RootModule().Resources {

0 commit comments

Comments
 (0)