Create and deploy a workflow using Terraform

Creates and deploys a sample workflow using Terraform.

Explore further

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

Code sample


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            = "sample-workflow"
  region          = "us-central1"
  description     = "A sample workflow"
  service_account =
  labels = {
    env = "test"
  user_env_vars = {
    url = ""
  source_contents = <<-EOF
  # This is a sample workflow that you can replace with your source code
  # The workflow does the following:
  # - Retrieves the current date from a public API and stores the
  #   response in `currentDate`
  # - Retrieves a list of Wikipedia articles from a public API related
  #   to the day of the week stored in `currentDate`
  # - Returns the list of articles in the workflow output
  # Note that when you define workflows in Terraform, variables must be
  # escaped with two dollar signs ($$) and not a single sign ($)

  - getCurrentDate:
      call: http.get
          url: $${sys.get_env("url")}
      result: currentDate
  - readWikipedia:
      call: http.get
              action: opensearch
              search: $${currentDate.body.dayOfWeek}
      result: wikiResult
  - returnOutput:
      return: $${wikiResult.body[1]}

  depends_on = [google_project_service.default]

What's next

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