vpn.tf 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. data "yandex_compute_image" "my_image" {
  2. family = "ubuntu-1804-lts"
  3. }
  4. data "template_file" "ipsec_init" {
  5. template = "${file("ipsec-init.tpl.yaml")}"
  6. vars = {
  7. ssh_key = "${file(var.public_key_path)}"
  8. vpn_addr = yandex_vpc_address.vpnaddr.external_ipv4_address.0.address
  9. remote_addr = yandex_vpc_address.remoteaddr.external_ipv4_address.0.address
  10. ipsec_pass = var.ipsec_password
  11. }
  12. }
  13. resource "yandex_vpc_address" "vpnaddr" {
  14. name = "vpnaddr"
  15. external_ipv4_address {
  16. zone_id = "ru-central1-a"
  17. }
  18. }
  19. resource "yandex_compute_instance" "cloud-vpn-gate" {
  20. zone = "ru-central1-a"
  21. name = "cloud-vpn-gate"
  22. hostname = "cloud-vpn-gate"
  23. platform_id = "standard-v2"
  24. resources {
  25. cores = 4
  26. memory = 8
  27. }
  28. boot_disk {
  29. initialize_params {
  30. image_id = data.yandex_compute_image.my_vpn.id
  31. type = "network-ssd"
  32. size = 13
  33. }
  34. }
  35. network_interface {
  36. subnet_id = yandex_vpc_subnet.vpn-subnet-a.id
  37. ip_address = "10.10.5.5"
  38. nat = true
  39. nat_ip_address = yandex_vpc_address.vpnaddr.external_ipv4_address.0.address
  40. security_group_ids = [yandex_vpc_security_group.sg-ipsec.id]
  41. }
  42. metadata = {
  43. user-data = "${data.template_file.ipsec_init.rendered}"
  44. serial-port-enable = 1
  45. }
  46. }