diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py index 88016982fb..f52a781459 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py @@ -165,7 +165,8 @@ except ImportError: pass # Handled by AnsibleAWSModule from ansible.module_utils.aws.core import AnsibleAWSModule -from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, ec2_argument_spec, ansible_dict_to_boto3_tag_list, camel_dict_to_snake_dict +from ansible.module_utils.ec2 import (boto3_conn, get_aws_connection_info, ec2_argument_spec, camel_dict_to_snake_dict, + ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict) from ansible.module_utils.six import string_types @@ -356,6 +357,7 @@ def main(): module.fail_json_aws(e, "Failed to update enabled dns hostnames attribute") final_state = camel_dict_to_snake_dict(get_vpc(module, connection, vpc_id)) + final_state['tags'] = boto3_tag_list_to_ansible_dict(final_state.get('tags', [])) final_state['id'] = final_state.pop('vpc_id') module.exit_json(changed=changed, vpc=final_state) diff --git a/test/integration/targets/ec2_vpc_net/tasks/main.yml b/test/integration/targets/ec2_vpc_net/tasks/main.yml index 9e8eb5d09f..74edfe7d02 100644 --- a/test/integration/targets/ec2_vpc_net/tasks/main.yml +++ b/test/integration/targets/ec2_vpc_net/tasks/main.yml @@ -250,6 +250,28 @@ # ============================================================ + - name: modify tags + ec2_vpc_net: + cidr_block: 20.0.0.0/24 + name: "{{ resource_prefix }}" + dns_support: True + dns_hostnames: True + state: present + multi_ok: no + tags: + Ansible: Test + <<: *aws_connection_info + register: result + + - name: assert the VPC has Name and Ansible tags + assert: + that: + - result.vpc.tags|length == 2 + - 'result.vpc.tags.Ansible == "Test"' + - 'result.vpc.tags.Name == "{{ resource_prefix }}"' + + # ============================================================ + - name: test check mode to delete a VPC ec2_vpc_net: cidr_block: 20.0.0.0/24