{"record":{"id":"11b927aa90dfc86c","repo":"hashicorp/terraform","slug":"failed-to-create-project-s-v","errorCode":null,"errorMessage":"failed to create project %s: %v","messagePattern":"failed to create project (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend.go","lineNumber":799,"sourceCode":"\n\t\tif b.WorkspaceMapping.Strategy() == WorkspaceTagsStrategy {\n\t\t\tworkspaceCreateOptions.Tags = b.WorkspaceMapping.tfeTags()\n\t\t} else if b.WorkspaceMapping.Strategy() == WorkspaceKVTagsStrategy {\n\t\t\tworkspaceCreateOptions.TagBindings = b.WorkspaceMapping.asTFETagBindings()\n\t\t}\n\n\t\t// Create project if not exists, otherwise use it\n\t\tif workspaceCreateOptions.Project == nil && b.WorkspaceMapping.Project != \"\" {\n\t\t\t// If we didn't find the project, try to create it\n\t\t\tif workspaceCreateOptions.Project == nil {\n\t\t\t\tcreateOpts := tfe.ProjectCreateOptions{\n\t\t\t\t\tName: b.WorkspaceMapping.Project,\n\t\t\t\t}\n\t\t\t\t// didn't find project, create it instead\n\t\t\t\tlog.Printf(\"[TRACE] cloud: Creating %s project %s/%s\", b.appName, b.Organization, b.WorkspaceMapping.Project)\n\t\t\t\tproject, err := b.client.Projects.Create(context.Background(), b.Organization, createOpts)\n\t\t\t\tif err != nil && err != tfe.ErrResourceNotFound {\n\t\t\t\t\treturn nil, diags.Append(fmt.Errorf(\"failed to create project %s: %v\", b.WorkspaceMapping.Project, err))\n\t\t\t\t}\n\t\t\t\tconfiguredProject = project\n\t\t\t\tworkspaceCreateOptions.Project = configuredProject\n\t\t\t}\n\t\t}\n\n\t\t// Create a workspace\n\t\tlog.Printf(\"[TRACE] cloud: Creating %s workspace %s/%s\", b.appName, b.Organization, name)\n\t\tworkspace, err = b.client.Workspaces.Create(context.Background(), b.Organization, workspaceCreateOptions)\n\t\tif err != nil {\n\t\t\treturn nil, diags.Append(fmt.Errorf(\"error creating workspace %s: %v\", name, err))\n\t\t}\n\n\t\tremoteTFVersion = workspace.TerraformVersion\n\n\t\t// Attempt to set the new workspace to use this version of Terraform. This\n\t\t// can fail if there's no enabled tool_version whose name matches our\n\t\t// version string, but that's expected sometimes -- just warn and continue.","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend.go#L781-L817","documentation":"Returned in backend StateMgr at backend.go:799 when b.client.Projects.Create returns a non-ErrResourceNotFound error while creating a project that did not exist, in order to host a new workspace. This path runs during workspace auto-creation (plan/apply) when the configured project is absent and the backend attempts to create it. %s=project name, %v=API error.","triggerScenarios":"terraform plan/apply with a cloud backend referencing a project that does not yet exist and workspaces that must be auto-created; Projects.Create fails (typically 401/403/409 conflict or 5xx).","commonSituations":"Token lacks project-create (admin) permission; a project of the same name already exists in a deleted state causing conflict; org billing limits on project count; API outage during create.","solutions":["Pre-create the project in the HCP/TFE UI so auto-create is not required.","Grant the token admin/project-create permission, or run with a token that has it.","Resolve 409 conflicts by renaming or restoring the existing project."],"exampleFix":"// before: token cannot create projects, backend tries to auto-create\ncloud { workspaces { project = \"platform\" name = \"new-ws\" } }\n\n// after: pre-create project in UI, or use an admin token\ncloud { workspaces { project = \"platform\" name = \"new-ws\" } }\n# ensure token has 'Manage Projects' (admin) scope","handlingStrategy":"try-catch","validationCode":"// Pre-create the project (idempotent) to avoid auto-create failures at plan time.\nfunc ensureProject(c *tfe.Client, org, name string) error {\n    if _, err := c.Projects.Create(ctx, org, tfe.ProjectCreateOptions{Name: name}); err != nil {\n        if !isConflict(err) { return err }\n    }\n    return nil\n}","typeGuard":"if errors.Is(err, tfe.ErrResourceNotFound) { /* tolerate */ } else if isConflict(err) { /* already exists */ }","tryCatchPattern":"project, err := b.client.Projects.Create(ctx, org, createOpts)\nif err != nil && !errors.Is(err, tfe.ErrResourceNotFound) {\n    if isConflict(err) {\n        // fetch existing instead\n        project, err = findProjectByName(b.client, org, name)\n    }\n    if err != nil {\n        return nil, fmt.Errorf(\"failed to create project %s: %v\", name, err)\n    }\n}","preventionTips":["Pre-create projects in the HCP/TFE UI rather than relying on auto-create.","Grant admin/project-create permission to the token's team.","Resolve 409 conflicts by reusing the existing project."],"tags":["terraform","cloud-backend","tfe-api","projects","create","permissions"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}