vms.tf 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //Create passwords (change this after first login)
  2. resource "random_password" "pass-sms" {
  3. count = 1
  4. length = 10
  5. special = false
  6. }
  7. resource "random_password" "pass-sic" {
  8. count = 1
  9. length = 13
  10. special = false
  11. }
  12. resource "random_password" "pass-win" {
  13. count = 1
  14. length = 20
  15. special = true
  16. }
  17. //Create ssh keys
  18. resource "tls_private_key" "ssh" {
  19. algorithm = "RSA"
  20. rsa_bits = "2048"
  21. }
  22. resource "local_file" "private_key" {
  23. content = tls_private_key.ssh.private_key_pem
  24. filename = "pt_key.pem"
  25. file_permission = "0600"
  26. }
  27. //Rnder cloud_init_files
  28. data "template_file" "cloud_init_sms" {
  29. template = file("./check-init-sms.yaml")
  30. vars = {
  31. ssh_key = "${chomp(tls_private_key.ssh.public_key_openssh)}"
  32. pass = "${random_password.pass-sms[0].result}"
  33. }
  34. }
  35. data "template_file" "cloud_init_gw-a" {
  36. template = file("./check-init_gw-a.yaml")
  37. vars = {
  38. ssh_key = "${chomp(tls_private_key.ssh.public_key_openssh)}"
  39. pass_sic = "${random_password.pass-sic[0].result}"
  40. dst-1 = "${replace(var.subnet-a_vpc_1, "1.0/24", "0.0/16")}"
  41. next-hop-1 = "${cidrhost(var.subnet-a_vpc_1, 1)}"
  42. dst-2 = "${replace(var.subnet-a_vpc_2, "1.0/24", "0.0/16")}"
  43. next-hop-2 = "${cidrhost(var.subnet-a_vpc_2, 1)}"
  44. gw = "${cidrhost(var.subnet-a_vpc_3, 1)}"
  45. dst-3 = "198.18.235.0/24"
  46. next-hop-3 = "${cidrhost(var.subnet-a_vpc_4, 1)}"
  47. dst-4 = "198.18.248.0/24"
  48. next-hop-4 = "${cidrhost(var.subnet-a_vpc_4, 1)}"
  49. }
  50. }
  51. data "template_file" "cloud_init_gw-b" {
  52. template = file("./check-init_gw-b.yaml")
  53. vars = {
  54. ssh_key = "${chomp(tls_private_key.ssh.public_key_openssh)}"
  55. pass_sic = "${random_password.pass-sic[0].result}"
  56. dst-1 = "${replace(var.subnet-a_vpc_2, "1.0/24", "0.0/16")}"
  57. next-hop-1 = "${cidrhost(var.subnet-b_vpc_2, 1)}"
  58. dst-2 = var.subnet-a_vpc_4
  59. next-hop-2 = "${cidrhost(var.subnet-b_vpc_4, 1)}"
  60. dst-3 = "${replace(var.subnet-a_vpc_1, "1.0/24", "0.0/16")}"
  61. next-hop-3 = "${cidrhost(var.subnet-b_vpc_1, 1)}"
  62. gw = "${cidrhost(var.subnet-b_vpc_3, 1)}"
  63. dst-4 = "198.18.235.0/24"
  64. next-hop-4 = "${cidrhost(var.subnet-b_vpc_4, 1)}"
  65. dst-5 = "198.18.248.0/24"
  66. next-hop-5 = "${cidrhost(var.subnet-b_vpc_4, 1)}"
  67. }
  68. }
  69. data "template_file" "cloud_init_win" {
  70. template = file("./cloud-init_win.tpl.yaml")
  71. vars = {
  72. pass-win = "${random_password.pass-win[0].result}"
  73. }
  74. }
  75. //Create checkpoint-a(FW-A)
  76. resource "yandex_compute_instance" "fw-a" {
  77. folder_id = yandex_resourcemanager_folder.folder4.id
  78. name = "fw-a"
  79. zone = "ru-central1-a"
  80. hostname = "fw-a"
  81. resources {
  82. cores = 4
  83. memory = 8
  84. }
  85. boot_disk {
  86. initialize_params {
  87. image_id = "fd8lv3k0bcm4a5v49mff"
  88. type = "network-ssd"
  89. size = 120
  90. }
  91. }
  92. network_interface {
  93. //mgmt-int
  94. subnet_id = yandex_vpc_subnet.subnet-a_vpc_4.id
  95. ip_address = "${cidrhost(var.subnet-a_vpc_4, 10)}"
  96. nat = false
  97. }
  98. network_interface {
  99. //transit-int
  100. subnet_id = yandex_vpc_subnet.subnet-a_vpc_3.id
  101. ip_address = "${cidrhost(var.subnet-a_vpc_3, 10)}"
  102. nat = true
  103. }
  104. network_interface {
  105. //servers-int
  106. subnet_id = yandex_vpc_subnet.subnet-a_vpc_1.id
  107. ip_address = "${cidrhost(var.subnet-a_vpc_1, 10)}"
  108. nat = false
  109. }
  110. network_interface {
  111. //database-int
  112. subnet_id = yandex_vpc_subnet.subnet-a_vpc_2.id
  113. ip_address = "${cidrhost(var.subnet-a_vpc_2, 10)}"
  114. nat = false
  115. }
  116. network_interface {
  117. //vpc5-int
  118. subnet_id = yandex_vpc_subnet.subnet-a_vpc_5.id
  119. ip_address = "${cidrhost(var.subnet-a_vpc_5, 10)}"
  120. nat = false
  121. }
  122. network_interface {
  123. //vpc6-int
  124. subnet_id = yandex_vpc_subnet.subnet-a_vpc_6.id
  125. ip_address = "${cidrhost(var.subnet-a_vpc_6, 10)}"
  126. nat = false
  127. }
  128. network_interface {
  129. //vpc7-int
  130. subnet_id = yandex_vpc_subnet.subnet-a_vpc_7.id
  131. ip_address = "${cidrhost(var.subnet-a_vpc_7, 10)}"
  132. nat = false
  133. }
  134. network_interface {
  135. //vpc8-int
  136. subnet_id = yandex_vpc_subnet.subnet-a_vpc_8.id
  137. ip_address = "${cidrhost(var.subnet-a_vpc_8, 10)}"
  138. nat = false
  139. }
  140. metadata = {
  141. user-data = "${data.template_file.cloud_init_gw-a.rendered}"
  142. serial-port-enable = 1
  143. }
  144. }
  145. //------------------------------------------------------------------------------------------------
  146. //Create checkpoint-a(FW-B)
  147. resource "yandex_compute_instance" "fw-b" {
  148. folder_id = yandex_resourcemanager_folder.folder4.id
  149. name = "fw-b"
  150. zone = "ru-central1-b"
  151. hostname = "fw-b"
  152. resources {
  153. cores = 4
  154. memory = 8
  155. }
  156. boot_disk {
  157. initialize_params {
  158. image_id = "fd8lv3k0bcm4a5v49mff"
  159. type = "network-ssd"
  160. size = 120
  161. }
  162. }
  163. network_interface {
  164. //mgmt-int
  165. subnet_id = yandex_vpc_subnet.subnet-b_vpc_4.id
  166. ip_address = "${cidrhost(var.subnet-b_vpc_4, 10)}"
  167. nat = false
  168. }
  169. network_interface {
  170. //transit-int
  171. subnet_id = yandex_vpc_subnet.subnet-b_vpc_3.id
  172. ip_address = "${cidrhost(var.subnet-b_vpc_3, 10)}"
  173. nat = true
  174. }
  175. network_interface {
  176. //servers-int
  177. subnet_id = yandex_vpc_subnet.subnet-b_vpc_1.id
  178. ip_address = "${cidrhost(var.subnet-b_vpc_1, 10)}"
  179. nat = false
  180. }
  181. network_interface {
  182. //database-int
  183. subnet_id = yandex_vpc_subnet.subnet-b_vpc_2.id
  184. ip_address = "${cidrhost(var.subnet-b_vpc_2, 10)}"
  185. nat = false
  186. }
  187. network_interface {
  188. //vpc5-int
  189. subnet_id = yandex_vpc_subnet.subnet-b_vpc_5.id
  190. ip_address = "${cidrhost(var.subnet-b_vpc_5, 10)}"
  191. nat = false
  192. }
  193. network_interface {
  194. //vpc6-int
  195. subnet_id = yandex_vpc_subnet.subnet-b_vpc_6.id
  196. ip_address = "${cidrhost(var.subnet-b_vpc_6, 10)}"
  197. nat = false
  198. }
  199. network_interface {
  200. //vpc7-int
  201. subnet_id = yandex_vpc_subnet.subnet-b_vpc_7.id
  202. ip_address = "${cidrhost(var.subnet-b_vpc_7, 10)}"
  203. nat = false
  204. }
  205. network_interface {
  206. //vpc8-int
  207. subnet_id = yandex_vpc_subnet.subnet-b_vpc_8.id
  208. ip_address = "${cidrhost(var.subnet-b_vpc_8, 10)}"
  209. nat = false
  210. }
  211. metadata = {
  212. user-data = "${data.template_file.cloud_init_gw-b.rendered}"
  213. serial-port-enable = 1
  214. }
  215. }
  216. //-------------------------------------------
  217. //Createтывание checkpoint management server
  218. resource "yandex_compute_instance" "mgmt-server" {
  219. folder_id = yandex_resourcemanager_folder.folder4.id
  220. name = "mgmt-server"
  221. zone = "ru-central1-a"
  222. hostname = "mgmt-server"
  223. resources {
  224. cores = 4
  225. memory = 8
  226. }
  227. boot_disk {
  228. initialize_params {
  229. image_id = "fd8hcf4gjv3adselqajo"
  230. type = "network-ssd"
  231. size = 120
  232. }
  233. }
  234. network_interface {
  235. subnet_id = yandex_vpc_subnet.subnet-a_vpc_4.id
  236. ip_address = "${cidrhost(var.subnet-a_vpc_4, 100)}"
  237. nat = false
  238. #security_group_ids = [yandex_vpc_security_group.ptaf-sg.id]
  239. }
  240. metadata = {
  241. user-data = "${data.template_file.cloud_init_sms.rendered}"
  242. serial-port-enable = 1
  243. }
  244. }
  245. //Create win-pc
  246. resource "yandex_compute_instance" "win-check" {
  247. folder_id = yandex_resourcemanager_folder.folder4.id
  248. name = "win-check"
  249. hostname = "win-check"
  250. platform_id = "standard-v2"
  251. zone = "ru-central1-a"
  252. resources {
  253. cores = 4
  254. memory = 8
  255. }
  256. boot_disk {
  257. initialize_params {
  258. image_id = "fd8vbpg8aq7gmf72a7qh"
  259. }
  260. }
  261. network_interface {
  262. subnet_id = yandex_vpc_subnet.subnet-a_vpc_4.id
  263. ip_address = "${cidrhost(var.subnet-a_vpc_4, 101)}"
  264. nat = true
  265. }
  266. metadata = {
  267. user-data = "${data.template_file.cloud_init_win.rendered}"
  268. }
  269. }
  270. output "a-external_ip_address_of_win-check-vm" {
  271. value = yandex_compute_instance.win-check.network_interface.0.nat_ip_address
  272. }
  273. output "b-password-for-win-check" {
  274. value = "${random_password.pass-win[0].result}"
  275. sensitive = true
  276. }
  277. output "c-ip_address_mgmt-server" {
  278. value = yandex_compute_instance.mgmt-server.network_interface.0.ip_address
  279. }
  280. output "d-ui_console_mgmt-server_password" {
  281. value = "admin"
  282. }
  283. output "e-gui_console_mgmt-server_password" {
  284. value = "${random_password.pass-sms[0].result}"
  285. sensitive = true
  286. }
  287. output "f-sic-password" {
  288. value = "${random_password.pass-sic[0].result}"
  289. sensitive = true
  290. }
  291. output "g-ip_address_fw-a" {
  292. value = yandex_compute_instance.fw-a.network_interface.0.ip_address
  293. }
  294. output "h-ip_address_fw-b" {
  295. value = yandex_compute_instance.fw-b.network_interface.0.ip_address
  296. }
  297. output "i-path_for_private_ssh_key" {
  298. value = "./pt_key.pem"
  299. }