network.tf 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //Create static routes for transit vpc
  2. resource "yandex_vpc_route_table" "transit-a" {
  3. folder_id = yandex_resourcemanager_folder.folder3.id
  4. network_id = yandex_vpc_network.vpc_name_3.id
  5. name = "transit-a"
  6. static_route {
  7. destination_prefix = "${replace(var.subnet-b_vpc_1, "1.0/24", "0.0/16")}"
  8. next_hop_address = "${cidrhost(var.subnet-b_vpc_3, 10)}"
  9. }
  10. }
  11. //--
  12. resource "yandex_vpc_route_table" "transit-b" {
  13. folder_id = yandex_resourcemanager_folder.folder3.id
  14. network_id = yandex_vpc_network.vpc_name_3.id
  15. name = "transit-b"
  16. static_route {
  17. destination_prefix = "${replace(var.subnet-a_vpc_1, "1.0/24", "0.0/16")}"
  18. next_hop_address = "${cidrhost(var.subnet-a_vpc_3, 10)}"
  19. }
  20. }
  21. //Create static routes for servers vpc
  22. resource "yandex_vpc_route_table" "servers-a" {
  23. folder_id = yandex_resourcemanager_folder.folder1.id
  24. network_id = yandex_vpc_network.vpc_name_1.id
  25. name = "servers-a"
  26. static_route {
  27. destination_prefix = "0.0.0.0/0"
  28. next_hop_address = "${cidrhost(var.subnet-a_vpc_1, 10)}"
  29. }
  30. }
  31. resource "yandex_vpc_route_table" "servers-b" {
  32. folder_id = yandex_resourcemanager_folder.folder1.id
  33. network_id = yandex_vpc_network.vpc_name_1.id
  34. name = "servers-b"
  35. static_route {
  36. destination_prefix = "0.0.0.0/0"
  37. next_hop_address = "${cidrhost(var.subnet-b_vpc_1, 10)}"
  38. }
  39. }
  40. //Create static routes for database vpc
  41. resource "yandex_vpc_route_table" "database-a" {
  42. folder_id = yandex_resourcemanager_folder.folder2.id
  43. network_id = yandex_vpc_network.vpc_name_2.id
  44. name = "database-a"
  45. static_route {
  46. destination_prefix = "0.0.0.0/0"
  47. next_hop_address = "${cidrhost(var.subnet-a_vpc_2, 10)}"
  48. }
  49. }
  50. resource "yandex_vpc_route_table" "database-b" {
  51. folder_id = yandex_resourcemanager_folder.folder2.id
  52. network_id = yandex_vpc_network.vpc_name_2.id
  53. name = "database-b"
  54. static_route {
  55. destination_prefix = "0.0.0.0/0"
  56. next_hop_address = "${cidrhost(var.subnet-b_vpc_2, 10)}"
  57. }
  58. }
  59. //Create networks-------------------
  60. //VPC-1
  61. resource "yandex_vpc_network" "vpc_name_1" {
  62. name = var.vpc_name_1
  63. folder_id = yandex_resourcemanager_folder.folder1.id
  64. }
  65. resource "yandex_vpc_subnet" "subnet-a_vpc_1" {
  66. folder_id = yandex_resourcemanager_folder.folder1.id
  67. name = var.subnet-a_vpc_1
  68. zone = "ru-central1-a"
  69. network_id = yandex_vpc_network.vpc_name_1.id
  70. v4_cidr_blocks = [var.subnet-a_vpc_1]
  71. route_table_id = yandex_vpc_route_table.servers-a.id
  72. }
  73. resource "yandex_vpc_subnet" "subnet-b_vpc_1" {
  74. folder_id = yandex_resourcemanager_folder.folder1.id
  75. name = var.subnet-b_vpc_1
  76. zone = "ru-central1-b"
  77. network_id = yandex_vpc_network.vpc_name_1.id
  78. v4_cidr_blocks = [var.subnet-b_vpc_1]
  79. route_table_id = yandex_vpc_route_table.servers-b.id
  80. }
  81. //VPC-2
  82. resource "yandex_vpc_network" "vpc_name_2" {
  83. name = var.vpc_name_2
  84. folder_id = yandex_resourcemanager_folder.folder2.id
  85. }
  86. resource "yandex_vpc_subnet" "subnet-a_vpc_2" {
  87. folder_id = yandex_resourcemanager_folder.folder2.id
  88. name = var.subnet-a_vpc_2
  89. zone = "ru-central1-a"
  90. network_id = yandex_vpc_network.vpc_name_2.id
  91. v4_cidr_blocks = [var.subnet-a_vpc_2]
  92. route_table_id = yandex_vpc_route_table.database-a.id
  93. }
  94. resource "yandex_vpc_subnet" "subnet-b_vpc_2" {
  95. folder_id = yandex_resourcemanager_folder.folder2.id
  96. name = var.subnet-b_vpc_2
  97. zone = "ru-central1-b"
  98. network_id = yandex_vpc_network.vpc_name_2.id
  99. v4_cidr_blocks = [var.subnet-b_vpc_2]
  100. route_table_id = yandex_vpc_route_table.database-b.id
  101. }
  102. //VPC-3
  103. resource "yandex_vpc_network" "vpc_name_3" {
  104. name = var.vpc_name_3
  105. folder_id = yandex_resourcemanager_folder.folder3.id
  106. }
  107. resource "yandex_vpc_subnet" "subnet-a_vpc_3" {
  108. folder_id = yandex_resourcemanager_folder.folder3.id
  109. name = var.subnet-a_vpc_3
  110. zone = "ru-central1-a"
  111. network_id = yandex_vpc_network.vpc_name_3.id
  112. v4_cidr_blocks = [var.subnet-a_vpc_3]
  113. route_table_id = yandex_vpc_route_table.transit-a.id
  114. }
  115. resource "yandex_vpc_subnet" "subnet-b_vpc_3" {
  116. folder_id = yandex_resourcemanager_folder.folder3.id
  117. name = var.subnet-b_vpc_3
  118. zone = "ru-central1-b"
  119. network_id = yandex_vpc_network.vpc_name_3.id
  120. v4_cidr_blocks = [var.subnet-b_vpc_3]
  121. route_table_id = yandex_vpc_route_table.transit-b.id
  122. }
  123. //VPC-4
  124. resource "yandex_vpc_network" "vpc_name_4" {
  125. name = var.vpc_name_4
  126. folder_id = yandex_resourcemanager_folder.folder4.id
  127. }
  128. resource "yandex_vpc_subnet" "subnet-a_vpc_4" {
  129. folder_id = yandex_resourcemanager_folder.folder4.id
  130. name = var.subnet-a_vpc_4
  131. zone = "ru-central1-a"
  132. network_id = yandex_vpc_network.vpc_name_4.id
  133. v4_cidr_blocks = [var.subnet-a_vpc_4]
  134. }
  135. resource "yandex_vpc_subnet" "subnet-b_vpc_4" {
  136. folder_id = yandex_resourcemanager_folder.folder4.id
  137. name = var.subnet-b_vpc_4
  138. zone = "ru-central1-b"
  139. network_id = yandex_vpc_network.vpc_name_4.id
  140. v4_cidr_blocks = [var.subnet-b_vpc_4]
  141. }
  142. //VPC-5
  143. resource "yandex_vpc_network" "vpc_name_5" {
  144. name = var.vpc_name_5
  145. folder_id = yandex_resourcemanager_folder.folder5.id
  146. }
  147. resource "yandex_vpc_subnet" "subnet-a_vpc_5" {
  148. folder_id = yandex_resourcemanager_folder.folder5.id
  149. name = var.subnet-a_vpc_5
  150. zone = "ru-central1-a"
  151. network_id = yandex_vpc_network.vpc_name_5.id
  152. v4_cidr_blocks = [var.subnet-a_vpc_5]
  153. }
  154. resource "yandex_vpc_subnet" "subnet-b_vpc_5" {
  155. folder_id = yandex_resourcemanager_folder.folder5.id
  156. name = var.subnet-b_vpc_5
  157. zone = "ru-central1-b"
  158. network_id = yandex_vpc_network.vpc_name_5.id
  159. v4_cidr_blocks = [var.subnet-b_vpc_5]
  160. }
  161. //VPC-6
  162. resource "yandex_vpc_network" "vpc_name_6" {
  163. name = var.vpc_name_6
  164. folder_id = yandex_resourcemanager_folder.folder6.id
  165. }
  166. resource "yandex_vpc_subnet" "subnet-a_vpc_6" {
  167. folder_id = yandex_resourcemanager_folder.folder6.id
  168. name = var.subnet-a_vpc_6
  169. zone = "ru-central1-a"
  170. network_id = yandex_vpc_network.vpc_name_6.id
  171. v4_cidr_blocks = [var.subnet-a_vpc_6]
  172. }
  173. resource "yandex_vpc_subnet" "subnet-b_vpc_6" {
  174. folder_id = yandex_resourcemanager_folder.folder6.id
  175. name = var.subnet-b_vpc_6
  176. zone = "ru-central1-b"
  177. network_id = yandex_vpc_network.vpc_name_6.id
  178. v4_cidr_blocks = [var.subnet-b_vpc_6]
  179. }
  180. //VPC-7
  181. resource "yandex_vpc_network" "vpc_name_7" {
  182. name = var.vpc_name_7
  183. folder_id = yandex_resourcemanager_folder.folder7.id
  184. }
  185. resource "yandex_vpc_subnet" "subnet-a_vpc_7" {
  186. folder_id = yandex_resourcemanager_folder.folder7.id
  187. name = var.subnet-a_vpc_7
  188. zone = "ru-central1-a"
  189. network_id = yandex_vpc_network.vpc_name_7.id
  190. v4_cidr_blocks = [var.subnet-a_vpc_7]
  191. }
  192. resource "yandex_vpc_subnet" "subnet-b_vpc_7" {
  193. folder_id = yandex_resourcemanager_folder.folder7.id
  194. name = var.subnet-b_vpc_7
  195. zone = "ru-central1-b"
  196. network_id = yandex_vpc_network.vpc_name_7.id
  197. v4_cidr_blocks = [var.subnet-b_vpc_7]
  198. }
  199. //VPC-8
  200. resource "yandex_vpc_network" "vpc_name_8" {
  201. name = var.vpc_name_8
  202. folder_id = yandex_resourcemanager_folder.folder8.id
  203. }
  204. resource "yandex_vpc_subnet" "subnet-a_vpc_8" {
  205. folder_id = yandex_resourcemanager_folder.folder8.id
  206. name = var.subnet-a_vpc_8
  207. zone = "ru-central1-a"
  208. network_id = yandex_vpc_network.vpc_name_8.id
  209. v4_cidr_blocks = [var.subnet-a_vpc_8]
  210. }
  211. resource "yandex_vpc_subnet" "subnet-b_vpc_8" {
  212. folder_id = yandex_resourcemanager_folder.folder8.id
  213. name = var.subnet-b_vpc_8
  214. zone = "ru-central1-b"
  215. network_id = yandex_vpc_network.vpc_name_8.id
  216. v4_cidr_blocks = [var.subnet-b_vpc_8]
  217. }