Problem
When you create a workspace using the Terraform ServiceNow Service Catalog integration's Provision Resources With Vars Flow, the workspace’s first run fails with an error indicating that the required variables are not populated.
The root module input variable "[VARIABLE NAME]" is not set, and has no default value. Use a -var or -var-file command line argument to provide a value for this variable. Error: No value for required variable
On the workspace’s variables page, all required variables are present with their assigned values. Manually queuing a run after the initial failure works as expected.
Prerequisites
- Terraform ServiceNow Service Catalog integration version 2.3.0 or earlier.
Cause
This issue is caused by a race condition related to the “queue all runs” workspace setting. The integration uses the HCP Terraform API to create a workspace with the queue-all-runs value set to true, which instructs HCP Terraform to start a run as soon as the workspace is created.
However, the integration adds workspace variables in separate API calls after the workspace is created. As a result, the variables are not available on the workspace when the first run is automatically triggered, causing the run to fail.
Note: Workspaces can be created successfully through this flow if there are no required variables in the Terraform configuration.
Solution
To resolve the race condition, modify the Provision Resources With Vars Flow to separate workspace creation from the initial run. This ensures all variables are populated before the first run begins.
- Disable Automatic Runs: In the flow action that creates the workspace, unselect the queue all runs option. This allows the workspace to be created without automatically triggering a run.
- Add a Run Trigger Action: Add a second, subsequent action to the flow that explicitly triggers a run on the newly created workspace.
This two-step process ensures that the workspace and its variables are fully configured before the first plan and apply is initiated.