gomorpheus / terraform-provider-morpheus

Terraform Morpheus provider
MIT License
17 stars 21 forks source link

morpheus_user 'password' and 'role_ids' should be required #218

Closed doubletwist13 closed 7 months ago

doubletwist13 commented 7 months ago

The documentation (and code) for morpheus_user resource has password and role_ids marked as optional. However creation of the resource will fail if those are not set.

Bad resource

resource "morpheus_user" "user1" {
  username              = "user1"
  email                 = "user1@example.com"
}

Plan

Terraform will perform the following actions:

  # morpheus_user.user1 will be created
  + resource "morpheus_user" "user1" {
      + email            = "user1@example.com"
      + first_name       = (known after apply)
      + id               = (known after apply)
      + last_name        = (known after apply)
      + linux_keypair_id = (known after apply)
      + linux_username   = (known after apply)
      + tenant_id        = (known after apply)
      + username         = "user1"
      + windows_username = (known after apply)
    }

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

Error on apply

2024-04-18T22:32:13.843Z [INFO]  provider.terraform-provider-morpheus_v0.9.8: 2024/04/18 22:32:13 API FAILURE: Response HTTP: 400  Success: false  Size: 107B Body: {"user":null,"success":false,"errors":{"password":"Please enter a password","role":"Please select a role"}} - API returned HTTP 400: timestamp=2024-04-18T22:32:13.842Z

Good Resource

However adding password and role_ids allows it to work:

resource "morpheus_user" "user1" {
  username              = "user1"
  email                 = "user1@example.com"
  password              = "Passw0rd!bad!"
  role_ids              = [5]
}

Success

Terraform will perform the following actions:

  # morpheus_user.user1 will be created
  + resource "morpheus_user" "user1" {
      + email            = "user1@example.com"
      + first_name       = (known after apply)
      + id               = (known after apply)
      + last_name        = (known after apply)
      + linux_keypair_id = (known after apply)
      + linux_username   = (known after apply)
      + password         = (sensitive value)
      + role_ids         = [
          + 5,
        ]
      + tenant_id        = (known after apply)
      + username         = "user1"
      + windows_username = (known after apply)
    }

Plan: 1 to add, 0 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

morpheus_user.user1: Creating...
morpheus_user.user1: Creation complete after 0s [id=6]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
martezr commented 7 months ago

This issue has been fixed in the latest release of the Terraform provider - https://registry.terraform.io/providers/gomorpheus/morpheus/latest/docs/resources/user