frontend.tf 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. data "yandex_compute_image" "container-optimized-image" {
  2. family = "container-optimized-image"
  3. }
  4. data "template_file" "cloud_init" {
  5. template = "${file("cloud-init.tpl.yaml")}"
  6. vars = {
  7. ssh_key = "${file(var.public_key_path)}"
  8. }
  9. }
  10. resource "yandex_compute_instance_group" "ig-frontend" {
  11. name = "ig-frontend"
  12. service_account_id = yandex_iam_service_account.ig_sa.id
  13. folder_id = var.folder_id
  14. instance_template {
  15. platform_id = "standard-v2"
  16. resources {
  17. cores = 4
  18. memory = 8
  19. }
  20. service_account_id = yandex_iam_service_account.ig_sa.id
  21. boot_disk {
  22. mode = "READ_WRITE"
  23. initialize_params {
  24. image_id = data.yandex_compute_image.container-optimized-image.id
  25. size = 13
  26. }
  27. }
  28. network_interface {
  29. subnet_ids = [yandex_vpc_subnet.frontend-subnet-a.id, yandex_vpc_subnet.frontend-subnet-b.id, yandex_vpc_subnet.frontend-subnet-c.id]
  30. nat = true
  31. security_group_ids = [yandex_vpc_security_group.sg-frontend.id]
  32. }
  33. metadata = {
  34. docker-container-declaration = file("docker-declaration.yaml")
  35. user-data = "${data.template_file.cloud_init.rendered}"
  36. serial-port-enable = 1
  37. }
  38. }
  39. scale_policy {
  40. fixed_scale {
  41. size = 3
  42. }
  43. }
  44. allocation_policy {
  45. zones = ["ru-central1-a", "ru-central1-b", "ru-central1-c"]
  46. }
  47. deploy_policy {
  48. max_unavailable = 3
  49. max_creating = 3
  50. max_expansion = 3
  51. max_deleting = 3
  52. }
  53. load_balancer {
  54. target_group_name = "frontend-tg"
  55. }
  56. depends_on = [
  57. yandex_resourcemanager_folder_iam_binding.sabind,
  58. ]
  59. }
  60. resource "yandex_lb_network_load_balancer" "lb-frontend" {
  61. name = "lb-frontend"
  62. listener {
  63. name = "ngnix-listener"
  64. port = 80
  65. target_port = 80
  66. external_address_spec {
  67. ip_version = "ipv4"
  68. }
  69. }
  70. attached_target_group {
  71. target_group_id = yandex_compute_instance_group.ig-frontend.load_balancer.0.target_group_id
  72. healthcheck {
  73. name = "tcp"
  74. tcp_options {
  75. port = 80
  76. }
  77. }
  78. }
  79. }