When creating a workspace in Terraform using the ServiceNow (SNOW) integration, the workspace’s first run fails with an error that the required fields are not populated. On the workspace’s variables page, however, all of the fields are all populated and manually queuing a run works as expected after the initial failure.
The error seen in the Terraform run log looks like this:
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
There is a race condition that causes this failure in the Terraform/SNOW integration involving “queue all runs”. The SNOW integration uses Terraform Enterprise’s API to create a workspace with the queue-all-runs value set to true, which indicates that Terraform Enterprise should start a run as soon as the workspace is created. When variables are added to a workspace using the SNOW workflow, this happens as a separate API call (one for each variable), and happens after the workspace is created, meaning that they would not be available on the workspace at the time of the first run if “queue all runs” is enabled.
Workspaces can be created successfully through this integration if there are not required variables. When required variables are involved, the error occurs.
The solution to this is to unselect the “queue all runs” option in SNOW, allowing the workspace to be created without automatically triggering a first run. A second action can then be added to the workflow in SNOW to trigger a run on the workspace. Separating the workflow into two actions allows the workspace to be fully created and the variables added before the first run is triggered, resolving the race condition error.