main.tf 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. resource "linode_instance" "tsung-client" {
  2. count = 10
  3. label = "${var.label}-client-${count.index}"
  4. region = "${var.region}"
  5. type = "g6-standard-8"
  6. image = "linode/debian9"
  7. backups_enabled = true
  8. private_ip = true
  9. swap_size = 256
  10. authorized_keys = ["${chomp(file("~/.ssh/id_rsa.pub"))}"]
  11. provisioner "remote-exec" {
  12. inline = [
  13. "hostnamectl set-hostname ${var.label}-client-${count.index}",
  14. "mkdir -p /root/.ssh",
  15. "echo 'Host tsung-server' >> /root/.ssh/config",
  16. "echo ' StrictHostKeyChecking no' >> /root/.ssh/config",
  17. "echo ' UserKnownHostsFile=/dev/null' >> /root/.ssh/config",
  18. "echo 'Host tsung-client-*' >> /root/.ssh/config",
  19. "echo ' StrictHostKeyChecking no' >> /root/.ssh/config",
  20. "echo ' UserKnownHostsFile=/dev/null' >> /root/.ssh/config",
  21. "chmod -R 0700 /root/.ssh",
  22. "chmod 0600 /root/.ssh/config"
  23. ]
  24. }
  25. provisioner "file" {
  26. source = "${path.module}/files/etc/"
  27. destination = "/etc"
  28. }
  29. provisioner "remote-exec" {
  30. inline = [
  31. "chmod -R +x /etc/network/if-*.d/ip*",
  32. ]
  33. }
  34. provisioner "remote-exec" {
  35. inline = [
  36. "mkdir -p /tmp/scripts",
  37. ]
  38. }
  39. provisioner "file" {
  40. source = "${path.module}/scripts/"
  41. destination = "/tmp/scripts"
  42. }
  43. provisioner "remote-exec" {
  44. inline = [
  45. "chmod +x /tmp/scripts/*",
  46. "run-parts /tmp/scripts",
  47. ]
  48. }
  49. }
  50. resource "linode_instance" "tsung-server" {
  51. label = "${var.label}-server"
  52. region = "${var.region}"
  53. type = "g6-standard-4"
  54. image = "linode/debian9"
  55. backups_enabled = true
  56. private_ip = true
  57. swap_size = 256
  58. authorized_keys = ["${chomp(file("~/.ssh/id_rsa.pub"))}"]
  59. provisioner "remote-exec" {
  60. inline = [
  61. "hostnamectl set-hostname ${var.label}-server",
  62. "echo '${self.private_ip_address} ${var.label}-server' >> /etc/hosts",
  63. "echo '${linode_instance.tsung-client.0.private_ip_address} tsung-client-0' >> /etc/hosts",
  64. "echo '${linode_instance.tsung-client.1.private_ip_address} tsung-client-1' >> /etc/hosts",
  65. "echo '${linode_instance.tsung-client.2.private_ip_address} tsung-client-2' >> /etc/hosts",
  66. "echo '${linode_instance.tsung-client.3.private_ip_address} tsung-client-3' >> /etc/hosts",
  67. "echo '${linode_instance.tsung-client.4.private_ip_address} tsung-client-4' >> /etc/hosts",
  68. "echo '${linode_instance.tsung-client.5.private_ip_address} tsung-client-5' >> /etc/hosts",
  69. "echo '${linode_instance.tsung-client.6.private_ip_address} tsung-client-6' >> /etc/hosts",
  70. "echo '${linode_instance.tsung-client.7.private_ip_address} tsung-client-7' >> /etc/hosts",
  71. "echo '${linode_instance.tsung-client.8.private_ip_address} tsung-client-8' >> /etc/hosts",
  72. "echo '${linode_instance.tsung-client.9.private_ip_address} tsung-client-9' >> /etc/hosts",
  73. "mkdir -p /root/.ssh",
  74. "echo 'Host tsung-server' >> /root/.ssh/config",
  75. "echo ' StrictHostKeyChecking no' >> /root/.ssh/config",
  76. "echo ' UserKnownHostsFile=/dev/null' >> /root/.ssh/config",
  77. "echo 'Host tsung-client-*' >> /root/.ssh/config",
  78. "echo ' StrictHostKeyChecking no' >> /root/.ssh/config",
  79. "echo ' UserKnownHostsFile=/dev/null' >> /root/.ssh/config",
  80. "chmod -R 0700 /root/.ssh",
  81. "chmod 0600 /root/.ssh/config",
  82. "scp /etc/hosts tsung-client-0:/etc/hosts",
  83. "scp /etc/hosts tsung-client-1:/etc/hosts",
  84. "scp /etc/hosts tsung-client-2:/etc/hosts",
  85. "scp /etc/hosts tsung-client-3:/etc/hosts",
  86. "scp /etc/hosts tsung-client-4:/etc/hosts",
  87. "scp /etc/hosts tsung-client-5:/etc/hosts",
  88. "scp /etc/hosts tsung-client-6:/etc/hosts",
  89. "scp /etc/hosts tsung-client-7:/etc/hosts",
  90. "scp /etc/hosts tsung-client-8:/etc/hosts",
  91. "scp /etc/hosts tsung-client-9:/etc/hosts",
  92. ]
  93. }
  94. provisioner "file" {
  95. source = "${path.module}/files/etc/"
  96. destination = "/etc"
  97. }
  98. provisioner "remote-exec" {
  99. inline = [
  100. "chmod -R +x /etc/network/if-*.d/ip*",
  101. ]
  102. }
  103. provisioner "file" {
  104. source = "${path.module}/files/bin/"
  105. destination = "/usr/local/bin"
  106. }
  107. provisioner "remote-exec" {
  108. inline = [
  109. "chmod -R +x /usr/local/bin",
  110. ]
  111. }
  112. provisioner "remote-exec" {
  113. inline = [
  114. "mkdir -p /tmp/scripts",
  115. ]
  116. }
  117. provisioner "file" {
  118. source = "${path.module}/scripts/"
  119. destination = "/tmp/scripts"
  120. }
  121. provisioner "remote-exec" {
  122. inline = [
  123. "chmod +x /tmp/scripts/*",
  124. "run-parts /tmp/scripts",
  125. ]
  126. }
  127. }