federation.tf 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # =======================
  2. # YC Federation Resources
  3. # =======================
  4. resource "yandex_organizationmanager_saml_federation" federation {
  5. name = "keycloak"
  6. description = "Keycloak Federation"
  7. organization_id = var.org_id
  8. issuer = "https://${var.kc_fqdn}:${var.kc_port}/realms/${var.kc_realm}"
  9. sso_url = "https://${var.kc_fqdn}:${var.kc_port}/realms/${var.kc_realm}/protocol/saml"
  10. sso_binding = "POST"
  11. auto_create_account_on_login = true
  12. security_settings {
  13. encrypted_assertions = true
  14. }
  15. }
  16. resource "null_resource" "federation_cert" {
  17. provisioner "local-exec" {
  18. command = <<-CMD
  19. echo -----BEGIN CERTIFICATE-----\\n$(curl -s https://${var.kc_fqdn}:${var.kc_port}/realms/${var.kc_realm}/protocol/saml/descriptor | awk '{split($0,lst,"X509Certificate>"); print substr(lst[2],1,length(lst[2])-5)}')\\n-----END CERTIFICATE----- | tee kc-cert.pem
  20. yc organization-manager federation saml certificate create \
  21. --name=kc-cert \
  22. --federation-id=${yandex_organizationmanager_saml_federation.federation.id} \
  23. --certificate-file=kc-cert.pem
  24. rm -f kc-cert.pem
  25. CMD
  26. }
  27. depends_on = [
  28. yandex_compute_instance.vm_instance
  29. ]
  30. }
  31. output "federation_link" {
  32. value = "https://console.cloud.yandex.ru/federations/${yandex_organizationmanager_saml_federation.federation.id}"
  33. }
  34. output "keycloak_links" {
  35. value = "https://${var.kc_fqdn}:8443"
  36. }
  37. output "federation_id" {
  38. value = yandex_organizationmanager_saml_federation.federation.id
  39. }