terraform runtime_error ai_generated true

Error: Provider produced inconsistent result after apply: After applying!terraform!plan, the provider returned a value for "instance_type" that was not in the plan: "t2.micro" -> "t3.micro"

ID: terraform/provider-inconsistent-result-after-apply

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2023-10-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform v1.5 active
Terraform v1.6 active
AWS Provider v5.0 active
AWS Provider v4.67 active

Root Cause

The provider modified a resource attribute during creation/update that Terraform did not expect, often due to AWS defaulting or auto-converting instance types (e.g., t2.micro to t3.micro in certain regions).

generic

中文

Provider 在创建/更新期间修改了 Terraform 未预期的资源属性,通常是由于 AWS 默认或自动转换实例类型(例如在某些区域 t2.micro 变为 t3.micro)。

Official Documentation

https://developer.hashicorp.com/terraform/language/resources/behavior#inconsistent-results

Workarounds

  1. 85% success Update the configuration to explicitly set the attribute to the value the provider expects. For example, change 'instance_type = "t2.micro"' to 'instance_type = "t3.micro"' in the resource block, then run 'terraform apply' again.
    Update the configuration to explicitly set the attribute to the value the provider expects. For example, change 'instance_type = "t2.micro"' to 'instance_type = "t3.micro"' in the resource block, then run 'terraform apply' again.
  2. 70% success If the attribute is not critical, use lifecycle.ignore_changes with caution. Add 'lifecycle { ignore_changes = [instance_type] }' to the resource, then run 'terraform apply' to accept the current state. Example: resource "aws_instance" "example" { ami = "ami-abc123" instance_type = "t2.micro" lifecycle { ignore_changes = [instance_type] } }
    If the attribute is not critical, use lifecycle.ignore_changes with caution. Add 'lifecycle { ignore_changes = [instance_type] }' to the resource, then run 'terraform apply' to accept the current state. Example: resource "aws_instance" "example" { ami = "ami-abc123" instance_type = "t2.micro" lifecycle { ignore_changes = [instance_type] } }

中文步骤

  1. Update the configuration to explicitly set the attribute to the value the provider expects. For example, change 'instance_type = "t2.micro"' to 'instance_type = "t3.micro"' in the resource block, then run 'terraform apply' again.
  2. If the attribute is not critical, use lifecycle.ignore_changes with caution. Add 'lifecycle { ignore_changes = [instance_type] }' to the resource, then run 'terraform apply' to accept the current state. Example: resource "aws_instance" "example" { ami = "ami-abc123" instance_type = "t2.micro" lifecycle { ignore_changes = [instance_type] } }

Dead Ends

Common approaches that don't work:

  1. 95% fail

    State files should not be manually edited; it can cause drift, corruption, and is not idempotent. Terraform will detect the edit and may error on next plan.

  2. 60% fail

    This prevents Terraform from detecting future changes to instance_type, masking the issue and allowing drift to go unnoticed.

  3. 70% fail

    Older providers may have the same issue or other bugs; it also prevents using new features and security fixes.