Skip to content

Core: Add hint for resource conflict errors (EntityAlreadyExists)#38038

Closed
KyungHwanKim-devs wants to merge 3 commits intohashicorp:mainfrom
KyungHwanKim-devs:fix-24704-hint-conflict
Closed

Core: Add hint for resource conflict errors (EntityAlreadyExists)#38038
KyungHwanKim-devs wants to merge 3 commits intohashicorp:mainfrom
KyungHwanKim-devs:fix-24704-hint-conflict

Conversation

@KyungHwanKim-devs
Copy link

@KyungHwanKim-devs KyungHwanKim-devs commented Jan 4, 2026

Refs #24704

Summary

  • Keep the existing diagnostic hint for resource conflict errors, but make it more precise and less noisy.
  • Tighten the match to only already exists/EntityAlreadyExists so unrelated duplicate errors do not get a misleading hint.
  • Expand the hint message to cover both common root causes: missing moved blocks during refactors and provider-side asynchronous deletes/eventual consistency.
  • Update tests and the changelog entry to match the refined behavior and wording.

Rationale / Background

This issue has two recurring causes:

  1. A refactor (rename or module move) where Terraform sees the old and new addresses as different resources. Without moved blocks, Terraform plans a destroy+create and may attempt the create before the old object is fully gone.
  2. Provider-side delete operations that return before the object is fully removed (eventual consistency), which can surface as already exists errors on replacement.

The hint should steer users toward the correct fix without over-triggering on unrelated errors. This change keeps the hint but narrows the match to explicit already exists signals and clarifies the two likely root causes in the message.

User-facing Behavior

No behavior change to planning or apply execution. A warning hint is appended only when an error explicitly indicates the object already exists.

Testing

  • go test ./internal/terraform -run TestHintIfAlreadyExists

Target Release

1.15.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

No. This only adjusts diagnostic messaging.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@KyungHwanKim-devs KyungHwanKim-devs requested a review from a team as a code owner January 4, 2026 11:17
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Jan 4, 2026

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


Gemini Agent seems not to be a GitHub user.
You need a GitHub account to be able to sign the CLA.
If you have already a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

Some provider errors indicate that a resource already exists during a replacement. This commonly happens when a resource is renamed or moved without a moved block; Terraform sees the old and new addresses as distinct and may attempt the create before the old object is fully gone. Add a diagnostic hint for explicit already exists signals to recommend moved blocks or terraform state mv.

Refs hashicorp#24704

Signed-off-by: KyungHwanKim-devs <kkhdevs@gmail.com>
Signed-off-by: KyungHwanKim-devs <kkhdevs@gmail.com>
Signed-off-by: KyungHwanKim-devs <kkhdevs@gmail.com>
@KyungHwanKim-devs
Copy link
Author

Hi @radeksimko , CI checks are passing and CLA is signed. Could someone from the team review this when you have a chance? Happy to address any feedback. Thanks!

@crw
Copy link
Contributor

crw commented Jan 22, 2026

Hi @KyungHwanKim-devs, this PR looks OK to review, the one comment from triage was:

The only thing that I’d want is another core maintainer's opinion on is whether we want to always prioritize the current non-configDirXDG path if both are present. The PR favors the XDG path over the current implementation.

I will raise this again in triage to see if we can prioritize reviewing this submission. Thanks!

@crw
Copy link
Contributor

crw commented Jan 27, 2026

Hi @KyungHwanKim-devs, the feedback from triage is that this error covers one possibility that could cause this error, but may be misleading to users for other ways in which this error could be triggered. So this could be helpful for the right user, but send other users with this issue down the wrong track. For that reason, we are going to decline accepting this PR. Feel free to follow up if you believe there is a better way to target this hint.

@crw crw closed this Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants