When creating a workspace via 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, however, all required variables are present with values. Additionally, manually queuing a run works as expected after the initial failure.
- Terraform ServiceNow Service Catalog integration <= v2.3.0
There is a race condition in this flow which is caused by the “queue all runs” workspace setting. The Terraform ServiceNow Service Catalog integration uses the Terraform Cloud API to create a workspace with the queue-all-runs value set to true, which indicates that Terraform Cloud should start a run as soon as the workspace is created. Workspaces variables are added to the workspace in a separate API call (one for each variable) after the workspace is created. As a result, they are not be available on the workspace at the time of the first run triggered by the queue all runs settings.
Note: Workspaces can be created successfully through this flow if their are no required variables in the Terraform configuration.
To resolve this, unselect the “queue all runs” option in the Provision Resources With Vars Flow flow, allowing the workspace to be created without automatically triggering a first run. A second action can be added to the flow to trigger a run on the workspace to retain this functionality. Separating the flow into two actions will allow the workspace to be fully created and the variables added before the first run is triggered, resolving the race condition error.