Problem
Runs triggered via CLI, API or UI fail with error: Invalid run parameters: Configuration version is still being processed
Prerequisites
- Terraform Enterprise
Cause
- Terraform code fails to be uploaded to the Terraform Enterprise application, leaving the configuration version in pending status
Solutions:
- Solution #1 Create a new configuration version via the API (Remember to backup the state first)
# Create payload.json ex:
{
"data": {
"type": "configuration-versions",
"attributes": {
"auto-queue-runs": true
}
}
}
# Create a Configuration Version.
# Replace the workspace ID and app.terraform.io with your Terraform Enterprise hostname
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data @payload.json \
https://app.terraform.io/api/v2/workspaces/ws-2Qhk7LHgbMrm3grF/configuration-versions
# Pay attention to the upload URL provided in the response of the API call above as it will be required to complete the next step
# @filename refers to the code being uploaded, ex main.tf or tfcode.tar.gz (containing your terraform code)
curl \
--header "Content-Type: application/octet-stream" \
--request PUT \
--data-binary @filename \
https://archivist.terraform.io/v1/object/4c44d964-eba7-4dd5-ad29-1ece7b99e8da
# Verify the configuration version status is now uploaded before triggering a new run
# Replace the hostname and configuration version ID
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
--request GET \
https://app.terraform.io/api/v2/configuration-versions/cv-ntv3HbhJqvFzamy7 - Solution #2 Delete the configuration versions stuck in pending status via Rails
# SSH to your Terraform Enterprise instance and launch the rails console.
# For TFE releases prior 619(v202205-1)replace tfe-atlas for ptfe_atlas
sudo docker exec -it tfe-atlas /usr/bin/init.sh /app/scripts/wait-for-token -- bash -ic 'cd /app && ./bin/rails c'
# Run the following commands in the Rails Console
# Replace CHANGEME with the workspace ID
ws = Workspace.find_by(external_id: "CHANGEME")
# Store in cvs all configuration versions in pending status
cvs = ws.configuration_versions.where(status: "pending")
# Mark configuration versions for deletion
cvs.each do |cv|
cv.destroy!
# Save
end
# Exit the Rails Console
exit
Outcome
By use of the API is possible to confirm the configuration version state shows uploaded and subsequent runs via API and UI are successful.