Skip to content

How to debug Terraform errors

How-to · Updated May 2026
Before this

How to debug Terraform errors

Terraform errors fall into distinct categories that require different debugging approaches: configuration errors caught before any API call, provider errors from the OpenStack API, and state management issues. This guide covers the debugging workflow, common error patterns, and recovery procedures.

Debug output#

Enable verbose logging to see the full HTTP request/response cycle between Terraform and the OpenStack API.

Set the log level#

bash
export TF_LOG=DEBUG
terraform apply
LevelOutput
TRACEMaximum detail including provider internals
DEBUGHTTP requests, responses, and provider logic
INFOHigh-level operation flow
WARNWarnings only
ERRORErrors only

Write logs to a file#

bash
export TF_LOG=DEBUG
export TF_LOG_PATH=./terraform-debug.log
terraform apply

Review the log for the HTTP status code and response body from the OpenStack API. Search for HTTP/1.1 4 or HTTP/1.1 5 to find error responses.

Disable logging#

bash
unset TF_LOG
unset TF_LOG_PATH

Debugging workflow#

Follow this sequence when a Terraform operation fails.

1. Format and validate#

Catch syntax and configuration errors before they reach the API:

bash
terraform fmt -check -recursive
terraform validate

validate checks HCL syntax, required attributes, and type constraints. It does not contact the OpenStack API.

2. Plan#

bash
terraform plan -out=tfplan

Review the plan output for unexpected resource changes. If the plan itself fails, the error is an authentication failure (Authentication failed or Could not find Application Credential) or a provider-configuration failure (No suitable endpoint could be found in the service catalog).

3. Apply with targeted debugging#

If apply fails on a specific resource, isolate it:

bash
terraform apply -target=openstack_compute_instance_v2.web

Enable debug logging for the isolated apply to capture the exact API interaction.

4. Inspect state#

After a partial failure, check what Terraform recorded:

bash
terraform state list
terraform state show openstack_compute_instance_v2.web

Common OpenStack provider errors#

Error messageCauseFix
Error: Error creating OpenStack image client: Authentication failed (wrong OS_APPLICATION_CREDENTIAL_SECRET) or Error: ... Could not find Application Credential: <id> (HTTP 404, wrong or deleted OS_APPLICATION_CREDENTIAL_ID)The app credential secret is wrong, the credential ID is wrong, the credential was deleted, or the credential is scoped to a different projectVerify OS_AUTH_URL and the app-credential set (OS_AUTH_TYPE=v3applicationcredential, OS_APPLICATION_CREDENTIAL_ID, OS_APPLICATION_CREDENTIAL_SECRET). Re-source your openrc.sh from the generated openrc.sh.
Error: Error creating OpenStack image client: No suitable endpoint could be found in the service catalog.The configured OS_REGION_NAME does not exist in the service catalog, or the service is not enabled in that regionSet OS_REGION_NAME to a region that appears in openstack catalog list (for example, us-east-1).
Error: Error creating openstack_networking_floatingip_v2: Expected HTTP response code [201 202] when accessing [POST .../v2.0/floatingips], but got 409 instead {"NeutronError": {"type": "OverQuota", "message": "Quota exceeded for resources: ['public_ip']."}}Project floating-IP quota is exhaustedCheck quota: openstack quota show --usage. Release unused floating IPs (openstack floating ip delete) or request a quota increase.
Error: Your query returned no results. Please change your search criteria and try again.A data source (network, image, flavor) name does not match any resource in the projectRun openstack network list, openstack image list, openstack flavor list to verify the exact name, and confirm the data source's filters (for example, most_recent = true on Glance images).
"Quota exceeded" (403 or 413)Project quota is fullFree resources or request a quota increase. See quota troubleshooting.
"Conflict" (409)Resource is in a transitional stateWait and retry. The resource may be building, attaching, or being modified by another operation.
"Unauthorized" (401)Token expired during a long applyTokens have a limited lifetime. For long operations, use application credentials instead of token-based auth.
Error: ... Build of instance ... aborted: Failed to allocate the network(s), not rescheduling.The Compute API cannot auto-allocate a port on an external network (for example, PublicStatic)Attach to PublicEphemeral for direct attach, or for PublicStatic declare an explicit openstack_networking_port_v2 and pair it with openstack_networking_floatingip_v2 + openstack_networking_floatingip_associate_v2 (see the Simple VM template).

State lock recovery#

Terraform uses a lock to prevent concurrent modifications. If a Terraform process crashes or is interrupted, the lock may remain.

Symptoms#

Error: Error acquiring the state lock
Lock Info:
  ID:        12345678-abcd-...
  Path:      terraform.tfstate
  Operation: OperationTypeApply
  Who:       user@hostname
  Created:   2026-04-08 12:00:00 +0000 UTC

Resolution#

  1. Verify no other Terraform process is running against the same state.
  2. Force-unlock using the lock ID from the error message:
bash
terraform force-unlock 12345678-abcd-...

Plan/apply drift#

Drift occurs when resources are modified outside Terraform (via the console, CLI, or another automation tool).

Detecting drift#

bash
terraform plan

If the plan shows changes you did not make in your .tf files, resources have drifted. Terraform will report either an update-in-place or a forced replacement.

Resolving drift#

Option 1: Accept the external changes. Refresh state to match reality:

bash
terraform apply -refresh-only

Review the changes and approve. This updates Terraform's state without modifying infrastructure.

Option 2: Revert to Terraform's definition. Run a normal apply to push the .tf configuration back to the infrastructure:

bash
terraform apply

Import errors#

When importing existing resources into Terraform state:

bash
terraform import openstack_compute_instance_v2.web INSTANCE_ID

Common import failures#

ErrorCauseFix
Cannot import non-existent remote objectThe resource ID is wrong or the resource was deletedVerify with openstack server show INSTANCE_ID
Resource already managed by TerraformThe resource is already in stateCheck with terraform state list. Remove the duplicate with terraform state rm if appropriate.
Post-import plan shows changesThe .tf definition does not match the imported resource's actual configurationUpdate the .tf file to match the real resource, then run terraform plan until it shows no changes.

Provider-level retry configuration#

The OpenStack Terraform provider supports retry configuration for transient failures:

HCL
provider "openstack" {
  max_retries = 3
}

This retries on connection errors and 5xx responses. For more granular control over retry behavior, see Retry and resilience patterns.

See also#

Usage Guidelines

The sample code, software libraries, command line tools, proofs of concept, templates, and other related technology on this page (including any of the foregoing that is provided by Quake AI personnel) is provided to you as Quake AI Content under the Quake AI Customer Agreement, or the relevant written agreement between you and Quake AI (whichever applies). Do not use this Quake AI Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the Quake AI Content (such as sample code) as appropriate for production grade use based on your specific quality control practices and standards. Deploying Quake AI Content may incur Quake AI charges for creating or using Quake AI chargeable resources, such as running Compute instances or storing data in Object Storage. Your use is also subject to the Acceptable Use Policy.

For the full policy, see Usage Guidelines.

Last validated: 25.05.2026

Was this page helpful?