-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: Add EBS extra volume support
Allow extra EBS volumes to be created for each AWS instance.
- Loading branch information
Showing
7 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
Submodule dcos
updated
from 0c0959 to f20c59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "volumes" { | ||
description = "List of volume IDs" | ||
value = ["${aws_ebs_volume.volume.*.id}"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
Submodule infrastructure
updated
from cbe83d to 078f49
Submodule instance
updated
from ecc464 to 1e3a74
Submodule private-agents
updated
from 240c9e to d34acd