gitlab_project_protected_environment: dynamic "deploy_access_levels" showing provider error

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Creating the projected environment for my projects using terraform by creating a module given below:

data "gitlab_user" "approvers" {
  for_each = toset(local.approvers)
  username = each.value
}

data "gitlab_user" "deployers" {
  for_each = local.deployers
  username = each.value
}

resource "gitlab_project_environment" "this" {
  for_each = toset(var.environment_names)
  project  = var.project_id
  name     = each.value
}

# Create protected environments with access controls
resource "gitlab_project_protected_environment" "this" {
  for_each    = toset(var.environment_names)
  project     = gitlab_project_environment.this[each.key].project
  environment = gitlab_project_environment.this[each.key].name

  dynamic "deploy_access_levels" {
    for_each = data.gitlab_user.deployers
    content {
      user_id = deploy_access_levels.value.id
    }
  }

  approval_rules = [
    for user in data.gitlab_user.approvers : {
      user_id = user.id
    }
  ]
}

Gitlab provider version: 17.10.0 Terraform provider version: 1.0.8

Getting no errors in the terraform plan, however applying changes leads to failure and gives the below errors:

Error: Skipping retry since count exceeded for matched error on line 956: Provider produced inconsistent result after apply. Commands matched: 4. Maximum retries: 3.

This is a bug in the provider, which should be reported in the provider's own issue tracker.

Faced another issue: This attribute is deprecated. Use deploy_access_levels_attribute instead.

I upgraded the provider to version 18.0.2 and used deploy_access_levels_attribute instead of deploy_access_levels but getting the same error.

This thread shows that this issue is resolved in the version 18.2.0 #6132 (closed)

Any suggestions/fix on how to use dynamic creation here ?

Edited by 🤖 GitLab Bot 🤖