Repository: ansible/ansible

Issue:
ec2_elb_lb: Ansible didn't detect "scheme" change
_From @ralfbergs on August 12, 2016 20:44_

<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Feature Idea
##### COMPONENT NAME

ec2_elb_lb
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.1.1.0
  config file = /Users/rabe/Documents/Projects/IoT/Design/Devel/Env-Setup/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
##### OS / ENVIRONMENT

N/A
##### SUMMARY

Changed the scheme from `internal` to `internet-facing`, and Ansible didn't detect that it had to change the state, i. e. perform some work.
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

Originally had the following:

```
    - name: Create Elastic Load Balancer for frontend
      ec2_elb_lb:
        name: "{{ owner }}-elb-{{ env }}-fe"
        region: "{{ region }}"
        subnets:
          - "{{ mgmt_subnet_fe_1 }}"
          - "{{ mgmt_subnet_fe_2 }}"
        state: present
        scheme: internal
        cross_az_load_balancing: yes
        listeners:
          - protocol: http
            instance_protocol: http
            load_balancer_port: 80
            instance_port: 80
        health_check:
          ping_protocol: http # options are http, https, ssl, tcp
          ping_port: 80
          ping_path: "/index.html" # not required for tcp or ssl
          response_timeout: 5 # seconds
          interval: 30 # seconds
          unhealthy_threshold: 2
          healthy_threshold: 10
        instance_ids:
          - "{{ mgmt_i_fe_1.tagged_instances[0].id }}"
          - "{{ mgmt_i_fe_2.tagged_instances[0].id }}"
        tags:
          Name: "{{ owner }}_elb_{{ env }}_fe"
          Env: "{{ owner }}_{{ env }}"
          Tier: "{{ owner }}_{{ env }}_frontend"
```

Changed the above "scheme" line as follows:

```
        scheme: internet-facing
```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

I expected that Ansible noticed it had to change the ELB config.
##### ACTUAL RESULTS

Ansible did _not_ notice it got work to do. I had to manually remove the ELB and re-run the playbook.


_Copied from original issue: ansible/ansible-modules-core#4414_
ec2_elb_lb: Ansible didn't detect "scheme" change
_From @ralfbergs on August 12, 2016 20:44_

<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Feature Idea
##### COMPONENT NAME

ec2_elb_lb
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.1.1.0
  config file = /Users/rabe/Documents/Projects/IoT/Design/Devel/Env-Setup/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
##### OS / ENVIRONMENT

N/A
##### SUMMARY

Changed the scheme from `internal` to `internet-facing`, and Ansible didn't detect that it had to change the state, i. e. perform some work.
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

Originally had the following:

```
    - name: Create Elastic Load Balancer for frontend
      ec2_elb_lb:
        name: "{{ owner }}-elb-{{ env }}-fe"
        region: "{{ region }}"
        subnets:
          - "{{ mgmt_subnet_fe_1 }}"
          - "{{ mgmt_subnet_fe_2 }}"
        state: present
        scheme: internal
        cross_az_load_balancing: yes
        listeners:
          - protocol: http
            instance_protocol: http
            load_balancer_port: 80
            instance_port: 80
        health_check:
          ping_protocol: http # options are http, https, ssl, tcp
          ping_port: 80
          ping_path: "/index.html" # not required for tcp or ssl
          response_timeout: 5 # seconds
          interval: 30 # seconds
          unhealthy_threshold: 2
          healthy_threshold: 10
        instance_ids:
          - "{{ mgmt_i_fe_1.tagged_instances[0].id }}"
          - "{{ mgmt_i_fe_2.tagged_instances[0].id }}"
        tags:
          Name: "{{ owner }}_elb_{{ env }}_fe"
          Env: "{{ owner }}_{{ env }}"
          Tier: "{{ owner }}_{{ env }}_frontend"
```

Changed the above "scheme" line as follows:

```
        scheme: internet-facing
```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

I expected that Ansible noticed it had to change the ELB config.
##### ACTUAL RESULTS

Ansible did _not_ notice it got work to do. I had to manually remove the ELB and re-run the playbook.


_Copied from original issue: ansible/ansible-modules-core#4414_


Discussion:
_From @ansibot on August 12, 2016 20:45_

<!-- @ralfbergs: Thanks for filing this bug report! -->

@jsdalton ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

_From @ansibot on September 8, 2016 18:58_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on October 5, 2016 15:18_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on October 21, 2016 8:42_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on November 6, 2016 9:40_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on November 22, 2016 9:49_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_renotify_maintainer --->
_From @ansibot on December 7, 2016 18:3_

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the <a href="http://docs.ansible.com/ansible/dev_guide/repomerge.html#move-issues-and-prs-to-new-repo">repomerge</a> page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

<!-- boilerplate: repomerge -->
I'm updating this PR to be a feature request because updating the scheme parameter requires replacing the elb resource.
_From @ansibot on August 12, 2016 20:45_

<!-- @ralfbergs: Thanks for filing this bug report! -->

@jsdalton ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

_From @ansibot on September 8, 2016 18:58_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on October 5, 2016 15:18_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on October 21, 2016 8:42_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on November 6, 2016 9:40_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->

_From @ansibot on November 22, 2016 9:49_

@jsdalton, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_renotify_maintainer --->
_From @ansibot on December 7, 2016 18:3_

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the <a href="http://docs.ansible.com/ansible/dev_guide/repomerge.html#move-issues-and-prs-to-new-repo">repomerge</a> page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

<!-- boilerplate: repomerge -->
I'm updating this PR to be a feature request because updating the scheme parameter requires replacing the elb resource.

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py b/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py
--- a/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_elb_lb.py
@@ -108,6 +108,9 @@
   scheme:
     description:
       - The scheme to use when creating the ELB. For a private VPC-visible ELB use 'internal'.
+        If you choose to update your scheme with a different value the ELB will be destroyed and
+        recreated. To update scheme you must use the option wait.
+    choices: ["internal", "internet-facing"]
     required: false
     default: 'internet-facing'
     version_added: "1.7"
@@ -487,10 +490,15 @@ def ensure_ok(self):
             # Zones and listeners will be added at creation
             self._create_elb()
         else:
-            self._set_zones()
-            self._set_security_groups()
-            self._set_elb_listeners()
-            self._set_subnets()
+            if self._get_scheme():
+                # the only way to change the scheme is by recreating the resource
+                self.ensure_gone()
+                self._create_elb()
+            else:
+                self._set_zones()
+                self._set_security_groups()
+                self._set_elb_listeners()
+                self._set_subnets()
         self._set_health_check()
         # boto has introduced support for some ELB attributes in
         # different versions, so we check first before trying to
@@ -871,6 +879,15 @@ def _set_subnets(self):
             if subnets_to_detach:
                 self._detach_subnets(subnets_to_detach)
 
+    def _get_scheme(self):
+        """Determine if the current scheme is different than the scheme of the ELB"""
+        if self.scheme:
+            if self.elb.scheme != self.scheme:
+                if not self.wait:
+                    self.module.fail_json(msg="Unable to modify scheme without using the wait option")
+                return True
+        return False
+
     def _set_zones(self):
         """Determine which zones need to be enabled or disabled on the ELB"""
         if self.zones:
@@ -1244,7 +1261,7 @@ def main():
         health_check={'default': None, 'required': False, 'type': 'dict'},
         subnets={'default': None, 'required': False, 'type': 'list'},
         purge_subnets={'default': False, 'required': False, 'type': 'bool'},
-        scheme={'default': 'internet-facing', 'required': False},
+        scheme={'default': 'internet-facing', 'required': False, 'choices': ['internal', 'internet-facing']},
         connection_draining_timeout={'default': None, 'required': False, 'type': 'int'},
         idle_timeout={'default': None, 'type': 'int', 'required': False},
         cross_az_load_balancing={'default': None, 'type': 'bool', 'required': False},


Test patch: