gitlab_project_protected_environment - Error: Provider produced inconsistent result after apply

Bug Report

Hello all,

While trying to implement protection for our gitlab project environments, we came across an inconsistent result issue (as described in details bellow). To help us debug the issue, we remove our custom code and use the example as provided on the official github provider documentation website ( https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_protected_environment )

Please advice, Thank you!

Relevant Terraform Configuration

resource "gitlab_project_environment" "environment" {
  for_each = { for env in local.gitlab_project_environments : env.name => env }

  project             = gitlab_project.project.id
  name                = each.value.name
  external_url        = each.value.external_url
  stop_before_destroy = each.value.stop_before_destroy
}

resource "gitlab_project_protected_environment" "environment" {
  for_each = gitlab_project_environment.environment

  project                 = gitlab_project.project.id
  required_approval_count = 2
  environment             = each.key

  deploy_access_levels {
    access_level = "developer"
  }

  deploy_access_levels {
    user_id = 12017791
  }
}

Relevant Terraform Command

terraform apply

Relevant Log Output

These are the debug logs of the `terraform` command output:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

  # module.gitlab_groups["GLG-20231105-001"].gitlab_group.group will be updated in-place
  ~ resource "gitlab_group" "group" {
        id                                 = "77737642"
        name                               = "GLG-20231105-001"
      ~ prevent_forking_outside_group      = false -> true
        # (25 unchanged attributes hidden)
    }

  # module.gitlab_projects["CBG-GLP-20231111-009"].gitlab_project_protected_environment.environment["master"] will be created
  + resource "gitlab_project_protected_environment" "environment" {
      + approval_rules          = [
        ] -> (known after apply)
      + environment             = "master"
      + id                      = (known after apply)
      + project                 = "52093411"
      + required_approval_count = 2

      + deploy_access_levels {
          + access_level             = "developer"
          + access_level_description = (known after apply)
          + id                       = (known after apply)
        }
      + deploy_access_levels {
          + access_level_description = (known after apply)
          + id                       = (known after apply)
          + user_id                  = 12017791
        }
    }

Plan: 1 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.gitlab_groups["GLG-20231105-001"].gitlab_group.group: Modifying... [id=77737642]
module.gitlab_projects["CBG-GLP-20231111-009"].gitlab_project_protected_environment.environment["master"]: Creating...
module.gitlab_groups["GLG-20231105-001"].gitlab_group.group: Modifications complete after 1s [id=77737642]

│ Error: Provider produced inconsistent result after apply

│ When applying changes to module.gitlab_projects["CBG-GLP-20231111-009"].gitlab_project_protected_environment.environment["master"], provider
│ "provider[\"registry.terraform.io/gitlabhq/gitlab\"]" produced an unexpected new value: .deploy_access_levels: planned set element
│ cty.ObjectVal(map[string]cty.Value{"access_level":cty.NullVal(cty.String), "access_level_description":cty.UnknownVal(cty.String), "group_id":cty.NullVal(cty.Number),
│ "id":cty.UnknownVal(cty.Number), "user_id":cty.NumberIntVal(1.2016019e+07)}) does not correlate with any element in actual.

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


terraform version
Terraform v1.2.2
on windows_amd64
+ provider registry.terraform.io/gitlabhq/gitlab v16.5.0

Additional Details

  • GitLab Terraform Provider Version: v16.5.0
  • GitLab Version: gitlab.com
  • Terraform Version: v1.2.2