Introduction
This article provides a solution for the "resource not found" error encountered when using the TFE provider to manage projects and workspaces in HCP Terraform.
Problem
When attempting to create a workspace in HCP Terraform (TFC) using Terraform code, the following error may occur:
"Error: Error creating workspace ABC for organization ABC-Org: resource not found".
resource "tfe_workspace" "tfc_abc_workspace" {
Prerequisites (if applicable)
- Basic understanding of HCP Terraform and TFE provider.
- Access to the TFC token used in the Terraform code.
Cause
The root cause of this error is typically associated with the TFC token used in the Terraform code. If the token is invalid or lacks the necessary permissions, it may result in a "resource not found" error.
Solutions:
It is possible to validate the TFC token by using the API and the same TFC token to perform the same action being done through the TFE provider. If the token is failing through the API as well, then the recommended solution is to reissue and re-upload the token. This is because when an invalid token is used with the TFE provider, it often results in "resource not found" errors instead of "permission denied" errors for security reasons.
Outcome
After reissuing and re-uploading the token, the "resource not found" error should no longer occur when creating a workspace in TFC using Terraform code.
Additional Information
-
Create a Workspace API documentation: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces#create-a-workspace