Repository: ansible/ansible

Issue:
ec2_vpc_net not idempotent when using variables in tags
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_vpc_net

##### ANSIBLE VERSION
```
ansible 2.6.0
  config file = /Users/sean/.ansible.cfg
  configured module search path = [u'/Users/sean/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Oct  6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
```

##### CONFIGURATION
```
DEFAULT_STDOUT_CALLBACK(/Users/sean/.ansible.cfg) = yaml
```

##### OS / ENVIRONMENT
macOS High Sierra 10.13.4

##### SUMMARY
when using variables within ec2 tags the module returns changed (yellow) even when running multiple times in a row (without the variable)

##### STEPS TO REPRODUCE
```yaml
- name: Perform Checks to make sure this Playbook will complete successfully
  hosts: localhost
  connection: local
  become: no
  gather_facts: no
  vars:
    ec2_name_prefix: SEAN-MAY9
    ec2_vpc_subnet: "172.16.0.0/16"
    ec2_region: us-east-1
    linklight_user: scavanaugh
    student_total: 1
  tasks:
    - name: Create AWS VPC SEAN-MAY9-vpc
      ec2_vpc_net:
        name: "{{ ec2_name_prefix }}-vpc"
        cidr_block: "{{ ec2_vpc_subnet }}"
        region: "{{ ec2_region }}"
        tags:
          Username: "{{ linklight_user }}"
          Info: "Username that provisioned this-> {{ linklight_user }}"
          Linklight: "This was provisioned through the linklight provisioner"
          Students: "{{student_total}}"
      register: create_vpc
      when: ec2_vpc_id is undefined
      until: create_vpc is not failed
      retries: 5
```


##### EXPECTED RESULTS
OK (green) without yellow changed

##### ACTUAL RESULTS
The playbook says Changed-> Yellow

```
TASK [Create AWS VPC SEAN-MAY9-vpc] *********************************************************************************************************************************************************************************
task path: /Users/sean/Desktop/ec2_modules.yml:13
Using module file /Library/Python/2.7/site-packages/ansible/modules/cloud/amazon/ec2_vpc_net.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: sean
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399 `" && echo ansible-tmp-1526402319.13-32210595629399="` echo /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399 `" ) && sleep 0'
<127.0.0.1> PUT /Users/sean/.ansible/tmp/ansible-local-480252UkIKf/tmpWszFdH TO /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399/ec2_vpc_net.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399/ /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399/ec2_vpc_net.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399/ec2_vpc_net.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/sean/.ansible/tmp/ansible-tmp-1526402319.13-32210595629399/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => changed=true
  attempts: 1
  invocation:
    module_args:
      aws_access_key: null
      aws_secret_key: null
      cidr_block:
      - 172.16.0.0/16
      dhcp_opts_id: null
      dns_hostnames: true
      dns_support: true
      ec2_url: null
      multi_ok: false
      name: SEAN-MAY9-vpc
      profile: null
      purge_cidrs: false
      region: us-east-1
      security_token: null
      state: present
      tags:
        Info: Username that provisioned this-> scavanaugh
        Linklight: This was provisioned through the linklight provisioner
        Name: SEAN-MAY9-vpc
        Students: 1
        Username: scavanaugh
      tenancy: default
      validate_certs: true
  vpc:
    cidr_block: 172.16.0.0/16
    cidr_block_association_set:
    - association_id: vpc-cidr-assoc-3733005a
      cidr_block: 172.16.0.0/16
      cidr_block_state:
        state: associated
    classic_link_enabled: false
    dhcp_options_id: dopt-e4da2281
    id: vpc-ca456bb1
    instance_tenancy: default
    is_default: false
    state: available
    tags:
      Info: Username that provisioned this-> scavanaugh
      Linklight: This was provisioned through the linklight provisioner
      Name: SEAN-MAY9-vpc
      Students: '1'
      Username: scavanaugh
```

if i manually substituted the variables into the tags, it will go green and be idempotent


Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/ec2_vpc_net.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @defionscode @s-hertel
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py
--- a/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_net.py
@@ -166,9 +166,10 @@
 
 from time import sleep, time
 from ansible.module_utils.aws.core import AnsibleAWSModule
-from ansible.module_utils.ec2 import (AWSRetry, camel_dict_to_snake_dict,
+from ansible.module_utils.ec2 import (AWSRetry, camel_dict_to_snake_dict, compare_aws_tags,
                                       ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict)
 from ansible.module_utils.six import string_types
+from ansible.module_utils._text import to_native
 
 
 def vpc_exists(module, vpc, name, cidr_block, multi):
@@ -229,16 +230,17 @@ def get_vpc(module, connection, vpc_id):
 
 
 def update_vpc_tags(connection, module, vpc_id, tags, name):
-
     if tags is None:
         tags = dict()
 
     tags.update({'Name': name})
+    tags = dict((k, to_native(v)) for k, v in tags.items())
     try:
         current_tags = dict((t['Key'], t['Value']) for t in connection.describe_tags(Filters=[{'Name': 'resource-id', 'Values': [vpc_id]}])['Tags'])
-        if tags != current_tags:
+        tags_to_update, dummy = compare_aws_tags(current_tags, tags, False)
+        if tags_to_update:
             if not module.check_mode:
-                tags = ansible_dict_to_boto3_tag_list(tags)
+                tags = ansible_dict_to_boto3_tag_list(tags_to_update)
                 vpc_obj = AWSRetry.backoff(
                     delay=1, tries=5,
                     catch_extra_error_codes=['InvalidVpcID.NotFound'],


Test patch: