Repository: ansible/ansible

Issue:
ec2_customer_gateway should not require bgp_asn
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_customer_gateway

##### ANSIBLE VERSION
```
2.3.1.0
```
##### SUMMARY
The ec2_customer_module makes it mandatory to set bgp_asn because this is required when state=present. 
state is present by default, so bgp_asn is always required.
When creating a customer gateway in the AWS Console manualy, the bgp asn is only required, when routing is set to dynamic instead of static.
So the depenency between state and bgp_asn should be removed. Instead there should be a new parameter called "routing" with values static or dynamic.
Setting routing to dynamic should make it mandatory to set bgp_asn, not any other parameter.

##### STEPS TO REPRODUCE

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- ec2_customer_gateway:
    ip_address: 1.2.3.4
    name: IndianapolisOffice
    state: present
    region: us-east-1
  register: cgw
```

##### EXPECTED RESULTS
Create customer gateway

##### ACTUAL RESULTS

```
TASK [Create customer gateway] *************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "state is present but the following are missing: bgp_asn"}
```

ec2_customer_gateway should not require bgp_asn
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ec2_customer_gateway

##### ANSIBLE VERSION
```
2.3.1.0
```
##### SUMMARY
The ec2_customer_module makes it mandatory to set bgp_asn because this is required when state=present. 
state is present by default, so bgp_asn is always required.
When creating a customer gateway in the AWS Console manualy, the bgp asn is only required, when routing is set to dynamic instead of static.
So the depenency between state and bgp_asn should be removed. Instead there should be a new parameter called "routing" with values static or dynamic.
Setting routing to dynamic should make it mandatory to set bgp_asn, not any other parameter.

##### STEPS TO REPRODUCE

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- ec2_customer_gateway:
    ip_address: 1.2.3.4
    name: IndianapolisOffice
    state: present
    region: us-east-1
  register: cgw
```

##### EXPECTED RESULTS
Create customer gateway

##### ACTUAL RESULTS

```
TASK [Create customer gateway] *************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "state is present but the following are missing: bgp_asn"}
```



Discussion:
cc @MichaelBaydoun @michaelbaydoun
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @MichaelBaydoun @michaelbaydoun
[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_customer_gateway.py b/lib/ansible/modules/cloud/amazon/ec2_customer_gateway.py
--- a/lib/ansible/modules/cloud/amazon/ec2_customer_gateway.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_customer_gateway.py
@@ -47,6 +47,12 @@
     description:
       - Name of the customer gateway.
     required: true
+  routing:
+    description:
+      - The type of routing.
+    choices: ['static', 'dynamic']
+    default: dynamic
+    version_added: '2.4'
   state:
     description:
       - Create or terminate the Customer Gateway.
@@ -129,7 +135,7 @@
 
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.ec2 import (boto3_conn, camel_dict_to_snake_dict,
-        ec2_argument_spec, get_aws_connection_info)
+                                      ec2_argument_spec, get_aws_connection_info)
 
 
 class Ec2CustomerGatewayManager:
@@ -153,6 +159,8 @@ def ensure_cgw_absent(self, gw_id):
         return response
 
     def ensure_cgw_present(self, bgp_asn, ip_address):
+        if not bgp_asn:
+            bgp_asn = 65000
         response = self.ec2.create_customer_gateway(
             DryRun=False,
             Type='ipsec.1',
@@ -204,6 +212,7 @@ def main():
             bgp_asn=dict(required=False, type='int'),
             ip_address=dict(required=True),
             name=dict(required=True),
+            routing=dict(default='dynamic', choices=['dynamic', 'static']),
             state=dict(default='present', choices=['present', 'absent']),
         )
     )
@@ -211,7 +220,7 @@ def main():
     module = AnsibleModule(argument_spec=argument_spec,
                            supports_check_mode=True,
                            required_if=[
-                               ('state', 'present', ['bgp_asn'])
+                               ('routing', 'dynamic', ['bgp_asn'])
                            ]
                            )
 


Test patch:
diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt
--- a/test/sanity/pep8/legacy-files.txt
+++ b/test/sanity/pep8/legacy-files.txt
@@ -17,7 +17,6 @@ lib/ansible/modules/cloud/amazon/dynamodb_table.py
 lib/ansible/modules/cloud/amazon/ec2_ami.py
 lib/ansible/modules/cloud/amazon/ec2_ami_copy.py
 lib/ansible/modules/cloud/amazon/ec2_ami_find.py
-lib/ansible/modules/cloud/amazon/ec2_customer_gateway.py
 lib/ansible/modules/cloud/amazon/ec2_eip.py
 lib/ansible/modules/cloud/amazon/ec2_eni_facts.py
 lib/ansible/modules/cloud/amazon/ec2_key.py