datadrivers / terraform-provider-nexus

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

Could not create privilege: id parameter must not be blank #319

Open mttradebyte opened 2 years ago

mttradebyte commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.0

Nexus Provider Version

1.21.0

Nexus Version

OSS 3.39.0-01

Affected Resource(s)/Data Source(s)

nexus_privilege

Terraform Configuration Files

resource "nexus_security_content_selector" "docker" {
  name       = "docker"
  expression = "path =^ \"/v2/aaaa/\""
}

resource "nexus_privilege" "docker_snapshot" {
  name             = "docker_snapshot"
  type             = "repository-content-selector"
  content_selector = "docker"
  repository       = "docker-snapshot"
  actions          = ["ADD", "EDIT", "READ"]

  depends_on = [ nexus_security_content_selector.docker ]
}

Debug Output/Panic Output

│ Error: could not create privilege "docker_snapshot": HTTP: 400, [ {
│   "id" : "PARAMETER format",
│   "message" : "must not be blank"
│ } ]
│
│   with nexus_privilege.docker_snapshot,
│   on privileges.tf line 129, in resource "nexus_privilege" "docker_snapshot":
│  129: resource "nexus_privilege" "docker_snapshot" {

Expected Behaviour

The privilege should have been created successfully.

Actual Behaviour

Errored out

Steps to Reproduce

No response

References

N/A

It should be noted that if the privilege is created in Nexus first, then imported, this configuration is acceptable. It just doesn't seem to work if creating from scratch. Additionally, id is a read-only attribute and cannot be set in the terraform config.

fmereu-bics commented 2 years ago

The error seems to say the format parameter is missing, not the ID. Can you try to set the format to docker?

mttradebyte commented 2 years ago

Interesting. That seemed to resolve it, but it's listed as an optional attribute in the documentation, as well as when you import them, you don't need to provide the format and it doesn't change it. I guess the documentation needs to be updated to specify that it's not optional, however I'm not sure why importing it no longer requires it to be specified in your terraform though. Your terraform should always mirror reality, so having it missing after an import seems like an anti-pattern.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 7 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

anmoel commented 1 year ago

/fresh Hi, we start to refactor the privilege resource. It would be splittet into own resources for each format, because the formats have different required parameters

Seq-73 commented 1 year ago

Nexus says:

"message" : "must not be blank"

and TF doesn't allow that message field.

Shocktrooper commented 1 year ago

I just got this error but with one addition. It wants a repository as well and not just the format. Both are listed as optional with the provider. Looking deeper it appears when trying to create a privilege in the UI only 2 out of the 6 privilege types actually require format. The rest don't even have format as an option.

We probably should change the documentation at the very minimum to note this and also later should probably handle this with code somehow

Required format:

Not applicable: