compute.tf 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # =================
  2. # Compute Resources
  3. # =================
  4. # Define SGW Folder
  5. data "yandex_resourcemanager_folder" "sgw_folder" {
  6. cloud_id = var.cloud_id
  7. name = var.yc_sgw.folder_name
  8. }
  9. # Define the VM image for SGW
  10. data "yandex_compute_image" "sgw_image" {
  11. folder_id = var.yc_sgw.image_folder_id
  12. name = var.yc_sgw.image_name
  13. # family = container-optimized-image
  14. }
  15. # Create SGW VM
  16. resource "yandex_compute_instance" "sgw" {
  17. folder_id = data.yandex_resourcemanager_folder.sgw_folder.id
  18. name = lower(var.yc_sgw.name)
  19. hostname = lower(var.yc_sgw.name)
  20. platform_id = "standard-v3"
  21. zone = var.yc_sgw.zone
  22. labels = var.labels
  23. resources {
  24. cores = 2
  25. memory = 4
  26. }
  27. boot_disk {
  28. initialize_params {
  29. image_id = data.yandex_compute_image.sgw_image.id
  30. }
  31. }
  32. network_interface {
  33. subnet_id = yandex_vpc_subnet.sgw_subnet.id
  34. ip_address = var.yc_sgw.inside_ip
  35. nat = true
  36. nat_ip_address = yandex_vpc_address.sgw_public_ip.external_ipv4_address[0].address
  37. security_group_ids = [yandex_vpc_security_group.sgw_sg.id]
  38. }
  39. metadata = {
  40. user-data = templatefile("${path.module}/sgw-vm-init.tpl", {
  41. ADMIN_NAME = var.yc_sgw.admin_name
  42. ADMIN_SSH_KEY = file(var.yc_sgw.admin_key_path)
  43. REMOTE_SGW_IP = var.remote_sgw.outside_ip
  44. POLICY_NAME = var.ipsec_policy.policy_name
  45. IKE_PROPOSAL = var.ipsec_policy.ike_proposal
  46. ESP_PROPOSAL = var.ipsec_policy.esp_proposal
  47. PSK = var.ipsec_policy.psk
  48. ROUTE_LIST = trim("%{for prefix in var.remote_subnets}ip route add ${prefix} dev ipsec0;%{~endfor~}", ";")
  49. })
  50. }
  51. }