Is it possible to integrate Google Workspace tools such as Calendar, Sheets, and Forms with Workflows? For example, can you trigger a workflow from a Google Form or a Sheet? Turns out, this is not only possible but also easier than you might think. Let me show you how with a sample use case.
Use case
Imagine you are an administrator in charge of allocating virtual machines (VM) in your cloud infrastructure to users. You want to capture user requests with the specifications for the VMs, have an approval step for the request, and then create the VM with an automated process.
You can implement such a process as follows:
- A Google Form captures the VM creation requests.
- A Google Sheet saves the responses from the Google Form with an approved checkbox.
- When a human selects the Approved checkbox, an Apps Script calls a workflow in Google Cloud with the VM details from the form.
- The workflow calls the Compute Engine API to create the VM for the user in Google Cloud.
Let’s take a look at each step in more detail.
Create a Google Form
Create a Google Form to capture the VM creation request from users.
Go to Google Forms and create a new form similar to the following:
Make sure you have the Collect email addresses
option selected under settings.
You’ll need an email address when creating the VM later.
Create a Google Sheet
Create a Google Sheet to capture the responses from the form. Under the
Responses
tab, click the Create Spreadsheet
button.
This takes you to the spreadsheet with the responses. In this spreadsheet, add
an Approved
column with a checkbox:
This checkbox will be used to trigger a workflow to create the VM.
Create an Apps Script
Create an Apps Script to watch for the Approved
checkbox.
Go to Extensions
and Apps Script
in the spreadsheet. This opens up the Apps
Script editor. Replace the default code in Code.gs
with the code in
Code.gs.
Make sure you replace the PROJECT_ID
with your own project id. This code
watches for changes for the checkbox in the Approved
column. When the checkbox
is selected, it calls a workflow to create the VM.
In the Apps Script editor, go to Settings
and check Show appsscript.json manifest file
in editor. Replace the contents of appscript.json
with
appscript.json.
This makes sure that the Apps Script has the required permissions.
Go to the Triggers
section and create a trigger from the sheet to the Apps Script when the sheet is edited:
Create a workflow
Make sure you have a Google Cloud project and the project id is set in gcloud
:
PROJECT_ID=your-project-id
gcloud config set project $PROJECT_ID
Run setup.sh to enable required services, grant necessary roles, and deploy the workflow defined in workflow.yaml. This workflow creates a Compute Engine VM with the supplied specifications.
Try it out
You’re now ready to test the end-to-end process.
Go back to the sheet and select the Approved
checkbox for the entry created
earlier:
In the Apps Script console, you can see a new execution:
In the Workflows console, you can also see a new execution:
And finally, in the Compute Engine console, you can see that a new VM is being created:
From now on, whenever a user fills the form, you’ll see a new entry to the Google Sheet. When you approve it by selecting the Approved checkbox, the VM will be created automatically by Workflows!
This is just one example of how to integrate Google Workspace with Workflows. If you have questions or feedback, feel free to reach out to me on Twitter @meteatamel. Thanks to our summer interns Cheran Mahalingam and Michael Yang, who validated the pattern and created the initial sample.