Repository: ansible/ansible

Issue:
ec2_vpc_igw no longer returns gateway_id
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
amazon/ec2_vpc_igw

##### ANSIBLE VERSION
Devel branch head.
```
ansible 2.4.0
  config file = /opt/ansible/ansible.cfg
  configured module search path = [u'./library/ansible-modules-core', u'/usr/share/ansible']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```
##### CONFIGURATION
Default

##### OS / ENVIRONMENT
Linux

##### SUMMARY
ec2_vpc_igw returns a gateway_id using the stable Ansible, and according to the documentation should https://docs.ansible.com/ansible/ec2_vpc_igw_module.html#examples

The latest devel branch returns an `id` instead of `gateway_id`.

It seems likely that https://github.com/ansible/ansible/pull/23782 has introduced this change.

It could be that this change is intentional and the old behavior can no longer be supported, but if so it would be good to update the docs (which state gateway_id even in the devel branch docs: https://github.com/brandond/ansible/blob/devel/lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py#L50) and note the API change in the changelog perhaps.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Test VPC Gateway ID fetch
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - name: Locate main gateway
    ec2_vpc_igw:
      vpc_id: [INSERT A VALID VPC ID]
      state: present
    register: vpc_igw
  - debug: var=vpc_igw.gateway_id
```

##### EXPECTED RESULTS
With Ansible stable (i.e. 2.3.1.0)
```
PLAY [Test VPC Gateway ID fetch] *****************************************************************************************************************************************

TASK [Locate main gateway] ***********************************************************************************************************************************************
ok: [localhost]

TASK [debug] *************************************************************************************************************************************************************
ok: [localhost] => {
    "vpc_igw.gateway_id": "igw-xxxxxxxx"
}                                                                                    
```

Specifically, ec2_vpc_igw returns:
```
    "gateway_id": "igw-xxxxxxxx", 
```
##### ACTUAL RESULTS

Using Ansible devel branch (reports 2.4.0):
```
PLAY [Test VPC Gateway ID fetch] ***************************************************************************
                                                                                                            
TASK [Locate main gateway] *********************************************************************************
changed: [localhost]                                                                                        
                                                                                                            
TASK [debug] ***********************************************************************************************
ok: [localhost] => {                                                                                        
    "failed": false,                                                                                        
    "vpc_igw.gateway_id": "VARIABLE IS NOT DEFINED!"                                                        
}                                                                                                           
```

Specifically, ec2_vpc_igw returns:
```
    "gateway": {
        "id": "igw-xxxxxxxx", 
        "tags": {}, 
        "vpc_id": "vpc-yyyyyyyy"
    }, 
```
ec2_vpc_igw no longer returns gateway_id
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
amazon/ec2_vpc_igw

##### ANSIBLE VERSION
Devel branch head.
```
ansible 2.4.0
  config file = /opt/ansible/ansible.cfg
  configured module search path = [u'./library/ansible-modules-core', u'/usr/share/ansible']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```
##### CONFIGURATION
Default

##### OS / ENVIRONMENT
Linux

##### SUMMARY
ec2_vpc_igw returns a gateway_id using the stable Ansible, and according to the documentation should https://docs.ansible.com/ansible/ec2_vpc_igw_module.html#examples

The latest devel branch returns an `id` instead of `gateway_id`.

It seems likely that https://github.com/ansible/ansible/pull/23782 has introduced this change.

It could be that this change is intentional and the old behavior can no longer be supported, but if so it would be good to update the docs (which state gateway_id even in the devel branch docs: https://github.com/brandond/ansible/blob/devel/lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py#L50) and note the API change in the changelog perhaps.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Test VPC Gateway ID fetch
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - name: Locate main gateway
    ec2_vpc_igw:
      vpc_id: [INSERT A VALID VPC ID]
      state: present
    register: vpc_igw
  - debug: var=vpc_igw.gateway_id
```

##### EXPECTED RESULTS
With Ansible stable (i.e. 2.3.1.0)
```
PLAY [Test VPC Gateway ID fetch] *****************************************************************************************************************************************

TASK [Locate main gateway] ***********************************************************************************************************************************************
ok: [localhost]

TASK [debug] *************************************************************************************************************************************************************
ok: [localhost] => {
    "vpc_igw.gateway_id": "igw-xxxxxxxx"
}                                                                                    
```

Specifically, ec2_vpc_igw returns:
```
    "gateway_id": "igw-xxxxxxxx", 
```
##### ACTUAL RESULTS

Using Ansible devel branch (reports 2.4.0):
```
PLAY [Test VPC Gateway ID fetch] ***************************************************************************
                                                                                                            
TASK [Locate main gateway] *********************************************************************************
changed: [localhost]                                                                                        
                                                                                                            
TASK [debug] ***********************************************************************************************
ok: [localhost] => {                                                                                        
    "failed": false,                                                                                        
    "vpc_igw.gateway_id": "VARIABLE IS NOT DEFINED!"                                                        
}                                                                                                           
```

Specifically, ec2_vpc_igw returns:
```
    "gateway": {
        "id": "igw-xxxxxxxx", 
        "tags": {}, 
        "vpc_id": "vpc-yyyyyyyy"
    }, 
```


Discussion:
cc @willthames
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Yep, this seems like a genuine mistake that should be fixed. Will try and get around to it unless you fancy it @grugnog - fix is just to change `get_igw_info` to return a dict with a 'gateway_id' key rather than an 'id' key
cc @willthames
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Yep, this seems like a genuine mistake that should be fixed. Will try and get around to it unless you fancy it @grugnog - fix is just to change `get_igw_info` to return a dict with a 'gateway_id' key rather than an 'id' key

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py
--- a/lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py
@@ -62,6 +62,34 @@
 
 '''
 
+RETURN = '''
+changed:
+  description: If any changes have been made to the Internet Gateway.
+  type: bool
+  returned: always
+  sample:
+    changed: false
+gateway_id:
+  description: The unique identifier for the Internet Gateway.
+  type: str
+  returned: I(state=present)
+  sample:
+    gateway_id: "igw-XXXXXXXX"
+tags:
+  description: The tags associated the Internet Gateway.
+  type: dict
+  returned: I(state=present)
+  sample:
+    tags:
+      "Ansible": "Test"
+vpc_id:
+  description: The VPC ID associated with the Internet Gateway.
+  type: str
+  returned: I(state=present)
+  sample:
+    vpc_id: "vpc-XXXXXXXX"
+'''
+
 try:
     import boto.ec2
     import boto.vpc
@@ -82,7 +110,7 @@ class AnsibleIGWException(Exception):
 
 
 def get_igw_info(igw):
-    return {'id': igw.id,
+    return {'gateway_id': igw.id,
             'tags': igw.tags,
             'vpc_id': igw.vpc_id
             }
@@ -215,7 +243,7 @@ def main():
     except AnsibleIGWException as e:
         module.fail_json(msg=str(e))
 
-    module.exit_json(**result)
+    module.exit_json(changed=result['changed'], **result.get('gateway', {}))
 
 
 if __name__ == '__main__':


Test patch: