IBM Support

Resolving Resource Drift Due to Missing State Entry in Terraform Cloud

Troubleshooting


Problem

Issue and Impact

During a Terraform run, an attempt was made to create a resource that already existed in the infrastructure. This results in a drift between the actual infrastructure and the Terraform state file, leading to unnecessary planned changes.

 

Cause

Upon investigation, it can be identified that the particular resource could be missing from the latest Terraform state file.

  • A previous Terraform run could have failed unexpectedly with a 409 Conflict error.

  • During that run, the resource in question was marked for deletion and then recreation.

  • The intermediate state where the resource could be "deleted"or uploaded to the workspace.

  • However, the final state file (after the resource was recreated) was never uploaded due to the failed run.

  • As a result, the resource no longer appears in the current state, though it still exists in the actual infrastructure.

  • To verify the state file resources, you can download the state file from HCP workspace and try to find out the particular resource .

Solution 

  • The missing resource can be re-imported into the workspace using Terraform’s import functionality.

  • A subsequent terraform plan confirms that there is no changes, indicating the state is aligned with the real infrastructure.

  • The import block can then be removed from the code to maintain consistency across multiple workspaces.

 

More helpful information 

Here are some useful resources to better understand state handling and recovery in Terraform:

Importing Resources into Terraform State:

Recovering State from Failed Apply:

Removing Resources from State:

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB77","label":"Automation Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSTYDYO","label":"IBM Terraform"},"ARM Category":[{"code":"a8mgJ0000000DmuQAE","label":"Terraform-\u003EDrift Detection"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":""}]

Historical Number

40515024670227

Document Information

Modified date:
05 June 2026

UID

ibm17263938