Introduction
When managing infrastructure with Terraform, you may encounter an error indicating that a provider produced an inconsistent result after an apply operation. This typically happens when a resource that was just created or updated cannot be found by Terraform during the final state refresh.
Problem
After a terraform apply, Terraform may report the following error, indicating that a resource it expected to be present was absent during the final read operation.
Error: Provider produced inconsistent result after apply When applying changes to aws_network_acl_rule.this, provider "registry.terraform.io/hashicorp/aws" produced an unexpected new value: Root resource was present, but now absent.
Cause
This error is often caused by a race condition related to eventual consistency in the remote service (like AWS, Azure, or GCP). When Terraform creates or updates a resource, the service API may report success before the resource is fully propagated and available to be read back. If Terraform's final read operation occurs during this brief interval, it fails to find the resource, leading to the "inconsistent result" error.
While some Terraform provider resources have built-in retry logic to handle this, not all do.
Solutions
The long-term solution is to report this behavior to the provider maintainers by opening an issue on their GitHub repository. This allows them to implement the necessary retry logic for the affected resource.
In the short term, you can use one of the following workarounds to align your Terraform state with the actual infrastructure.
Solution 1: Import the Existing Resource
If the resource was successfully created in the remote service but is missing from the Terraform state, you can import it. This updates the state file to match the real-world resource without needing to recreate it.
- Confirm the resource exists in the provider's console or via its CLI.
- Use the
terraform importcommand to bring the resource into your state. - Run
terraform planto confirm that Terraform now recognizes the resource and no further changes are needed.
Solution 2: Recreate the Resource
If the affected resource is not critical and can be safely recreated, you can manually delete it from the remote service and run the apply operation again.
- Delete the resource manually using the provider's console or CLI.
- Run
terraform applyagain. Terraform will detect that the resource is missing and recreate it.