mrparkers / terraform-provider-keycloak

Terraform provider for Keycloak
https://registry.terraform.io/providers/mrparkers/keycloak/latest/docs
MIT License
607 stars 295 forks source link

Group attributes are not organized in a linear way #859

Open kjrsimoes opened 1 year ago

kjrsimoes commented 1 year ago

Currently, group mappers are organized according to their IDs in the database, and that is the order they will have in the state file. This makes it so that even if your mappers are the same as they are in the state but unordered they will show up in the plan as an update. This happens at least when the realm was already created and the group has been imported. It would be interese To give an example of the problem: 1- Create group resource and variable:

resource "keycloak_group" "example_group" {
  realm_id   = var.realm_id
  name       = var.group.name
  attributes = var.group.attributes
}

variable "group" {
type = any
}

group = {
name="example_group"
attributes = "attribute1##attribute2##attribute3"
}

Run apply. If you are lucky the attributes will be created in the database in the same order you created them. But this will probably not happen. If you run terraform plan again. You may see something like this:

imagem

My suggestion is to order the attributes that terraforms receives when refreshing the state (e.g. alphabetically) and order the inputs from the user in the same way.

I am available to create a PR since this is a fix we require.