Create a trigger using Terraform (workflow)

Creates a workflow that returns information about Google Cloud Storage events.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Terraform

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands. For more information, see the Terraform provider reference documentation.

# Create a workflow
resource "google_workflows_workflow" "default" {
  name        = "storage-workflow-tf"
  region      = "us-central1"
  description = "Workflow that returns information about storage events"

  deletion_protection = false # set to "true" in production

  # Note that $$ is needed for Terraform
  source_contents = <<EOF
  main:
    params: [event]
    steps:
      - log_event:
          call: sys.log
          args:
            text: $${event}
            severity: INFO
      - gather_data:
          assign:
            - bucket: $${event.data.bucket}
            - name: $${event.data.name}
            - message: $${"Received event " + event.type + " - " + bucket + ", " + name}
      - return_data:
          return: $${message}
  EOF

  depends_on = [
    google_project_service.workflows
  ]
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.