{"record":{"id":"be65d465291d699a","repo":"hashicorp/terraform","slug":"module-q-was-not-found-please-ensure-that-the-o","errorCode":null,"errorMessage":"module %q was not found.\n\nPlease ensure that the organization and hostname are correct and that your API token for %s is valid.","messagePattern":"module %q was not found\\.\n\nPlease ensure that the organization and hostname are correct and that your API token for (.+?) is valid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/test.go","lineNumber":416,"sourceCode":"\n\t\tif client, err = tfe.NewClient(cfg); err != nil {\n\t\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\t\ttfdiags.Error,\n\t\t\t\t\"Failed to create the HCP Terraform or Terraform Enterprise client\",\n\t\t\t\tfmt.Sprintf(\n\t\t\t\t\t`Encountered an unexpected error while creating the `+\n\t\t\t\t\t\t`HCP Terraform or Terraform Enterprise client: %s.`, err,\n\t\t\t\t),\n\t\t\t))\n\t\t\treturn nil, nil, diags\n\t\t}\n\t}\n\n\tmodule, err := client.RegistryModules.Read(runner.StoppedCtx, id)\n\tif err != nil {\n\t\t// Then the module doesn't exist, and we can't run tests against it.\n\t\tif err == tfe.ErrResourceNotFound {\n\t\t\terr = fmt.Errorf(\"module %q was not found.\\n\\nPlease ensure that the organization and hostname are correct and that your API token for %s is valid.\", addr.ForDisplay(), addr.Package.Host.ForDisplay())\n\t\t}\n\t\tdiags = diags.Append(tfdiags.AttributeValue(\n\t\t\ttfdiags.Error,\n\t\t\tfmt.Sprintf(\"Failed to read module %q\", addr.ForDisplay()),\n\t\t\tfmt.Sprintf(\"Encountered an unexpected error while the module: %s\", err),\n\t\t\tcty.Path{cty.GetAttrStep{Name: \"source\"}}))\n\t\treturn client, nil, diags\n\t}\n\n\t// Enable retries for server errors.\n\tclient.RetryServerErrors(true)\n\n\trunner.appName = client.AppName()\n\tif isValidAppName(runner.appName) {\n\t\trunner.appName = \"HCP Terraform\"\n\t}\n\n\t// Aaaaand I'm done.","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/test.go#L398-L434","documentation":"terraform test reads the private-registry module via RegistryModules.Read; a 404 is wrapped as 'module not found'. Because HCP/TFE returns 404 both for non-existent modules and for ones the token cannot access, this can also indicate an auth/permission problem.","triggerScenarios":"Module address is wrong (org/namespace/name/provider mismatch), the module is not published to the private registry, or the API token lacks read access to that module.","commonSituations":"Typo in the module source, module not yet published/uploaded, token for the wrong organization, or token without private-registry read scope.","solutions":["Confirm the module is published in the private registry under the exact org/namespace/name/provider.","Verify the API token is valid and scoped to that organization.","Re-check the hostname in the source address.","Run terraform login <hostname> to refresh the token."],"exampleFix":"# before: module not published / wrong org -> module \"...\" was not found\n# after: publish the module to the private registry and confirm token scope\nterraform login app.terraform.io\nterraform test","handlingStrategy":"validation","validationCode":"// Pre-flight: confirm the module exists in the private registry\nif _, err := client.RegistryModules.Read(ctx, id); err != nil {\n    if errors.Is(err, tfe.ErrResourceNotFound) {\n        return fmt.Errorf(\"module not found or token lacks access: %s\", addr.ForDisplay())\n    }\n    return err\n}","typeGuard":"func isModuleNotFound(err error) bool {\n    return errors.Is(err, tfe.ErrResourceNotFound)\n}","tryCatchPattern":"module, err := client.RegistryModules.Read(ctx, id)\nif err != nil {\n    if errors.Is(err, tfe.ErrResourceNotFound) {\n        // could be missing OR unauthorized (404 hides both); verify token scope and publishing\n    }\n}","preventionTips":["Publish the module to the private registry under the exact org/namespace/name/provider","Use a token scoped to the right organization","Run terraform login <hostname> to refresh credentials"],"tags":["module-registry","auth","not-found","test-runner"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}