Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add volume tags key with empty dict and test #383

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/383_ec2_snapshot_tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_snapshot - Fix snapshot issue when capturing a snapshot of a volume without tags (https://github.com/ansible-collections/amazon.aws/pull/383)
3 changes: 2 additions & 1 deletion plugins/modules/ec2_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def create_snapshot(module, ec2, description=None, wait=None,
volume_id = volume['VolumeId']
else:
volume = get_volume_by_id(module, ec2, volume_id)

if 'Tags' not in volume:
volume['Tags'] = {}
if last_snapshot_min_age > 0:
current_snapshots = get_snapshots_by_volume(module, ec2, volume_id)
last_snapshot_min_age = last_snapshot_min_age * 60 # Convert to seconds
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/targets/ec2_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@


block:
- name: Gather availability zones
aws_az_facts:
register: azs

# Create a new volume in detached mode without tags
- name: Create a detached volume without tags
ec2_vol:
volume_size: 1
zone: '{{ azs.availability_zones[0].zone_name }}'
register: volume_detached

# Capture snapshot of this detached volume and assert the results
- name: Create a snapshot of detached volume without tags and store results
ec2_snapshot:
volume_id: '{{ volume_detached.volume_id }}'
register: untagged_snapshot

- assert:
that:
- untagged_snapshot is changed
- untagged_snapshot.snapshots| length == 1
- untagged_snapshot.snapshots[0].volume_id == volume_detached.volume_id

- ec2_ami_info:
owners: amazon
filters:
Expand Down Expand Up @@ -340,3 +363,15 @@
id: '{{ volume_id }}'
state: absent
ignore_errors: true

- name: Delete detached and untagged volume
ec2_vol:
id: '{{ volume_detached.volume_id}}'
state: absent
ignore_errors: true

- name: Delete untagged snapshot
ec2_snapshot:
state: absent
snapshot_id: '{{ untagged_snapshot.snapshot_id }}'
ignore_errors: true