Create and update a workflow

Stay organized with collections Save and categorize content based on your preferences.

This page shows you how to create a workflow and update an existing workflow in the Google Cloud console or by using the Google Cloud CLI.

Before you begin

Some of the steps in this document might not work correctly if your organization applies constraints to your Google Cloud environment. In that case, you might not be able to complete tasks like creating public IP addresses or service account keys. If you make a request that returns an error about constraints, see how to Develop applications in a constrained Google Cloud environment.

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  6. Enable the Workflows API.

    Enable the Workflows API

Create a service account

Create a service account if you don't already have one; then grant it the roles necessary for managing workflows and creating logs. Learn more about creating and managing service accounts.

Note that to create a resource and attach a service account, you need permissions to create that resource and to impersonate the service account that you will attach to the resource. For more information, see Service account permissions.

Console

  1. In the Google Cloud console, go to the Service Accounts page.

    Go to Service Accounts

  2. Select a project and then click Create service account.

  3. In the Service account name field, enter a name.

    The name must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. After you create a service account, you cannot change its name.

  4. Click Create and continue.

  5. Click Select a role.

  6. Select the following roles, clicking Add another role as required:

    • To create, update, and execute workflows, select Workflows > Workflows Editor.
    • To send logs to Cloud Logging, select Logging > Logs Writer.
  7. Click Done to finish creating the service account.

gcloud

  1. Create the service account.

    gcloud iam service-accounts create NAME
  2. Grant permissions to the service account by assigning a role.

    gcloud projects add-iam-policy-binding PROJECT_ID \
       --member "serviceAccount:NAME@PROJECT_ID.iam.gserviceaccount.com" \
       --role "roles/logging.logWriter"
    

    Replace the following:

    • NAME: the name of the service account. It must be between 6 and 30 characters, and can contain lowercase alphanumeric characters and dashes. After you create a service account, you cannot change its name.
    • PROJECT_ID: your project's ID.

    The --role flag is used to authorizes your service account to access resources.

Create a workflow

A workflow definition is made up of a series of steps described using the Workflows syntax, which can be written in either YAML or JSON format. After creating a workflow, you deploy it to make it available for execution. The deploy step also validates that the source file can be executed. It fails if the source file doesn't contain a valid workflow definition.

Console

  1. In the Google Cloud console, go to the Workflows page.

    Go to Workflows

  2. Click Create.

  3. Enter a name for the new workflow, such as myFirstWorkflow. The name can contain letters, numbers, underscores, and hyphens. It must start with a letter and end with a number or letter.

  4. In the Region list, select an appropriate region; for example, us-central1.

  5. In the Service account list, select a service account for your workflow to use for authentication with other Google Cloud services.

    We strongly recommend using a service account with the least privileges necessary to access the required resources.

  6. Optionally, do any of the following:

    1. Add a label: labels are key-value pairs that help you organize your Google Cloud instances. For more information, see Create and manage labels.

    2. Schedule your workflow: select Add new trigger > Cloud Scheduler. For more information, see Schedule a workflow using Cloud Scheduler.

    3. Trigger your workflow through an event or Pub/Sub message: select Add new trigger > Eventarc. For more information, see Trigger a workflow with events or Pub/Sub messages.

  7. Click Next.

  8. In the workflow editor, enter the definition for your workflow. See an example workflow.

  9. Click Deploy.

gcloud

  1. Make sure your workflow's source code is saved in a YAML or JSON file, such as MY_WORKFLOW.YAML or MY_WORKFLOW.JSON. See an example workflow.

  2. Open a terminal.

  3. Deploy the workflow by entering the following command:

    gcloud workflows deploy MY_WORKFLOW \
       --source=YAML_OR_JSON_SOURCE_FILE \
       --service-account=MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM
    

    Replace the following:

    • MY_WORKFLOW: the name of your workflow.

    • YAML_OR_JSON_SOURCE_FILE: the source file to use for the workflow. For example: myFirstWorkflow.yaml.

    • MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM: optional. The service account your workflow will use to access other Google Cloud services. We strongly recommend using a service account with the least privileges necessary to access the required resources. If left blank, the default service account is used.

Update a workflow

You can update an existing workflow to change its source, description, labels, triggers, or its associated service account. Updating a workflow does not affect in-progress executions. Only future executions of the workflow will use the updated configuration.

Console

  1. In the Google Cloud console, go to the Workflows page.

    Go to Workflows

  2. Click the name of the workflow you want to update and then click Edit.

  3. On the Edit workflow page, you can edit the description, update the service account the workflow uses for authentication, or add or update a label or trigger. You cannot edit the workflow's name.

  4. When you have completed your initial updates, click Next.

  5. In the workflow editor, you can update the workflow's source code.

  6. Click Deploy.

gcloud

  1. Open a terminal.

  2. Find the name of the workflow you want to update. If you don't know the workflow's name, you can enter the following command to list all your workflows:

    gcloud workflows list
    
  3. Locate the YAML or JSON file where your workflow source is saved, such as WORKFLOW_NAME.YAML or WORKFLOW_NAME.JSON.

  4. You can update a workflow's source, associated service account, description, or labels:

    gcloud workflows deploy WORKFLOW_NAME \
       --source=YAML_OR_JSON_SOURCE_FILE \
       --service-account=MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM \
       --labels=KEY=VALUE... \
       --description='WORKFLOW_DESCRIPTION'
    

    Replace the following:

    • WORKFLOW_NAME: required. The name of your workflow.

    • YAML_OR_JSON_SOURCE_FILE: required. The source file for the workflow in either YAML or JSON format. For example: myFirstWorkflow.yaml.

    • MY_SERVICE_ACCOUNT@MY_PROJECT.IAM.GSERVICEACCOUNT.COM: optional. The service account your workflow will use to access other Google Cloud services. To learn more about service accounts, see Create and manage service accounts.

    • KEY=VALUE: optional. KEY=VALUE pairs of labels, in a comma-separated list if you add more than one. Labels help you organize your Google Cloud instances. For more information, see Create and manage labels.

    • WORKFLOW_DESCRIPTION: optional. The description you want to give your workflow.

    You must specify the name of the workflow you want to update and its source; however, the rest of the flags are optional.

Each time you update a workflow, its versionID is updated. The versionID consists of two parts, separated by a hyphen:

  • A number, starting at one, that is incremented each time you update a workflow.

  • A random, three-character, alphanumeric string.

For example, 000002-d52 indicates a workflow that has been updated once. 000001-27f indicates a workflow that is on its initial version.

What's next