terraform-state-identity-mismatch

Remove and re-import Terraform resources to fix identity mismatch errors.

5|Updated Feb 7, 2021
One-click install
npx skills add https://github.com/ViktorBarzin/infra --skill terraform-state-identity-mismatch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-state-identity-mismatch
Source: https://github.com/ViktorBarzin/infra/tree/main/.claude/skills/terraform-state-identity-mismatch
Command: npx skills add https://github.com/ViktorBarzin/infra --skill terraform-state-identity-mismatch

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Fix Terraform "Unexpected Identity Change" errors during plan/apply. Use when: (1) Terraform fails with "the Terraform Provider unexpectedly returned a different identity", (2) State refresh shows identity mismatch between stored and current values, (3) Resource was created but terraform apply timed out, leaving state inconsistent. Solution involves removing and reimporting the affected resource.

Core Features & Use Cases

  • Identify the affected resource from the error message.
  • Remove from state and re-import the resource back into Terraform state.
  • Verify with plan and apply to ensure drift is synchronized. Use Case: Kubernetes deployments where a timeout during deployment leaves state inconsistent.

Quick Start

Identify the affected resource from the error message, remove it from state, re-import the resource using the correct address, then run a targeted plan and apply to synchronize state.

Frequently Asked Questions about terraform-state-identity-mismatch

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Terraform unexpected identity change errors during plan or apply?

Fix Terraform unexpected identity change errors by removing the affected resource from state and re-importing it to restore correct identity mapping. Run a targeted plan and apply afterward to synchronize state drift.

Why does Terraform state refresh show an identity mismatch for Kubernetes resources?

Terraform state refresh shows identity mismatch when stored state values diverge from real Kubernetes resource identities, often caused by creation timeouts leaving state inconsistent. Remove and re-import the resource to resolve it.

What is the best way to resolve Terraform state drift after an apply timeout?

Resolving Terraform state drift after an apply timeout requires identifying the affected resource, removing it from state, and re-importing it using the correct address. Verify synchronization with a targeted plan and apply.

Can I re-import a Kubernetes resource into Terraform state without recreating it?

Yes, you can re-import an existing Kubernetes resource into Terraform state without recreating it by first removing the corrupted resource from state, then using terraform import with the correct address to reestablish mapping.

How do I identify which Terraform resource has an unexpected identity change?

Identify the Terraform resource with an unexpected identity change by parsing the error message returned during plan or apply. The message explicitly names the affected resource requiring state removal and re-import.

Does removing a Terraform resource from state delete the real Kubernetes deployment?

Removing a Terraform resource from state does not delete the real Kubernetes deployment. It only drops the state mapping, allowing you to re-import the existing resource to fix identity mismatch without physical destruction.