vms.tf 7.7 KB

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