network.tf 6.8 KB

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