Repository: ansible/ansible

Issue:
elb_target_group does not hand off target port corectly
##### ISSUE TYPE
 - Bug Report


##### COMPONENT NAME
elb_target_group

##### ANSIBLE VERSION
```
ansible 2.4.1.0
  config file = None
  configured module search path = [u'/home/mmercer/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Sep  5 2017, 08:53:59) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]

```

##### CONFIGURATION
No output from ansible-config dump --only-changed

##### OS / ENVIRONMENT
Fedora 26, managing AWS ELB v2 (Application Load Balancer)

##### SUMMARY
Reading target port as a variable into a playbook results in a boto3 error -- Port[0] is being handed as a string not an int.

##### STEPS TO REPRODUCE
Using the var and task below as an example, try to create an ALB modification using a port from variable.

```yaml
vars.yml:
---
port: 9443
maybe_other_port: 9442

tasklist.yml
---
  - name: provision the new instance(s) in the ALB target group
    elb_target_group:
      name: sometestname
      port: "{{ maybe_other_port }}"
      protocol: https
      vpc_id: some-vpcid
      targets:
        - Id: ec2-instance-id
          Port: "{{ port }}" 
      modify_targets: yes
      state: present
  connection: local
  become: false
  run_once: true

```

##### EXPECTED RESULTS
Expect the task to modify the ALB target_group replacing port variable with port value 

##### ACTUAL RESULTS
Boto3 returns an error about 'str' instead of 'int'

```
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Invalid type for parameter Targets[0].Port, value: 9443, type: <type 'str'>, valid types: <type 'int'>, <type 'long'>                                                                                                                                                    
fatal: [10.1.16.63]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_PU04tX/ansible_module_elb_target_group.py\", line 672, in <module>\n    main()\n  File \"/tmp/ansible_PU04tX/ansible_module_elb_target_group.py\", line 667, in main\n    create_or_update_target_group(connection, module)
\n  File \"/tmp/ansible_PU04tX/ansible_module_elb_target_group.py\", line 465, in create_or_update_target_group\n    connection.register_targets(TargetGroupArn=tg['TargetGroupArn'], Targets=instances_to_add)\n  File \"/usr/lib/python2.7/site-packages/botocore/client.py\", line 312, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n  File \"
/usr/lib/python2.7/site-packages/botocore/client.py\", line 579, in _make_api_call\n    api_params, operation_model, context=request_context)\n  File \"/usr/lib/python2.7/site-packages/botocore/client.py\", line 634, in _convert_to_request_dict\n    api_params, operation_model)\n  File \"/usr/lib/python2.7/site-packages/botocore/validate.py\", line 291, in ser
ialize_to_request\n    raise ParamValidationError(report=report.generate_report())\nbotocore.exceptions.ParamValidationError: Parameter validation failed:\nInvalid type for parameter Targets[0].Port, value: 9443, type: <type 'str'>, valid types: <type 'int'>, <type 'long'>\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}  
```



Discussion:
@abadger Bug filed.  If you need any more data, let me know.
cc @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
This is fixed in latest devel branch
@wimnat Just tested against devel, still appears to be hitting this bug

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/elb_target_group.py b/lib/ansible/modules/cloud/amazon/elb_target_group.py
--- a/lib/ansible/modules/cloud/amazon/elb_target_group.py
+++ b/lib/ansible/modules/cloud/amazon/elb_target_group.py
@@ -459,7 +459,7 @@ def create_or_update_target_group(connection, module):
                     instances_to_add = []
                     for target in params['Targets']:
                         if target['Id'] in add_instances:
-                            instances_to_add.append(target)
+                            instances_to_add.append({'Id': target['Id'], 'Port': int(target['Port'])})
 
                     changed = True
                     try:


Test patch: