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.

77 lines
1.4 KiB

  1. /**
  2. * Cluster on DO
  3. *
  4. */
  5. variable "name" {
  6. description = "The cluster name, e.g cdn"
  7. }
  8. variable "environment" {
  9. description = "Environment tag, e.g prod"
  10. }
  11. variable "image_id" {
  12. description = "Image ID"
  13. }
  14. variable "regions" {
  15. description = "Regions to launch in"
  16. type = "list"
  17. }
  18. variable "key_ids" {
  19. description = "SSH keys to use"
  20. type = "list"
  21. }
  22. variable "instance_size" {
  23. description = "The instance size to use, e.g 2gb"
  24. }
  25. variable "desired_capacity" {
  26. description = "Desired instance count"
  27. default = 3
  28. }
  29. #-----------------------
  30. # Instances
  31. resource "digitalocean_droplet" "cluster" {
  32. # set the image and instance type
  33. name = "${var.name}${count.index}"
  34. image = "${var.image_id}"
  35. size = "${var.instance_size}"
  36. # the `element` function handles modulo
  37. region = "${element(var.regions, count.index)}"
  38. ssh_keys = "${var.key_ids}"
  39. count = "${var.desired_capacity}"
  40. lifecycle = {
  41. prevent_destroy = false
  42. }
  43. }
  44. #-----------------------
  45. // The cluster name, e.g cdn
  46. output "name" {
  47. value = "${var.name}"
  48. }
  49. // The list of cluster instance ids
  50. output "instances" {
  51. value = ["${digitalocean_droplet.cluster.*.id}"]
  52. }
  53. // The list of cluster instance ips
  54. output "private_ips" {
  55. value = ["${digitalocean_droplet.cluster.*.ipv4_address_private}"]
  56. }
  57. // The list of cluster instance ips
  58. output "public_ips" {
  59. value = ["${digitalocean_droplet.cluster.*.ipv4_address}"]
  60. }