Problem
When using the tfe_provider to manage resources in Terraform Enterprise or HCP Terraform, a previously applied workspace may unexpectedly report that new resources need to be created. This can occur even when the resources were successfully applied and exist in the state file.
You may see an error message similar to the following.
Error: Error refreshing workspace tfe-test for organization hashicorp: resource not found
on main.tf line 1, in resource "tfe_workspace" "tfe-test":
4: resource "tfe_workspace" "tfe-test" {Prerequisites
- You are using the TFE Provider.
- You are authenticating with a User, Team, or Organization Token.
Cause
Terraform attempts to recreate these objects because the API token used by the tfe_provider is no longer valid or does not have the required permissions for the target resources.
Solutions
Solution 1: Validate the API Token
Ensure that the API token you are using is still valid and has the correct permissions to manage the resources in the target organization and workspace.
Solution 2: Create a New API Token
If the token is invalid or its permissions are insufficient, create a new API token with the appropriate scope and update your Terraform configuration to use it.
Outcome
After you update the configuration with a valid API token, Terraform runs should complete successfully without attempting to recreate existing resources.