VM.tf 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. data "yandex_compute_image" "nat_instance" {
  2. family = "nat-instance-ubuntu"
  3. }
  4. data "yandex_compute_image" "img_bastion" {
  5. family = "ubuntu-2004-lts"
  6. }
  7. data "yandex_compute_image" "vm_img" {
  8. family = "ubuntu-1804-lts"
  9. }
  10. data "template_file" "cloud_init_bastion" {
  11. template = "${file("cloud-init-bastion.tpl.yaml")}"
  12. vars = {
  13. aws_key = "${module.sa_and_key.aws_key_id}"
  14. aws_sec = "${module.sa_and_key.aws_secret}"
  15. ssh_key = "${file(var.public_key_path)}"
  16. }
  17. }
  18. data "template_file" "cloud_init" {
  19. template = "${file("cloud-init.tpl.yaml")}"
  20. vars = {
  21. ssh_key = "${file(var.public_key_path)}"
  22. }
  23. }
  24. resource "yandex_compute_instance" "nat-instance" {
  25. zone = "ru-central1-a"
  26. name = "nat-instance"
  27. hostname = "nat-instance"
  28. platform_id = "standard-v2"
  29. resources {
  30. cores = 2
  31. memory = 4
  32. }
  33. boot_disk {
  34. initialize_params {
  35. image_id = data.yandex_compute_image.nat_instance.id
  36. type = "network-ssd"
  37. size = 26
  38. }
  39. }
  40. network_interface {
  41. subnet_id = yandex_vpc_subnet.public-subnet.id
  42. ip_address = "10.0.0.5"
  43. nat = true
  44. security_group_ids = [yandex_vpc_security_group.sg-inet-acc.id]
  45. }
  46. metadata = {
  47. user-data = "${data.template_file.cloud_init.rendered}"
  48. serial-port-enable = 1
  49. }
  50. }
  51. resource "yandex_compute_instance" "vm-ci-cd" {
  52. zone = "ru-central1-a"
  53. name = "vm-ci-cd"
  54. hostname = "vm-ci-cd"
  55. platform_id = "standard-v2"
  56. resources {
  57. cores = 2
  58. memory = 4
  59. }
  60. boot_disk {
  61. initialize_params {
  62. image_id = data.yandex_compute_image.vm_img.id
  63. type = "network-ssd"
  64. size = 26
  65. }
  66. }
  67. network_interface {
  68. subnet_id = yandex_vpc_subnet.tools-subnet.id
  69. ip_address = "10.50.0.5"
  70. nat = false
  71. security_group_ids = [yandex_vpc_security_group.sg-ci-cd.id]
  72. }
  73. metadata = {
  74. user-data = "${data.template_file.cloud_init.rendered}"
  75. serial-port-enable = 1
  76. }
  77. }
  78. resource "yandex_compute_instance" "bastion" {
  79. zone = "ru-central1-a"
  80. name = "bastion"
  81. hostname = "bastion"
  82. platform_id = "standard-v2"
  83. service_account_id = "${module.sa_and_key.s3_writer}"
  84. resources {
  85. cores = 2
  86. memory = 4
  87. }
  88. boot_disk {
  89. initialize_params {
  90. image_id = data.yandex_compute_image.img_bastion.id
  91. type = "network-ssd"
  92. size = 26
  93. }
  94. }
  95. network_interface {
  96. subnet_id = yandex_vpc_subnet.public-subnet.id
  97. ip_address = "10.0.0.10"
  98. nat = true
  99. security_group_ids = [yandex_vpc_security_group.sg-bastion.id]
  100. }
  101. metadata = {
  102. user-data = "${data.template_file.cloud_init_bastion.rendered}"
  103. serial-port-enable = 1
  104. }
  105. }
  106. resource "yandex_compute_instance" "vm-dev" {
  107. zone = "ru-central1-a"
  108. name = "vm-dev"
  109. hostname = "vm-dev"
  110. platform_id = "standard-v2"
  111. folder_id = var.dev_folder_id
  112. resources {
  113. cores = 2
  114. memory = 4
  115. }
  116. boot_disk {
  117. initialize_params {
  118. image_id = data.yandex_compute_image.vm_img.id
  119. type = "network-ssd"
  120. size = 26
  121. }
  122. }
  123. network_interface {
  124. subnet_id = yandex_vpc_subnet.subnet-dev.id
  125. ip_address = "10.30.0.5"
  126. nat = true
  127. security_group_ids = [yandex_vpc_security_group.sg-dev.id]
  128. }
  129. metadata = {
  130. user-data = "${data.template_file.cloud_init.rendered}"
  131. serial-port-enable = 1
  132. }
  133. }
  134. resource "yandex_compute_instance" "app-stage" {
  135. zone = "ru-central1-a"
  136. name = "app-stage"
  137. hostname = "app-stage"
  138. platform_id = "standard-v2"
  139. folder_id = var.stage_folder_id
  140. resources {
  141. cores = 2
  142. memory = 4
  143. }
  144. boot_disk {
  145. initialize_params {
  146. image_id = data.yandex_compute_image.vm_img.id
  147. type = "network-ssd"
  148. size = 26
  149. }
  150. }
  151. network_interface {
  152. subnet_id = yandex_vpc_subnet.subnet-stage.id
  153. ip_address = "10.20.0.5"
  154. nat = false
  155. security_group_ids = [yandex_vpc_security_group.sg-stage.id]
  156. }
  157. metadata = {
  158. user-data = "${data.template_file.cloud_init.rendered}"
  159. serial-port-enable = 1
  160. }
  161. }
  162. resource "yandex_compute_instance" "app-prod" {
  163. zone = "ru-central1-a"
  164. name = "app-prod"
  165. hostname = "app-prod"
  166. platform_id = "standard-v2"
  167. folder_id = var.prod_folder_id
  168. resources {
  169. cores = 2
  170. memory = 4
  171. }
  172. boot_disk {
  173. initialize_params {
  174. image_id = data.yandex_compute_image.vm_img.id
  175. type = "network-ssd"
  176. size = 26
  177. }
  178. }
  179. network_interface {
  180. subnet_id = yandex_vpc_subnet.subnet-prod.id
  181. ip_address = "10.10.0.5"
  182. nat = false
  183. security_group_ids = [yandex_vpc_security_group.sg-prod.id]
  184. }
  185. metadata = {
  186. user-data = "${data.template_file.cloud_init.rendered}"
  187. serial-port-enable = 1
  188. }
  189. }