diff --git a/modules/aws/dcos b/modules/aws/dcos index 0c09598..f20c59c 160000 --- a/modules/aws/dcos +++ b/modules/aws/dcos @@ -1 +1 @@ -Subproject commit 0c095981707df048189b78ef326ff15a3e790887 +Subproject commit f20c59cdf05825fc1308ab325ea22e483c003f7d diff --git a/modules/aws/ebs/main.tf b/modules/aws/ebs/main.tf new file mode 100644 index 0000000..98636f8 --- /dev/null +++ b/modules/aws/ebs/main.tf @@ -0,0 +1,75 @@ +/** + * AWS EBS + * ======= + * This module creates additional ebs volumes and attaches them to the instances. + * + * EXAMPLE + * ------- + * + *```hcl + * module "instance-volume" { + * source = "dcos-terraform/ebs/aws" + * + * instances = ["id-ablsldhfa123", "id-aidrkdkek131"] + * num = "3" + * size = "500" + * type = "gp2" + * iops = "3000" + * } + *``` + */ + +provider "aws" {} + +data "aws_instance" "instance" { + count = "${var.num_instances}" + instance_id = "${element(var.instances, count.index)}" +} + +locals { + device_names = [ + "/dev/xvdi", + "/dev/xvdj", + "/dev/xvdk", + "/dev/xvdm", + "/dev/xvdn", + "/dev/xvdo", + "/dev/xvdp", + "/dev/xvdq", + "/dev/xvdr", + "/dev/xvds", + ] +} + +resource "aws_ebs_volume" "volume" { + # We group volumes from one instance first. For instance: + # - var.num = 2 + # - var.num_instances = 3 + # + # We will get: + # - volume.0 (instance 0) + # - volume.1 (instance 0) + # - volume.2 (instance 1) + # - volume.3 (instance 1) + # - volume.4 (instance 2) + # - volume.5 (instance 2) + count = "${var.num * var.num_instances}" + availability_zone = "${element(data.aws_instance.instance.*.availability_zone, count.index / (var.num > 0 ? var.num : 1))}" + size = "${var.size}" + type = "${var.type}" + iops = "${var.iops}" + + tags = "${merge(var.tags, map( + "Name", format(var.ebs_name_format, + var.cluster_name, + element(var.instances, count.index / (var.num > 0 ? var.num : 1))), + "Cluster", var.cluster_name))}" +} + +resource "aws_volume_attachment" "volume-attachment" { + count = "${var.num * var.num_instances}" + device_name = "${element(local.device_names, count.index % (var.num > 0 ? var.num : 1))}" + volume_id = "${element(aws_ebs_volume.volume.*.id, count.index)}" + instance_id = "${element(var.instances, count.index / (var.num > 0 ? var.num : 1))}" + force_detach = true +} diff --git a/modules/aws/ebs/outputs.tf b/modules/aws/ebs/outputs.tf new file mode 100644 index 0000000..1f6b401 --- /dev/null +++ b/modules/aws/ebs/outputs.tf @@ -0,0 +1,4 @@ +output "volumes" { + description = "List of volume IDs" + value = ["${aws_ebs_volume.volume.*.id}"] +} diff --git a/modules/aws/ebs/variables.tf b/modules/aws/ebs/variables.tf new file mode 100644 index 0000000..ab38743 --- /dev/null +++ b/modules/aws/ebs/variables.tf @@ -0,0 +1,42 @@ +variable "instances" { + description = "List of instance IDs" + type = "list" +} + +variable "num_instances" { + description = "Number of instances" +} + +variable "num" { + description = "The number of EBS volumes to create for each instance" +} + +variable "size" { + description = "The size in GB for each volume" + default = "120" +} + +variable "type" { + description = "The type for each volume" + default = "" +} + +variable "iops" { + description = "The iops for each volume" + default = "0" +} + +variable "cluster_name" { + description = "Name of the DC/OS cluster" +} + +variable "tags" { + description = "Add custom tags to all resources" + type = "map" + default = {} +} + +variable "ebs_name_format" { + description = "Printf style format for naming the EBS volume. Gets truncated to 32 characters. (input cluster_name and instance ID)" + default = "ebs-%s-%s" +} diff --git a/modules/aws/infrastructure b/modules/aws/infrastructure index cbe83dd..078f494 160000 --- a/modules/aws/infrastructure +++ b/modules/aws/infrastructure @@ -1 +1 @@ -Subproject commit cbe83dd9f04ddab8e767a124e46a56eae1e7ebf1 +Subproject commit 078f494dbe549e7c1296da94a9121ab953458de3 diff --git a/modules/aws/instance b/modules/aws/instance index ecc464e..1e3a74d 160000 --- a/modules/aws/instance +++ b/modules/aws/instance @@ -1 +1 @@ -Subproject commit ecc464e9c33249825ed5f6ba8c7d2856db700346 +Subproject commit 1e3a74d37499a9497bbdd847239a79116cb7835a diff --git a/modules/aws/private-agents b/modules/aws/private-agents index 240c9ec..d34acdf 160000 --- a/modules/aws/private-agents +++ b/modules/aws/private-agents @@ -1 +1 @@ -Subproject commit 240c9ecac8ffec89fbd6c30ebb8998ea7d4e5dfe +Subproject commit d34acdf1db646474fdb33ed1f6cef10e3b501254