hashicorp/terraform · error

Attempted to find configured project %s but was unable to.

Error message

Attempted to find configured project %s but was unable to.

What it means

Returned in backend StateMgr at backend.go:756 when b.client.Projects.List fails with a non-ErrResourceNotFound error during project resolution for a configured project (project= or TF_CLOUD_PROJECT). Unlike 474, the raw API error is swallowed and only the generic message naming the project (%s) is reported. This blocks backend initialization for plan/apply.

Source

Thrown at internal/cloud/backend.go:756

	workspace, err := b.client.Workspaces.Read(context.Background(), b.Organization, name)
	if err != nil && err != tfe.ErrResourceNotFound {
		return nil, diags.Append(fmt.Errorf("Failed to retrieve workspace %s: %v", name, err))
	}
	if workspace != nil {
		remoteTFVersion = workspace.TerraformVersion
	}

	var configuredProject *tfe.Project

	// Attempt to find project if configured
	if b.WorkspaceMapping.Project != "" {
		listOpts := &tfe.ProjectListOptions{
			Name: b.WorkspaceMapping.Project,
		}
		projects, err := b.client.Projects.List(context.Background(), b.Organization, listOpts)
		if err != nil && err != tfe.ErrResourceNotFound {
			// This is a failure to make an API request, fail to initialize
			return nil, diags.Append(fmt.Errorf("Attempted to find configured project %s but was unable to.", b.WorkspaceMapping.Project))
		}
		for _, p := range projects.Items {
			if p.Name == b.WorkspaceMapping.Project {
				configuredProject = p
				break
			}
		}

		if configuredProject == nil {
			// We were able to read project, but were unable to find the configured project
			// This is not fatal as we may attempt to create the project if we need to create
			// the workspace
			log.Printf("[TRACE] cloud: Attempted to find configured project %s but was unable to.", b.WorkspaceMapping.Project)
		}
	}

	if err == tfe.ErrResourceNotFound {
		// Create workspace if it was not found

View on GitHub (pinned to c9def3e214)

Solutions

  1. Grant the token project-read permission in the organization.
  2. Retry on transient API failures; verify HCP/TFE health.
  3. Temporarily remove project scoping to confirm the token/org pair works, then re-add.

Example fix

// before
cloud { workspaces { project = "platform" name = "dev" } }

// after: confirm access first without project scoping
cloud { workspaces { name = "dev" } }
# re-add project once token has project-read
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm project-list permission before relying on it.
if _, err := b.client.Projects.List(ctx, org, &tfe.ProjectListOptions{Name: project}); err != nil && !errors.Is(err, tfe.ErrResourceNotFound) {
    return fmt.Errorf("token cannot list projects: %w", err)
}

Type guard

if errors.Is(err, tfe.ErrResourceNotFound) { /* tolerate */ } else { /* init failure */ }

Try / catch

projects, err := b.client.Projects.List(ctx, org, opts)
if err != nil && !errors.Is(err, tfe.ErrResourceNotFound) {
    return nil, fmt.Errorf("Attempted to find configured project %s but was unable to.", project)
}

Prevention

When it happens

Trigger: terraform plan/apply with a cloud backend that sets a project; the Projects.List lookup fails with a transport/permission/5xx error (404 is tolerated).

Common situations: Token lacks project-list permission; API outage; rate limiting; the configured project name is valid but the API is unreachable.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/672829ec8d5a53f8. Report an issue: GitHub.