Skip to content

Error in apply when passing path to id attribute on gitlab_project data source

Bug Report

The following error message happens during an apply when we try to pass a project path to the id attribute on the gitlab_project data source. I have sanitized the values.

 Error: Provider produced inconsistent final plan
 
 When expanding the plan for
 module.permissions["team"].gitlab_project_share_group.share_project["project"]
 to include new values learned so far during apply, provider
 "registry.terraform.io/gitlabhq/gitlab" produced an invalid new value for
 .project_id: was
 cty.StringVal("path/to/project"),
 but now cty.StringVal("123456").
 
 This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

I believe the issue is here: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/internal/provider/sdk/data_source_gitlab_project.go#L437 The gitlab_project data source allows a numerical project id or a project path, but the GitLab API is returning the numerical project id, which the provider attempts to set, but Terraform appears to see this as a conflict since id was originally the path. I believe the id attribute should only accept a numerical project id as there is another attribute path_with_namespace that can be used to pass the project path.

When we changed our gitlab_project data source to use the path_with_namespace attribute instead, the error no longer occurred.

Relevant Terraform Configuration

data "gitlab_project" "shared_project" {
 for_each = var.project_permissions
 id       = "${var.projects_group_full_path}/${each.key}"
}

resource "gitlab_project_share_group" "share_project" {
 for_each = { for entry in local.combined_group_permissions : "${entry.project}.${entry.group}" => entry }

 project_id   = data.gitlab_project.shared_project[each.value.project].id
 group_id     = var.group_ids[each.value.group]
 group_access = each.value.permission
}

Relevant Log Output

These are the debug logs of the `terraform` command output:
 Error: Provider produced inconsistent final plan
 
 When expanding the plan for
 module.permissions["team"].gitlab_project_share_group.share_project["project"]
 to include new values learned so far during apply, provider
 "registry.terraform.io/gitlabhq/gitlab" produced an invalid new value for
 .project_id: was
 cty.StringVal("path/to/project"),
 but now cty.StringVal("123456").
 
 This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Additional Details

  • GitLab Terraform Provider Version: 15.8.0
  • GitLab Version: 15.9.3 (SaaS)
  • Terraform Version: 1.3.7