Skip to content

keycloak_user attributes not applied on first terraform apply, no error shown #1215

@rif281

Description

@rif281

Describe the bug

Description

When creating a user with the keycloak_user resource and setting attributes, they appear in the first terraform plan output, but are not created in Keycloak after the first apply. No error is shown. Running plan and apply a second time applies the missing attributes successfully.

Terraform Configuration

resource "keycloak_user" "user" {
  for_each = local.keycloak_spec["keycloak_users"]
  realm_id = keycloak_realm.name.id
  username = each.key
  enabled  = local.enable_local_users

  email          = lookup(each.value , "email", "${each.key}@${each.key}.com")
  email_verified = lookup(each.value , "email_verified", false)
  first_name     = lookup(each.value , "first_name", each.key)
  last_name      = lookup(each.value , "last_name", each.key)

  attributes = {
    role        = each.value["role"]
    phoneNumber = lookup(each.value , "phoneNumber", "0000000000")
  }

  initial_password {
    value     = random_password.keycloak_users_secrets[each.key].result
    temporary = false
  }
}

First plan output:

# module.keycloak_seed.keycloak_user.user["user1"] will be created
+ attributes = {
    "phoneNumber" = "0000000000"
    "role"        = "AccountAdmin"
  }
+ other fields...

Second plan output:

# module.keycloak_seed.keycloak_user.user["user1"] will be updated in-place
! attributes = {
    "phoneNumber" = "0000000000"
    "role"        = "AccountAdmin"
  }

Version

24.0.4

Expected behavior

The attributes should be created after the first apply, or an error message should be displayed.

Actual behavior

No error message is displayed, and the attributes are only created after the second attempt.

How to Reproduce?

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions