cert-manager.tf 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # ==============================
  2. # Certificate Manager resources
  3. # Let's Encrypt certificate
  4. # ==============================
  5. # Create request to the Let's Encrypt service for Keycloak's VM certificate
  6. resource "yandex_cm_certificate" "kc_le_cert" {
  7. folder_id = var.values.folder_id
  8. name = var.values.keycloak.le_cert_name
  9. domains = ["${var.values.keycloak.subdomain}.${var.values.domain}"]
  10. description = "LE Certificate for Keycloak VM"
  11. managed {
  12. challenge_type = "DNS_CNAME"
  13. }
  14. }
  15. # Create domain validation DNS record for Let's Encrypt service
  16. resource "yandex_dns_recordset" "validation_dns_rec" {
  17. zone_id = var.values.dns_zone_id
  18. name = yandex_cm_certificate.kc_le_cert.challenges[0].dns_name
  19. type = yandex_cm_certificate.kc_le_cert.challenges[0].dns_type
  20. data = [yandex_cm_certificate.kc_le_cert.challenges[0].dns_value]
  21. ttl = 60
  22. }
  23. # Still waiting upon the cert will be issued (up to 30 min!)
  24. data "yandex_cm_certificate_content" "cert_check_status" {
  25. folder_id = var.values.folder_id
  26. name = var.values.keycloak.le_cert_name
  27. wait_validation = true
  28. private_key_format = "PKCS1"
  29. depends_on = [yandex_dns_recordset.validation_dns_rec]
  30. }
  31. # Save generated public keys chain to the specified file
  32. resource "local_file" "kc_pub_chain" {
  33. content = join("", [for el in data.yandex_cm_certificate_content.cert_check_status.certificates : format("%s", el)])
  34. filename = "le-cert-pub-chain.pem"
  35. depends_on = [data.yandex_cm_certificate_content.cert_check_status]
  36. }
  37. # Save generated private key to the specified file
  38. resource "local_file" "kc_private_key" {
  39. content = data.yandex_cm_certificate_content.cert_check_status.private_key
  40. filename = "le-cert-priv-key.pem"
  41. depends_on = [data.yandex_cm_certificate_content.cert_check_status]
  42. }