diff --git a/terraform/keycloak/backend.tf b/terraform/keycloak/backend.tf new file mode 100644 index 0000000..3b5e266 --- /dev/null +++ b/terraform/keycloak/backend.tf @@ -0,0 +1,40 @@ +resource "keycloak_openid_client" "backend" { + access_type = "CONFIDENTIAL" + client_id = "backend" + realm_id = keycloak_realm.poulet.id + valid_redirect_uris = [ + "*" + ] + standard_flow_enabled = true + direct_access_grants_enabled = true + service_accounts_enabled = true + client_secret = var.client_secret +} + +resource "keycloak_role" "backend_doctor" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.backend.id + name = "doctor" + description = "Role with doctor privilege" +} + +resource "keycloak_role" "backend_nurse" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.backend.id + name = "nurse" + description = "Role with nrse privilege" +} + +resource "keycloak_role" "backend_patient" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.backend.id + name = "patient" + description = "Role with patient privilege" +} + +resource "keycloak_role" "backend_familly" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.backend.id + name = "familly" + description = "Role with familly privilege" +} \ No newline at end of file diff --git a/terraform/keycloak/frontend.tf b/terraform/keycloak/frontend.tf new file mode 100644 index 0000000..4185168 --- /dev/null +++ b/terraform/keycloak/frontend.tf @@ -0,0 +1,40 @@ +resource "keycloak_openid_client" "frontend" { + access_type = "CONFIDENTIAL" + client_id = "frontend" + realm_id = keycloak_realm.poulet.id + valid_redirect_uris = [ + "*" + ] + standard_flow_enabled = true + direct_access_grants_enabled = true + service_accounts_enabled = true + client_secret = var.client_secret +} + +resource "keycloak_role" "frontend_doctor" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.frontend.id + name = "doctor" + description = "Role with doctor privilege" +} + +resource "keycloak_role" "frontend_nurse" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.frontend.id + name = "nurse" + description = "Role with nrse privilege" +} + +resource "keycloak_role" "frontend_patient" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.frontend.id + name = "patient" + description = "Role with patient privilege" +} + +resource "keycloak_role" "frontend_familly" { + realm_id = keycloak_realm.poulet.id + client_id = keycloak_openid_client.frontend.id + name = "familly" + description = "Role with familly privilege" +} \ No newline at end of file diff --git a/terraform/keycloak/realm.tf b/terraform/keycloak/realm.tf index fd49913..cfd9011 100644 --- a/terraform/keycloak/realm.tf +++ b/terraform/keycloak/realm.tf @@ -6,7 +6,9 @@ resource "keycloak_role" "admin_role" { realm_id = keycloak_realm.poulet.id name = "admin" composite_roles = [ - keycloak_role.grafana_admin.id + keycloak_role.grafana_admin.id, + keycloak_role.backend_doctor.id, + keycloak_role.frontend_doctor.id ] } @@ -14,6 +16,36 @@ resource "keycloak_role" "doctor_role" { realm_id = keycloak_realm.poulet.id name = "doctor" composite_roles = [ - keycloak_role.grafana_viewer.id + keycloak_role.grafana_viewer.id, + keycloak_role.backend_doctor.id, + keycloak_role.frontend_doctor.id + ] +} + +resource "keycloak_role" "nurse_role" { + realm_id = keycloak_realm.poulet.id + name = "nurse" + composite_roles = [ + keycloak_role.grafana_viewer.id, + keycloak_role.backend_nurse.id, + keycloak_role.frontend_nurse.id + ] +} + +resource "keycloak_role" "patient_role" { + realm_id = keycloak_realm.poulet.id + name = "patient" + composite_roles = [ + keycloak_role.backend_patient.id, + keycloak_role.frontend_patient.id + ] +} + +resource "keycloak_role" "familly_role" { + realm_id = keycloak_realm.poulet.id + name = "familly" + composite_roles = [ + keycloak_role.backend_familly.id, + keycloak_role.frontend_familly.id ] } diff --git a/terraform/keycloak/user.tf b/terraform/keycloak/user.tf index d0ebfe9..b5addae 100644 --- a/terraform/keycloak/user.tf +++ b/terraform/keycloak/user.tf @@ -1,3 +1,29 @@ +resource "keycloak_user" "poulet_admin" { + realm_id = keycloak_realm.poulet.id + username = "poulet_admin" + enabled = true + + email = "admin@poulet.com" + email_verified = true + + first_name = "John" + last_name = "Doe" + + initial_password { + value = "admin" + temporary = false + } +} + +resource "keycloak_user_roles" "admin_role" { + realm_id = keycloak_realm.poulet.id + user_id = keycloak_user.poulet_admin.id + + role_ids = [ + keycloak_role.admin_role.id + ] +} + resource "keycloak_user" "doctor" { realm_id = keycloak_realm.poulet.id username = "doctor" @@ -22,4 +48,82 @@ resource "keycloak_user_roles" "doctor_role" { role_ids = [ keycloak_role.doctor_role.id ] +} + +resource "keycloak_user" "nurse" { + realm_id = keycloak_realm.poulet.id + username = "nurse" + enabled = true + + email = "nurse@poulet.com" + email_verified = true + + first_name = "John" + last_name = "Doe" + + initial_password { + value = "nurse" + temporary = false + } +} + +resource "keycloak_user_roles" "nurse_role" { + realm_id = keycloak_realm.poulet.id + user_id = keycloak_user.nurse.id + + role_ids = [ + keycloak_role.nurse_role.id + ] +} + +resource "keycloak_user" "patient" { + realm_id = keycloak_realm.poulet.id + username = "patient" + enabled = true + + email = "patient@poulet.com" + email_verified = true + + first_name = "John" + last_name = "Doe" + + initial_password { + value = "patient" + temporary = false + } +} + +resource "keycloak_user_roles" "patient_role" { + realm_id = keycloak_realm.poulet.id + user_id = keycloak_user.patient.id + + role_ids = [ + keycloak_role.patient_role.id + ] +} + +resource "keycloak_user" "familly" { + realm_id = keycloak_realm.poulet.id + username = "familly" + enabled = true + + email = "familly@poulet.com" + email_verified = true + + first_name = "John" + last_name = "Doe" + + initial_password { + value = "familly" + temporary = false + } +} + +resource "keycloak_user_roles" "familly_role" { + realm_id = keycloak_realm.poulet.id + user_id = keycloak_user.familly.id + + role_ids = [ + keycloak_role.familly_role.id + ] } \ No newline at end of file