ec2: Fix bug with EBS creation when no tags were specified

Also make the creation params a little more modular
This commit is contained in:
Anders Ingemann 2018-07-19 13:00:38 +02:00
parent 2d64ddb867
commit 7a845fcd81
No known key found for this signature in database
GPG key ID: 16A5864B259E59CD

View file

@ -13,14 +13,18 @@ class EBSVolume(Volume):
tags = e.tags
size = self.size.bytes.get_qty_in('GiB')
params = dict(Size=size,
AvailabilityZone=zone,
VolumeType='gp2',
TagSpecifications=[{'ResourceType': 'volume', 'Tags': tags}],
Encrypted=e.encrypted)
params = {
'Size': size,
'AvailabilityZone': zone,
'VolumeType': 'gp2',
}
if len(tags) > 0:
params['TagSpecifications'] = [{'ResourceType': 'volume', 'Tags': tags}]
if e.encrypted and e.kms_key_id:
params['KmsKeyId'] = e.kms_key_id
if e.encrypted:
params['Encrypted'] = e.encrypted
if e.kms_key_id:
params['KmsKeyId'] = e.kms_key_id
self.volume = self.conn.create_volume(**params)