compute.tf 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Create ssh keys for compute resources
  2. resource "tls_private_key" "ssh" {
  3. algorithm = "RSA"
  4. rsa_bits = "2048"
  5. }
  6. resource "local_file" "private_key" {
  7. content = tls_private_key.ssh.private_key_pem
  8. filename = "pt_key.pem"
  9. file_permission = "0600"
  10. }
  11. resource "random_string" "firezone_admin_password" {
  12. length = 12
  13. upper = true
  14. lower = true
  15. numeric = true
  16. special = true
  17. override_special = "!@%&*()-_=+[]{}<>:?"
  18. }
  19. data "yandex_compute_image" "container-optimized-image" {
  20. family = "container-optimized-image"
  21. }
  22. // Create firezone control server
  23. resource "yandex_compute_instance" "firezone" {
  24. folder_id = var.values.folder_id
  25. name = "firezone"
  26. hostname = "firezone"
  27. platform_id = "standard-v3"
  28. zone = "ru-central1-a"
  29. resources {
  30. cores = 2
  31. memory = 4
  32. }
  33. boot_disk {
  34. initialize_params {
  35. image_id = data.yandex_compute_image.container-optimized-image.id
  36. type = "network-ssd"
  37. size = 30
  38. }
  39. }
  40. network_interface {
  41. subnet_id = yandex_vpc_subnet.firezone-subnet.id
  42. ip_address = "${cidrhost(var.values.firezone.subnet, 100)}"
  43. nat = true
  44. nat_ip_address = yandex_vpc_address.firezone-public-ip.external_ipv4_address.0.address
  45. security_group_ids = [yandex_vpc_security_group.firezone-sg.id]
  46. }
  47. metadata = {
  48. user-data = templatefile("${path.module}/templates/cloud-init_firezone.tpl.yaml",
  49. {
  50. firezone_ssh_key_pub = "${chomp(tls_private_key.ssh.public_key_openssh)}",
  51. firezone_vm_username = var.values.firezone.vm_username
  52. firezone_admin_email = var.values.firezone.admin_email
  53. firezone_admin_password = "${random_string.firezone_admin_password.result}"
  54. firezone_url = "https://${var.values.firezone.subdomain}.${var.values.domain}"
  55. version = var.values.firezone.version
  56. db_host = yandex_mdb_postgresql_cluster.pg_cluster.host.0.fqdn
  57. db_name = var.values.postgres.db_firezone_name
  58. db_user = var.values.postgres.db_user
  59. db_pass = random_string.postgres_user_password.result
  60. wg_port = var.values.firezone.wg_port
  61. })
  62. }
  63. depends_on = [yandex_mdb_postgresql_database.pg_firezone_db]
  64. }