Repository: ansible/ansible

Issue:
Try to update azure_rm_securitygroup : source_address_prefix
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->

`azure_rm_securitygroup`

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
2.4.0
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT

CentOS 7.3

Steps of the Ansible installation
```
sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel epel-release
sudo yum install -y python-pip python-wheel

sudo pip install ansible
sudo pip install ansible[azure]
sudo pip install dnspython
```

##### SUMMARY

Hello,

When I try to update network security group rules for Azure, in fact the option **source_address_prefix**, the value updated in the YML is not updated in Azure. However option like destination_port_range are updated when modified

##### 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 -->

Original YML

```yaml

  - name: Create security group that allows SSH and HTTP
    azure_rm_securitygroup: 
      resource_group: '{{ resourceGroup }}'
      name: 'NSG-{{ nsgName }}'
      purge_rules: yes
      state: present
      rules: 
        - name: SSH-Ansible
          protocol: Tcp
          destination_port_range: 22
          access: Allow
          priority: 100
          direction: Inbound
          source_address_prefix: 1.1.1.1


```

Modified YML

```yaml

  - name: Create security group that allows SSH and HTTP
    azure_rm_securitygroup: 
      resource_group: '{{ resourceGroup }}'
      name: 'NSG-{{ nsgName }}'
      purge_rules: yes
      state: present
      rules: 
        - name: SSH-Ansible
          protocol: Tcp
          destination_port_range: 22
          access: Allow
          priority: 100
          direction: Inbound
          source_address_prefix: 2.2.2.2


```
_strings in {{ }} are parameters passed with --extra-vars_

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS

The IP source has to be updated in Azure.

##### ACTUAL RESULTS

Nothing is updated



Discussion:
cc @haroldwongms @nitzmahone @tstringer
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @chouseknecht
[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/azure/azure_rm_securitygroup.py b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
--- a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
@@ -426,6 +426,9 @@ def compare_rules(r, rule):
         if rule['direction'] != r['direction']:
             changed = True
             r['direction'] = rule['direction']
+        if rule['source_address_prefix'] != str(r['source_address_prefix']):
+            changed = True
+            r['source_address_prefix'] = rule['source_address_prefix']
     return matched, changed
 
 


Test patch:
diff --git a/test/integration/targets/azure_rm_securitygroup/tasks/main.yml b/test/integration/targets/azure_rm_securitygroup/tasks/main.yml
--- a/test/integration/targets/azure_rm_securitygroup/tasks/main.yml
+++ b/test/integration/targets/azure_rm_securitygroup/tasks/main.yml
@@ -14,9 +14,9 @@
             access: Deny
             priority: 100
             direction: Inbound
-          - name: 'AllowSSH'
+          - name: AllowSSH
             protocol: Tcp
-            source_address_prefix: '174.109.158.0/24'
+            source_address_prefix: 174.109.158.0/24
             destination_port_range: 22
             access: Allow
             priority: 101
@@ -41,33 +41,38 @@
       resource_group: "{{ resource_group }}"
       name: mysecgroup
       rules:
-          - name: DenySSH
+          - name: AllowSSH
             protocol: Tcp
-            destination_port_range: 22-23
-            access: Deny
-            priority: 100
+            source_address_prefix: 174.108.158.0/24
+            destination_port_range: 22
+            access: Allow
+            priority: 101
           - name: AllowSSHFromHome
             protocol: Tcp
-            source_address_prefix: '174.109.158.0/24'
+            source_address_prefix: 174.109.158.0/24
             destination_port_range: 22-23
             priority: 102
   register: output
 
-- assert: { that: "{{ output.state.rules | length }} == 3" }
+- assert: 
+      that:
+          - "{{ output.state.rules | length }} == 3"
+          - output.state.rules[1].source_address_prefix == '174.108.158.0/24'
 
 - name: Test idempotence
   azure_rm_securitygroup:
       resource_group: "{{ resource_group }}"
       name: mysecgroup
       rules:
-          - name: DenySSH
+          - name: AllowSSH
             protocol: Tcp
-            destination_port_range: 22-23
-            access: Deny
-            priority: 100
+            source_address_prefix: 174.108.158.0/24
+            destination_port_range: 22
+            access: Allow
+            priority: 101
           - name: AllowSSHFromHome
             protocol: Tcp
-            source_address_prefix: '174.109.158.0/24'
+            source_address_prefix: 174.109.158.0/24
             destination_port_range: 22-23
             priority: 102
   register: output