From e9267bf6d6f40f6f6739f7beb8b1c10a0243b7ae Mon Sep 17 00:00:00 2001 From: Kevin C Date: Thu, 19 Dec 2019 12:45:22 -0500 Subject: [PATCH] Cloudformation info checkmode (#65958) * set supports_check_mode=True I don't see any reason why this module cannot run in check mode. The following API calls are made, none of which modify configurations All using boto3.client('cloudformation') describe_change_set describe_stacks describe_stack_events get_paginator get_stack_policy get_template list_change_sets list_stack_resources * duplicate cloudformation_info tasks with checkmode Duplicated all existing cloudformation_info tests and added check_mode: yes to them * delete duplicate empty line --- .../cloud/amazon/cloudformation_info.py | 2 +- .../targets/cloudformation/tasks/main.yml | 79 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/amazon/cloudformation_info.py b/lib/ansible/modules/cloud/amazon/cloudformation_info.py index ec06faa6803..f62b80235dd 100644 --- a/lib/ansible/modules/cloud/amazon/cloudformation_info.py +++ b/lib/ansible/modules/cloud/amazon/cloudformation_info.py @@ -297,7 +297,7 @@ def main(): stack_template=dict(required=False, default=False, type='bool'), stack_change_sets=dict(required=False, default=False, type='bool'), ) - module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=False) + module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) is_old_facts = module._name == 'cloudformation_facts' if is_old_facts: diff --git a/test/integration/targets/cloudformation/tasks/main.yml b/test/integration/targets/cloudformation/tasks/main.yml index 8d437511ef8..9e95f26ecb5 100644 --- a/test/integration/targets/cloudformation/tasks/main.yml +++ b/test/integration/targets/cloudformation/tasks/main.yml @@ -153,6 +153,24 @@ - "'stack_tags' in stack_info.cloudformation[stack_name]" - "stack_info.cloudformation[stack_name].stack_tags.Stack == stack_name" + - name: get stack details (checkmode) + cloudformation_info: + stack_name: "{{ stack_name }}" + register: stack_info + check_mode: yes + + - name: assert stack info + assert: + that: + - "'cloudformation' in stack_info" + - "stack_info.cloudformation | length == 1" + - "stack_name in stack_info.cloudformation" + - "'stack_description' in stack_info.cloudformation[stack_name]" + - "'stack_outputs' in stack_info.cloudformation[stack_name]" + - "'stack_parameters' in stack_info.cloudformation[stack_name]" + - "'stack_tags' in stack_info.cloudformation[stack_name]" + - "stack_info.cloudformation[stack_name].stack_tags.Stack == stack_name" + - name: get stack details (all_facts) cloudformation_info: stack_name: "{{ stack_name }}" @@ -168,6 +186,22 @@ - "'stack_resources' in stack_info.cloudformation[stack_name]" - "'stack_template' in stack_info.cloudformation[stack_name]" + - name: get stack details (all_facts) (checkmode) + cloudformation_info: + stack_name: "{{ stack_name }}" + all_facts: yes + register: stack_info + check_mode: yes + + - name: assert stack info + assert: + that: + - "'stack_events' in stack_info.cloudformation[stack_name]" + - "'stack_policy' in stack_info.cloudformation[stack_name]" + - "'stack_resource_list' in stack_info.cloudformation[stack_name]" + - "'stack_resources' in stack_info.cloudformation[stack_name]" + - "'stack_template' in stack_info.cloudformation[stack_name]" + # ==== Cloudformation tests (create changeset) ============================ # try to create a changeset by changing instance type @@ -204,6 +238,18 @@ that: - "'stack_change_sets' in stack_info.cloudformation[stack_name]" + - name: get stack details with changesets (checkmode) + cloudformation_info: + stack_name: "{{ stack_name }}" + stack_change_sets: True + register: stack_info + check_mode: yes + + - name: assert changesets in info + assert: + that: + - "'stack_change_sets' in stack_info.cloudformation[stack_name]" + # try to create an empty changeset by passing in unchanged template - name: create a changeset cloudformation: @@ -257,6 +303,17 @@ that: - "stack_info.cloudformation[stack_name].stack_description.enable_termination_protection" + - name: get stack details (checkmode) + cloudformation_info: + stack_name: "{{ stack_name }}" + register: stack_info + check_mode: yes + + - name: assert stack info + assert: + that: + - "stack_info.cloudformation[stack_name].stack_description.enable_termination_protection" + - name: set termination protection to false cloudformation: stack_name: "{{ stack_name }}" @@ -287,6 +344,17 @@ that: - "not stack_info.cloudformation[stack_name].stack_description.enable_termination_protection" + - name: get stack details (checkmode) + cloudformation_info: + stack_name: "{{ stack_name }}" + register: stack_info + check_mode: yes + + - name: assert stack info + assert: + that: + - "not stack_info.cloudformation[stack_name].stack_description.enable_termination_protection" + # ==== Cloudformation tests (delete stack tests) ========================== - name: delete cloudformation stack (check mode) @@ -351,6 +419,17 @@ that: - "not stack_info.cloudformation" + - name: get stack details (checkmode) + cloudformation_info: + stack_name: "{{ stack_name }}" + register: stack_info + check_mode: yes + + - name: assert stack info + assert: + that: + - "not stack_info.cloudformation" + # ==== Cleanup ============================================================ always: