@@ -395,6 +395,127 @@ resource "google_compute_instance" "instance_virtual_display" {
395395` , context )
396396}
397397
398+ func TestAccCGCSnippet_eventarcWorkflowsExample (t * testing.T ) {
399+ t .Parallel ()
400+
401+ context := map [string ]interface {}{
402+ "random_suffix" : randString (t , 10 ),
403+ }
404+
405+ vcrTest (t , resource.TestCase {
406+ PreCheck : func () { testAccPreCheck (t ) },
407+ Providers : testAccProvidersOiCS ,
408+ Steps : []resource.TestStep {
409+ {
410+ Config : testAccCGCSnippet_eventarcWorkflowsExample (context ),
411+ },
412+ {
413+ ResourceName : "google_eventarc_trigger.trigger_pubsub_tf" ,
414+ ImportState : true ,
415+ ImportStateVerify : true ,
416+ },
417+ },
418+ })
419+ }
420+
421+ func testAccCGCSnippet_eventarcWorkflowsExample (context map [string ]interface {}) string {
422+ return Nprintf (`
423+ # Used to retrieve project_number later
424+ data "google_project" "project" {
425+ provider = google-beta
426+ }
427+
428+ # Enable Eventarc API
429+ resource "google_project_service" "eventarc" {
430+ provider = google-beta
431+ service = "eventarc.googleapis.com"
432+ disable_on_destroy = false
433+ }
434+
435+ # Enable Pub/Sub API
436+ resource "google_project_service" "pubsub" {
437+ provider = google-beta
438+ service = "pubsub.googleapis.com"
439+ disable_on_destroy = false
440+ }
441+
442+ # Enable Workflows API
443+ resource "google_project_service" "workflows" {
444+ provider = google-beta
445+ service = "workflows.googleapis.com"
446+ disable_on_destroy = false
447+ }
448+
449+
450+
451+ # Create a service account for Eventarc trigger and Workflows
452+ resource "google_service_account" "eventarc_workflows_service_account" {
453+ provider = google-beta
454+ account_id = "eventarc-workflows-sa"
455+ display_name = "Eventarc Workflows Service Account"
456+ }
457+
458+ # Grant the logWriter role to the service account
459+ resource "google_project_iam_binding" "project_binding_eventarc" {
460+ provider = google-beta
461+ project = data.google_project.project.id
462+ role = "roles/logging.logWriter"
463+
464+ members = ["serviceAccount:${google_service_account.eventarc_workflows_service_account.email}"]
465+
466+ depends_on = [google_service_account.eventarc_workflows_service_account]
467+ }
468+
469+ # Grant the workflows.invoker role to the service account
470+ resource "google_project_iam_binding" "project_binding_workflows" {
471+ provider = google-beta
472+ project = data.google_project.project.id
473+ role = "roles/workflows.invoker"
474+
475+ members = ["serviceAccount:${google_service_account.eventarc_workflows_service_account.email}"]
476+
477+ depends_on = [google_service_account.eventarc_workflows_service_account]
478+ }
479+
480+
481+ # Define and deploy a workflow
482+ resource "google_workflows_workflow" "workflows_example" {
483+ name = "tf-test-pubsub-workflow-tf%{random_suffix}"
484+ provider = google-beta
485+ region = "us-central1"
486+ description = "A sample workflow"
487+ service_account = google_service_account.eventarc_workflows_service_account.id
488+ # Imported main workflow YAML file
489+ source_contents = templatefile("test-fixtures/workflow.yaml",{})
490+
491+ depends_on = [google_project_service.workflows,
492+ google_service_account.eventarc_workflows_service_account]
493+ }
494+
495+
496+ # Create an Eventarc trigger routing Pub/Sub events to Workflows
497+ resource "google_eventarc_trigger" "trigger_pubsub_tf" {
498+ name = "tf-test-trigger-pubsub-workflow-tf%{random_suffix}"
499+ provider = google-beta
500+ location = "us-central1"
501+ matching_criteria {
502+ attribute = "type"
503+ value = "google.cloud.pubsub.topic.v1.messagePublished"
504+ }
505+ destination {
506+ workflow = google_workflows_workflow.workflows_example.id
507+ }
508+
509+
510+ service_account = google_service_account.eventarc_workflows_service_account.id
511+
512+ depends_on = [google_project_service.pubsub, google_project_service.eventarc,
513+ google_service_account.eventarc_workflows_service_account]
514+ }
515+
516+ ` , context )
517+ }
518+
398519func TestAccCGCSnippet_sqlDatabaseInstanceSqlserverExample (t * testing.T ) {
399520 skipIfVcr (t )
400521 t .Parallel ()
0 commit comments