datadrivers / terraform-provider-nexus

Terraform provider for Sonatype Nexus
https://registry.terraform.io/providers/datadrivers/nexus
Mozilla Public License 2.0
119 stars 53 forks source link

Order of repositories in docker repository group is not respected #339

Closed xgcssch closed 3 months ago

xgcssch commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.7

Nexus Provider Version

1.21.2

Nexus Version

3.37.3

Affected Resource(s)/Data Source(s)

nexus_repository_docker_group

Terraform Configuration Files

resource "nexus_repository_docker_hosted" docker-hosted-repos-rfrg {
  name   = "docker-h-rfrg"
  online = true
  docker {
    force_basic_auth = false
    v1_enabled       = false
    https_port       = 5001
  }
  storage {
    blob_store_name                = "TransientData"
    strict_content_type_validation = true
  }
}

resource "nexus_repository_docker_hosted" docker-hosted-repos-rint {
  name   = "docker-h-rint"
  online = true
  docker {
    force_basic_auth = false
    v1_enabled       = false
    https_port       = 5002
  }
  storage {
    blob_store_name                = "TransientData"
    strict_content_type_validation = true
  }
}

resource "nexus_repository_docker_hosted" docker-hosted-repos-rewt {
  name   = "docker-h-rewt"
  online = true
  docker {
    force_basic_auth = false
    v1_enabled       = false
    https_port       = 5003
  }
  storage {
    blob_store_name                = "TransientData"
    strict_content_type_validation = true
  }
}

resource "nexus_repository_docker_group" docker-group-repos {
  name   = "docker-g-rewt"
  online = true
  docker {
    force_basic_auth = false
    v1_enabled       = false
    https_port       = 5023
  }
  group {
        member_names     = [
          nexus_repository_docker_hosted.docker-hosted-repos-rewt.name,
          nexus_repository_docker_hosted.docker-hosted-repos-rint.name,
          nexus_repository_docker_hosted.docker-hosted-repos-rfrg.name,
          ]
  }
  storage {
    blob_store_name                = "TransientData"
    strict_content_type_validation = true
  }
}

Debug Output/Panic Output

omitted

Expected Behaviour

Final order in Nexus after applying

docker-h-rewt
docker-h-rint
docker-h-rfrg

Actual Behaviour

Final order in Nexus after applying

docker-h-rint
docker-h-rfrg
docker-h-rewt

Funny: in the Terraform difference output the order is different too:

  # nexus_repository_docker_group.docker-group-repos will be created
  + resource "nexus_repository_docker_group" "docker-group-repos" {
      + id     = (known after apply)
      + name   = "docker-g-rewt"
      + online = true

      + docker {
          + force_basic_auth = false
          + https_port       = 5023
          + v1_enabled       = false
        }

      + group {
          + member_names = [
              + "docker-h-rewt",
              + "docker-h-rfrg",
              + "docker-h-rint",
            ]
        }

      + storage {
          + blob_store_name                = "TransientData"
          + strict_content_type_validation = true
        }
    }

Steps to Reproduce

terraform apply

References

25 or #140

bkolanko commented 11 months ago

It's the same bug for the other type of groups, like npm and maven.

joeyaurel commented 10 months ago

I can confirm that this problem still exists. Looking into it.

Edu-DevOps commented 10 months ago

I´ve checked this and the issue seems to be in this schema attribute since TypeSet is used to represent an unordered collection of items. Terraform doc reference: https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-types#typeset

We would need to use TypeList to preserver the order I believe

salakonrad commented 9 months ago

The problem still exists in the latest provider version

sonykus commented 9 months ago

I can confirm that the problem still exists in version 2.1.0 of the datadriver, and this also affects ALL kind of groups (not just docker). The underlying issue was well pointed out in the comments above: The datadriver implementation uses a set, not a list, and therefore the ordered input gets reshuffled along the way.

Environment (although irrelevant due to the nature of this bug): Terraform 1.7.1 and Nexus RM Pro 3.62.0-01.

anmoel commented 8 months ago

first, it is only fixed for docker groups

anmoel commented 8 months ago

we will implement the same way for all repository types if someone can approve that the problem is fixed in version https://github.com/datadrivers/terraform-provider-nexus/releases/tag/v2.2.0

oliverisaac commented 8 months ago

The merged PR applies to the base repository schema so it applied to all repository types.

This is working as expected for an npm repo:

anmoel commented 3 months ago

the issue looks closed. please open again if not so