keycloak-config.tf 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # ================================
  2. # Keycloak configuration resources
  3. # ================================
  4. # https://github.com/mrparkers/terraform-provider-keycloak/tree/master
  5. provider "keycloak" {
  6. client_id = "admin-cli"
  7. username = module.settings.keycloak.admin_user
  8. password = var.kc_admin_password
  9. url = "https://${module.settings.keycloak.subdomain}.${module.settings.domain}:${module.settings.keycloak.port}"
  10. }
  11. resource "random_string" "kc_test_user_password" {
  12. length = 12
  13. upper = true
  14. lower = true
  15. numeric = true
  16. special = true
  17. override_special = "!@%&*()-_=+[]{}<>:?"
  18. }
  19. resource "keycloak_realm" "realm" {
  20. realm = "firezone"
  21. enabled = true
  22. display_name = "Firezone"
  23. display_name_html = "<b>Firezone</b>"
  24. ssl_required = "external"
  25. registration_allowed = false
  26. registration_email_as_username = false
  27. remember_me = false
  28. verify_email = false
  29. reset_password_allowed = false
  30. login_with_email_allowed = false
  31. internationalization {
  32. supported_locales = [ "en" ]
  33. default_locale = "en"
  34. }
  35. }
  36. # Keycloak OpenID Connect client
  37. resource "keycloak_openid_client" "firezone" {
  38. realm_id = keycloak_realm.realm.id
  39. client_id = "firezone"
  40. name = "Keycloak for Firezone"
  41. enabled = true
  42. access_type = "CONFIDENTIAL"
  43. standard_flow_enabled = true
  44. direct_access_grants_enabled = true
  45. use_refresh_tokens = true
  46. pkce_code_challenge_method = "S256"
  47. valid_redirect_uris = [
  48. "https://${module.settings.firezone.subdomain}.${module.settings.domain}/auth/oidc/keycloak/callback/"
  49. ]
  50. valid_post_logout_redirect_uris = [
  51. "https://${module.settings.firezone.subdomain}.${module.settings.domain}/"
  52. ]
  53. }
  54. # Keycloak test user account
  55. resource "keycloak_user" "test_user" {
  56. realm_id = keycloak_realm.realm.id
  57. username = module.settings.keycloak.test_user.name
  58. enabled = true
  59. email = module.settings.keycloak.test_user.email
  60. email_verified = true
  61. attributes = {}
  62. initial_password {
  63. value = "${random_string.kc_test_user_password.result}"
  64. temporary = false
  65. }
  66. }