Skip to main content
DevOps Insightsguides & answers

Terraform · intermediate

Provider Produced Inconsistent Result After Apply, Explained

Short answer

Terraform held the provider, the plugin that talks to the cloud API for it, to its plan, and the provider broke it: a value came back different from what it promised. The last line of the error names the attribute and shows both values. Usually the cloud API rewrote what you sent, so write it the way the API returns it, or upgrade the provider. If the resource was being created, it is now tainted, marked for replacement. Fix the cause, then, if the real object is fine, untaint it rather than letting the next apply replace it.

N
Neeraj Jha
3 min read
On this page · 3 sections
Diagram of How one lowercase letter fails an apply: 1. Plan, 2. Apply, 3. Provider returns, 4. Terraform compares, 5. Error, object tainted.

What Terraform is checking

Terraform plans, then applies, and only values shown as (known after apply) are allowed to change between the two. Everything you could see in the plan must come back exactly as planned. When it does not, you get this:

text
Error: Provider produced inconsistent result after apply

When applying changes to aws_example.this, provider
"registry.terraform.io/hashicorp/aws" produced an unexpected
new value: .name: was cty.StringVal("MyName"), but now
cty.StringVal("myname").

That was … but now … detail is the whole diagnosis. If the two values differ only in case, order, spacing or JSON formatting, the API normalised your input.

How one lowercase letter fails an apply

1. Plan. The provider promises name = "MyName", taken from your configuration.

1 / 5

Fix it in this order

  1. Match the value the API returns. Use the exact case and order from the but now value. For policies and other JSON documents, build them with jsonencode() rather than a hand-formatted string.
  2. Upgrade the provider with terraform init -upgrade. These mismatches get fixed resource by resource. If the error started right after an upgrade, pin the last version that worked instead.
  3. Deal with the tainted resource. On a failed create, Terraform still saves the object, marked tainted, so the next plan says it "is tainted, so must be replaced". If the real object is fine, keep it:
bash
terraform untaint 'aws_example.this'
terraform plan

The plan should now show no replacement. For a database, read that plan carefully before applying anything: a replacement would destroy the existing one.

Why newer resources hit it more

For resources built on the older plugin SDK, Terraform only writes a warning to the log for the same mismatch. Resources built on the newer plugin framework get the error. So a brand-new resource type is where you are most likely to see it.

The full page, with a decision tree, is Provider produced inconsistent result after apply. Its close relative, an identity error after a provider upgrade, is covered on the resource identity page.

Tagged with

Enjoyed this article?

Get more DevOps insights delivered to your inbox.

Get new posts by email

Subscribe to get an email when a new blog post is published. Skip anytime.

No spam, unsubscribe anytime.

N

Written by

Neeraj Jha

Platform administrator and lead writer.

View all posts →

Discussion

0 comments

Sign in to join the conversation.

Be the first to comment

Start a conversation about this post

Share: