Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Enable ec2 volume types
Browse files Browse the repository at this point in the history
At the moment we default to EBSBlockDevice, we need to be able to allow SSD
for example:

  prod:
    master_zone: domain.io
    ec2:
      block_devices:
      - DeviceName: /dev/sda1
        VolumeSize: 30
        VolumeType: gp2

(Closes # 160)
  • Loading branch information
Niall Creech committed Nov 2, 2015
1 parent 314466e commit 22ca40a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -162,6 +162,10 @@ The ``ec2`` key configures the EC2 instances created by auto-scaling groups (ASG
The path of the linux device to attach the instance to
``VolumeSize``
Size in gigabytes of the EBS volume
``VolumeType (optional)``
The type of the volume to create. One of standard (default), gp2 or io1 (see `AWS API reference <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVolume.html>`_)
``Iops (Required for io1 type)``
The Iops value to assign to the io1 volume type.

Example::

Expand All @@ -172,6 +176,7 @@ The ``ec2`` key configures the EC2 instances created by auto-scaling groups (ASG
- DeviceName: /dev/sda1
VolumeSize: 10
- DeviceName: /dev/sdf
VolumeType: gp2
VolumeSize: 100

:``security_groups``:
Expand Down
19 changes: 17 additions & 2 deletions bootstrap_cfn/config.py
Expand Up @@ -865,9 +865,24 @@ def ec2(self):
devices = []
try:
for i in data['block_devices']:
device_name = i['DeviceName']
volume_size = i.get('VolumeSize', 20)
volume_type = i.get('VolumeType', 'standard')
iops = i.get('Iops', False)
# Check we have a permitted volume type
if volume_type not in ['standard', 'gp2', 'io1']:
raise errors.CfnConfigError("config: Volume type '%s' but must be one of standard', 'gp2' or 'io1"
% (volume_type))
# We need to specifiy iops if we have a volume type of io1
if volume_type == 'io1' and not iops:
raise errors.CfnConfigError("config: Volume type io1 must have Iops defined")

devices.append(BlockDeviceMapping(
DeviceName=i['DeviceName'],
Ebs=EBSBlockDevice(VolumeSize=i['VolumeSize']),
DeviceName=device_name,
Ebs=EBSBlockDevice(
VolumeType=volume_type,
VolumeSize=volume_size,
Iops=iops),
))
except KeyError:
devices.append(BlockDeviceMapping(
Expand Down
1 change: 1 addition & 0 deletions tests/sample-project.yaml
Expand Up @@ -15,6 +15,7 @@ dev:
- DeviceName: /dev/sda1
VolumeSize: 10
- DeviceName: /dev/sdf
VolumeType: gp2
VolumeSize: 10
security_groups:
AnotherSG:
Expand Down
1 change: 1 addition & 0 deletions tests/test.py
Expand Up @@ -29,6 +29,7 @@ def setUp(self):
'block_devices': [{'DeviceName': '/dev/sda1',
'VolumeSize': 10},
{'DeviceName': '/dev/sdf',
'VolumeType': 'gp2',
'VolumeSize': 10}],
'parameters': {'InstanceType': 't2.micro',
'KeyName': 'default'},
Expand Down
8 changes: 4 additions & 4 deletions tests/tests.py
Expand Up @@ -1295,11 +1295,11 @@ def test_ec2(self):
BlockDeviceMappings=[
{
"DeviceName": "/dev/sda1",
"Ebs": {"VolumeSize": 10}
"Ebs": {"Iops": False, "VolumeSize": 10, "VolumeType": "standard"}
},
{
"DeviceName": "/dev/sdf",
"Ebs": {"VolumeSize": 10}
"Ebs": {"Iops": False, "VolumeSize": 10, "VolumeType": "gp2"}
}
],
KeyName="default",
Expand Down Expand Up @@ -1345,11 +1345,11 @@ def test_launchconfig_userdata(self):
BlockDeviceMappings=[
{
"DeviceName": "/dev/sda1",
"Ebs": {"VolumeSize": 10}
"Ebs": {"Iops": False, "VolumeSize": 10, "VolumeType": "standard"}
},
{
"DeviceName": "/dev/sdf",
"Ebs": {"VolumeSize": 10}
"Ebs": {"Iops": False, "VolumeSize": 10, "VolumeType": "gp2"}
}
],
KeyName="default",
Expand Down

0 comments on commit 22ca40a

Please sign in to comment.