This is a Terraform project to deploy DigitalOcean droplets for my LPI classes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. provider "digitalocean" {
  2. token = "${var.do_token}"
  3. }
  4. resource "digitalocean_volume" "centos_lpi" {
  5. count = "${var.count}"
  6. name = "${var.server_name["centos"]}-${count.index}.vol"
  7. region = "${var.region}"
  8. size = 20
  9. description = "Empty Volume"
  10. }
  11. resource "digitalocean_droplet" "centos_lpi" {
  12. count = "${var.count}"
  13. name = "${var.server_name["centos"]}-${count.index}.${var.domain}"
  14. image = "${var.images["centos"]}"
  15. size = "${var.size}"
  16. region = "${var.region}"
  17. ssh_keys = "${var.ssh_keys}"
  18. volume_ids = ["${element(digitalocean_volume.centos_lpi.*.id, count.index)}"]
  19. }
  20. resource "digitalocean_volume" "debian_lpi" {
  21. count = "${var.count}"
  22. name = "${var.server_name["debian"]}-${count.index}.vol"
  23. region = "${var.region}"
  24. size = 20
  25. description = "Empty Volume"
  26. }
  27. resource "digitalocean_droplet" "debian_lpi" {
  28. count = "${var.count}"
  29. name = "${var.server_name["debian"]}-${count.index}.${var.domain}"
  30. image = "${var.images["debian"]}"
  31. size = "${var.size}"
  32. region = "${var.region}"
  33. ssh_keys = "${var.ssh_keys}"
  34. volume_ids = ["${element(digitalocean_volume.debian_lpi.*.id, count.index)}"]
  35. }
  36. provider "dns" {
  37. update {
  38. server = "${var.dns_server}"
  39. key_name = "${var.dns_key_name}"
  40. key_algorithm = "hmac-sha512"
  41. key_secret = "${var.dns_key}"
  42. }
  43. }
  44. resource "dns_a_record_set" "centos_lpi" {
  45. count = "${var.count}"
  46. zone = "${var.domain}."
  47. name = "${var.server_name["centos"]}-${count.index}"
  48. addresses = ["${element(digitalocean_droplet.centos_lpi.*.ipv4_address, count.index)}"]
  49. ttl = 300
  50. provisioner "remote-exec" {
  51. inline = [
  52. "rndc sync -clean",
  53. ]
  54. connection {
  55. type = "ssh"
  56. host = "${var.dns_server}"
  57. user = "root"
  58. port = "3347"
  59. private_key = "${file("private.key")}"
  60. }
  61. }
  62. }
  63. resource "dns_a_record_set" "debian_lpi" {
  64. count = "${var.count}"
  65. zone = "${var.domain}."
  66. name = "${var.server_name["debian"]}-${count.index}"
  67. addresses = ["${element(digitalocean_droplet.debian_lpi.*.ipv4_address, count.index)}"]
  68. ttl = 300
  69. provisioner "remote-exec" {
  70. inline = [
  71. "rndc sync -clean",
  72. ]
  73. connection {
  74. type = "ssh"
  75. host = "${var.dns_server}"
  76. user = "root"
  77. port = "3347"
  78. private_key = "${file("private.key")}"
  79. }
  80. }
  81. }