network.tf 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. data "yandex_vpc_network" "vpc-positive" {
  2. network_id = var.vpc_id
  3. }
  4. resource "yandex_vpc_subnet" "ext-subnet" {
  5. folder_id = var.folder_id
  6. count = 2
  7. name = "ext-subnet-${element(var.network_names, count.index)}"
  8. zone = element(var.zones, count.index)
  9. network_id = data.yandex_vpc_network.vpc-positive.id
  10. v4_cidr_blocks = [element(var.ext_cidrs, count.index)]
  11. }
  12. resource "yandex_vpc_subnet" "mgmgt-subnet" {
  13. folder_id = var.folder_id
  14. count = 2
  15. name = "mgmt-subnet-${element(var.network_names, count.index)}"
  16. zone = element(var.zones, count.index)
  17. network_id = data.yandex_vpc_network.vpc-positive.id
  18. v4_cidr_blocks = [element(var.mgmt_cidrs, count.index)]
  19. }
  20. //Создание Security Group
  21. resource "yandex_vpc_security_group" "ptaf-sg" {
  22. folder_id = var.folder_id
  23. name = "ptaf-sg"
  24. network_id = data.yandex_vpc_network.vpc-positive.id
  25. ingress {
  26. protocol = "TCP"
  27. v4_cidr_blocks = ["0.0.0.0/0"]
  28. port = 80
  29. }
  30. ingress {
  31. protocol = "TCP"
  32. security_group_id = yandex_vpc_security_group.ssh-broker.id
  33. from_port = 0
  34. to_port = 65535
  35. }
  36. ingress {
  37. protocol = "TCP"
  38. v4_cidr_blocks = ["198.18.235.0/24", "198.18.248.0/24"]
  39. from_port = 0
  40. to_port = 65535
  41. }
  42. ingress {
  43. protocol = "TCP"
  44. predefined_target = "self_security_group"
  45. from_port = 0
  46. to_port = 65535
  47. }
  48. egress {
  49. protocol = "ANY"
  50. v4_cidr_blocks = ["0.0.0.0/0"]
  51. from_port = 0
  52. to_port = 65535
  53. }
  54. }
  55. resource "yandex_vpc_security_group" "app-sg" {
  56. folder_id = var.folder_id
  57. name = "apps-sg"
  58. network_id = data.yandex_vpc_network.vpc-positive.id
  59. ingress {
  60. protocol = "TCP"
  61. security_group_id = yandex_vpc_security_group.ptaf-sg.id
  62. port = 80
  63. }
  64. ingress {
  65. protocol = "TCP"
  66. v4_cidr_blocks = ["0.0.0.0/0"]
  67. port = 80
  68. }
  69. ingress {
  70. protocol = "TCP"
  71. v4_cidr_blocks = ["198.18.235.0/24", "198.18.248.0/24"]
  72. from_port = 0
  73. to_port = 65535
  74. }
  75. egress {
  76. protocol = "ANY"
  77. v4_cidr_blocks = ["0.0.0.0/0"]
  78. from_port = 0
  79. to_port = 65535
  80. }
  81. }
  82. resource "yandex_vpc_security_group" "ssh-broker" {
  83. folder_id = var.folder_id
  84. name = "broker-sg"
  85. network_id = data.yandex_vpc_network.vpc-positive.id
  86. ingress {
  87. protocol = "TCP"
  88. v4_cidr_blocks = ["0.0.0.0/0"]
  89. port = 22
  90. }
  91. egress {
  92. protocol = "ANY"
  93. v4_cidr_blocks = ["0.0.0.0/0"]
  94. from_port = 0
  95. to_port = 65535
  96. }
  97. }
  98. //Создание LB_target_group ptaf
  99. resource "yandex_lb_target_group" "ptaf_group" {
  100. name = "ptafgroup"
  101. target {
  102. subnet_id = yandex_vpc_subnet.ext-subnet[0].id
  103. address = yandex_compute_instance.ptaf-a.network_interface.0.ip_address
  104. }
  105. target {
  106. subnet_id = yandex_vpc_subnet.ext-subnet[1].id
  107. address = yandex_compute_instance.ptaf-b.network_interface.0.ip_address
  108. }
  109. }
  110. //Объявление extLB для импорта
  111. resource "yandex_lb_network_load_balancer" "ext-lb" {
  112. name = "extlb"
  113. listener {
  114. name = "my-listener"
  115. port = 80
  116. external_address_spec {
  117. ip_version = "ipv4"
  118. }
  119. }
  120. attached_target_group {
  121. target_group_id = "${yandex_lb_target_group.ptaf_group.id}"
  122. healthcheck {
  123. name = "tcp"
  124. tcp_options {
  125. port = 80
  126. }
  127. }
  128. }
  129. }
  130. //data target-group app
  131. data "yandex_lb_target_group" "app-group" {
  132. target_group_id = var.app_target_group_id
  133. }
  134. //Создание intLB
  135. resource "yandex_lb_network_load_balancer" "int-lb" {
  136. name = "intlb"
  137. type = "internal"
  138. depends_on = [
  139. yandex_lb_network_load_balancer.ext-lb,
  140. ]
  141. listener {
  142. name = "my-listener"
  143. port = 80
  144. internal_address_spec {
  145. subnet_id = yandex_vpc_subnet.ext-subnet[0].id
  146. }
  147. }
  148. attached_target_group {
  149. target_group_id = data.yandex_lb_target_group.app-group.id
  150. healthcheck {
  151. name = "tcp"
  152. tcp_options {
  153. port = 80
  154. }
  155. }
  156. }
  157. }