Skip to content

Error message lost, resulting in unexpected state 'failed', wanted target 'finished'. last error: %!s()

Bug Report

When creating a project from a template, the provider will repeatedly check the import status of the project. When the import fails (import_status: failed) the import_error never reaches the user. I would expect this error to be displayed. Instead the following message is shown: unexpected state 'failed', wanted target 'finished'. last error: %!s(<nil>).

Even though the import_error field contains the exact message that should be propagated:

Error importing repository into rug-digitallab/experiments/repoman/template-test/destination-terraform/template-from-group-access-token - Error adding importer user to Project members. Validation failed: User project bots cannot be added to other groups [FILTERED] projects

Relevant Terraform Configuration

{
  "terraform": {
    "required_providers": {
      "gitlab": {
        "source": "gitlabhq/gitlab",
        "version": "17.11.0"
      }
    }
  },
  "provider": {
    "gitlab": [
      {
        "base_url": "https://gitlab.com",
        "token": "<a group access token>"
      }
    ]
  },
  "resource": {
      "gitlab_project": {
        "project_from_template": {
          "name": "Template from Group Access Token",
          "use_custom_template": true,
          "group_with_project_templates_id": <id of group containing templates>,
          "template_project_id": <id of the template project in the above group>,
          "namespace_id": <destination group id for the instantiation of the template>
        }
      }
  }
}

Relevant Terraform Command

tofu apply

Relevant Log Output

These are the debug logs of the `terraform` command output:
2025-05-01T12:08:18.674+0200 [DEBUG] provider.terraform-provider-gitlab_v17.8.0: Received HTTP Response: Cf-Cache-Status=MISS Cf-Ray=938e7a0f9868da9e-AMS Strict-Transport-Security=max-age=31536000 Server=cloudflare X-Frame-Options=SAMEORIGIN tf_http_op_type=response tf_http_trans_id=8ffbfd00-f479-969f-3d89-3db2ca0f733e @module=gitlab.GitLab Content-Security-Policy="default-src 'none'" Referrer-Policy=strict-origin-when-cross-origin X-Request-Id=6ed99f34ddf8cb11cfaccafafa0e0d6e tf_http_res_version=HTTP/2.0 Cache-Control="max-age=0, private, must-revalidate" Gitlab-Sv=api-gke-us-east1-c Set-Cookie="_cfuvid=r6A4pfYR6.IE6CZy6gYjktohRe.TDqn1vVzfciAuem0-1746094098584-0.0.1.1-604800000; path=/; domain=.gitlab.com; HttpOnly; Secure; SameSite=None" new_logger_warning="This log was generated by a subsystem logger that wasn't created before being used. Use tflog.NewSubsystem to create this logger before it is used." tf_http_res_body="{\"id\":69478443,\"description\":null,\"name\":\"Template from Group Access Token\",\"name_with_namespace\":\"RuG Digital Lab / Experiments / RepoMan Experiments / Template Test / Destination Terraform / Template from Group Access Token\",\"path\":\"template-from-group-access-token\",\"path_with_namespace\":\"rug-digitallab/experiments/repoman/template-test/destination-terraform/template-from-group-access-token\",\"created_at\":\"2025-05-01T10:08:12.916Z\",\"import_status\":\"failed\",\"import_type\":\"gitlab_custom_project_template\",\"correlation_id\":null,\"failed_relations\":[],\"import_error\":\"Error importing repository  into rug-digitallab/experiments/repoman/template-test/destination-terraform/template-from-group-access-token - Error adding importer user to Project members. Validation failed: User project bots cannot be added to other groups [FILTERED] projects\",\"stats\":null}" X-Content-Type-Options=nosniff X-Gitlab-Meta="{\"correlation_id\":\"6ed99f34ddf8cb11cfaccafafa0e0d6e\",\"version\":\"1\"}" X-Runtime=0.536090 Date="Thu, 01 May 2025 10:08:18 GMT" Etag="W/\"cda2b25273bb29a75263302fc71ae402\"" Nel="{\"max_age\": 0}" tf_http_res_status_reason="200 OK" @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.35.0/helper/logging/logging_http_transport.go:160 Content-Type=application/json Gitlab-Lb=haproxy-main-56-lb-gprd Vary="Origin, Accept-Encoding" tf_http_res_status_code=200 timestamp="2025-05-01T12:08:18.674+0200"

2025-05-01T12:08:18.674+0200 [ERROR] provider.terraform-provider-gitlab_v17.8.0: Response contains error diagnostic: @caller=github.com/hashicorp/terraform-plugin-go@v0.25.0/tfprotov6/internal/diag/diagnostics.go:58 diagnostic_detail="" diagnostic_severity=ERROR tf_provider_addr=registry.terraform.io/gitlabhq/gitlab tf_req_id=cc519f76-2335-ed89-dfde-e9ea39a79e14 tf_resource_type=gitlab_project tf_rpc=ApplyResourceChange @module=sdk.proto diagnostic_summary="error while waiting for project \"Template from Group Access Token\" import to finish: unexpected state 'failed', wanted target 'finished'. last error: %!s(<nil>)" tf_proto_version=6.7 timestamp="2025-05-01T12:08:18.674+0200"

2025-05-01T12:08:18.676+0200 [ERROR] vertex "gitlab_project.project_from_template" error: error while waiting for project "Template from Group Access Token" import to finish: unexpected state 'failed', wanted target 'finished'. last error: %!s(<nil>)

Additional Details

  • GitLab Terraform Provider Version: 17.11.0
  • GitLab Instance Version: gitlab.com
  • Terraform Version: OpenTofu v1.9.1
Edited by Brian Setz