mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
[ec2_ami] Ensure name or image_id is provided for state=present (#38972)
Add integration tests for backward compatibility and ensuring name or image_id is provided
This commit is contained in:
parent
cdb79b0e3a
commit
e2aa1155ba
2 changed files with 30 additions and 2 deletions
|
@ -656,7 +656,7 @@ def main():
|
||||||
virtualization_type=dict(default='hvm'),
|
virtualization_type=dict(default='hvm'),
|
||||||
root_device_name=dict(),
|
root_device_name=dict(),
|
||||||
delete_snapshot=dict(default=False, type='bool'),
|
delete_snapshot=dict(default=False, type='bool'),
|
||||||
name=dict(default=''),
|
name=dict(),
|
||||||
wait=dict(type='bool', default=False),
|
wait=dict(type='bool', default=False),
|
||||||
wait_timeout=dict(default=900, type='int'),
|
wait_timeout=dict(default=900, type='int'),
|
||||||
description=dict(default=''),
|
description=dict(default=''),
|
||||||
|
@ -680,6 +680,11 @@ def main():
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Using a required_one_of=[['name', 'image_id']] overrides the message that should be provided by
|
||||||
|
# the required_if for state=absent, so check manually instead
|
||||||
|
if not any([module.params['image_id'], module.params['name']]):
|
||||||
|
module.fail_json(msg="one of the following is required: name, image_id")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
||||||
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||||
|
|
|
@ -87,6 +87,30 @@
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
- name: test clean failure if not providing image_id or name with state=present
|
||||||
|
ec2_ami:
|
||||||
|
ec2_region: '{{ec2_region}}'
|
||||||
|
ec2_access_key: '{{ec2_access_key}}'
|
||||||
|
ec2_secret_key: '{{ec2_secret_key}}'
|
||||||
|
security_token: '{{security_token}}'
|
||||||
|
instance_id: '{{ setup_instance.instance_ids[0] }}'
|
||||||
|
state: present
|
||||||
|
description: '{{ ec2_ami_description }}'
|
||||||
|
tags:
|
||||||
|
Name: '{{ ec2_ami_name }}_ami'
|
||||||
|
wait: yes
|
||||||
|
root_device_name: /dev/xvda
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: assert error message is helpful
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.failed
|
||||||
|
- "result.msg == 'one of the following is required: name, image_id'"
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
- name: create an image from the instance
|
- name: create an image from the instance
|
||||||
ec2_ami:
|
ec2_ami:
|
||||||
ec2_region: '{{ec2_region}}'
|
ec2_region: '{{ec2_region}}'
|
||||||
|
@ -295,7 +319,6 @@
|
||||||
security_token: '{{security_token}}'
|
security_token: '{{security_token}}'
|
||||||
state: present
|
state: present
|
||||||
image_id: '{{ result.image_id }}'
|
image_id: '{{ result.image_id }}'
|
||||||
name: '{{ ec2_ami_name }}_ami'
|
|
||||||
description: '{{ ec2_ami_description }}'
|
description: '{{ ec2_ami_description }}'
|
||||||
tags:
|
tags:
|
||||||
Name: '{{ ec2_ami_name }}_ami'
|
Name: '{{ ec2_ami_name }}_ami'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue