jfrog / terraform-provider-project

Terraform provider to manage JFrog Projects
https://jfrog.com/artifactory
Apache License 2.0
150 stars 11 forks source link

Empty lists as resource attribute value resolve to the predefined default, rather than an empty list. #126

Closed eelginUPS closed 5 months ago

eelginUPS commented 5 months ago

The plan correctly points out the roles to be removed

# xxx["dct-gbs-mera"] will be updated in-place
  ~ resource "project_group" "pipeline-reader-groups" {
        id          = "dct:dct-gbs-mera-pipeline-reader"
        name        = "dct-gbs-mera-pipeline-reader"
      ~ roles       = [
          - "Viewer",
        ]
        # (1 unchanged attribute hidden)
    }

  # xxx["dct-runteam"] will be updated in-place
  ~ resource "project_group" "pipeline-reader-groups" {
        id          = "dct:dct-runteam-pipeline-reader"
        name        = "dct-runteam-pipeline-reader"
      ~ roles       = [
          - "Viewer",
        ]
        # (1 unchanged attribute hidden)
    }

It also claims in the apply that the updates were applied.

Versions of tf + providers: terraform_1.7.5_linux_amd64.zip jfrog/project v1.5.2 jfrog/platform v1.7.4 jfrog/artifactory v10.8.0

Expected behavior roles: [] should apply what the plan states, and remove the default 'viewer' role.

alexhung commented 5 months ago

@eelginUPS Thank you for the report. Projects do not allows group without a role assigned to it. You can verify this on the web UI.

When a new project_group is created with empty roles, Artifactory returns the group with one role which it defaults to the "Viewer" role since that has the least permission.

I missed this use case when I created this resource and did not have a test for this.

To avoid state drift, you should include "Viewer" in the roles list.

I'll be updating the resource to ensure roles attribute must have at least one item.