forked from ansible-collections/amazon.aws
-
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.
Tagging - cleanup docs for ec2_snapshot_copy (ansible-collections#1201)
Tagging - ec2_snapshot_copy SUMMARY Add the "resource_tags" alias, for consistency with other modules minor docs clean-up Use TagSpecification on creation rather than making a separate API call to tag the resource after creation. Does not add purge_tags, since the module performs a one-shot action rather than managing the resources. ISSUE TYPE Docs Pull Request Feature Pull Request COMPONENT NAME ec2_snapshot_copy ADDITIONAL INFORMATION Since we don't have a tags-only fragment, I've not switched this over to using a fragment. If I find more modules with a similar use-case I'll try to find a standard fragment we can use. Reviewed-by: Alina Buzachis <None>
- Loading branch information
Showing
1 changed file
with
14 additions
and
13 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -11,9 +11,9 @@ | |
--- | ||
module: ec2_snapshot_copy | ||
version_added: 1.0.0 | ||
short_description: Copies an EC2 snapshot and returns the new Snapshot ID. | ||
short_description: Copies an EC2 snapshot and returns the new Snapshot ID | ||
description: | ||
- Copies an EC2 Snapshot from a source region to a destination region. | ||
- Copies an EC2 Snapshot from a source region to a destination region. | ||
options: | ||
source_region: | ||
description: | ||
|
@@ -40,7 +40,7 @@ | |
type: str | ||
wait: | ||
description: | ||
- Wait for the copied Snapshot to be in 'Available' state before returning. | ||
- Wait for the copied Snapshot to be in the C(Available) state before returning. | ||
type: bool | ||
default: 'no' | ||
wait_timeout: | ||
|
@@ -50,12 +50,14 @@ | |
type: int | ||
tags: | ||
description: | ||
- A hash/dictionary of tags to add to the new Snapshot; '{"key":"value"}' and '{"key":"value","key":"value"}' | ||
- A dictionary representing the tags to be applied to the newly created resource. | ||
type: dict | ||
author: Deepak Kothandan (@Deepakkothandan) <[email protected]> | ||
aliases: ['resource_tags'] | ||
author: | ||
- Deepak Kothandan (@Deepakkothandan) <[email protected]> | ||
extends_documentation_fragment: | ||
- amazon.aws.aws | ||
- amazon.aws.ec2 | ||
- amazon.aws.aws | ||
- amazon.aws.ec2 | ||
''' | ||
|
||
EXAMPLES = ''' | ||
|
@@ -112,6 +114,7 @@ | |
pass # Handled by AnsibleAWSModule | ||
|
||
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule | ||
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications | ||
|
||
|
||
def copy_snapshot(module, ec2): | ||
|
@@ -134,6 +137,9 @@ def copy_snapshot(module, ec2): | |
if module.params.get('kms_key_id'): | ||
params['KmsKeyId'] = module.params.get('kms_key_id') | ||
|
||
if module.params.get('tags'): | ||
params['TagSpecifications'] = boto3_tag_specifications(module.params.get('tags')) | ||
|
||
try: | ||
snapshot_id = ec2.copy_snapshot(**params)['SnapshotId'] | ||
if module.params.get('wait'): | ||
|
@@ -145,11 +151,6 @@ def copy_snapshot(module, ec2): | |
SnapshotIds=[snapshot_id], | ||
WaiterConfig=dict(Delay=delay, MaxAttempts=max_attempts) | ||
) | ||
if module.params.get('tags'): | ||
ec2.create_tags( | ||
Resources=[snapshot_id], | ||
Tags=[{'Key': k, 'Value': v} for k, v in module.params.get('tags').items()] | ||
) | ||
|
||
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: | ||
module.fail_json_aws(e, msg='An error occurred waiting for the snapshot to become available.') | ||
|
@@ -166,7 +167,7 @@ def main(): | |
kms_key_id=dict(type='str', required=False), | ||
wait=dict(type='bool', default=False), | ||
wait_timeout=dict(type='int', default=600), | ||
tags=dict(type='dict'), | ||
tags=dict(type='dict', aliases=['resource_tags']), | ||
) | ||
|
||
module = AnsibleAWSModule(argument_spec=argument_spec) | ||
|