diff --git a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py
index bbc7e1ce6c6..9a692002c2b 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py
@@ -184,7 +184,7 @@ def subnet_to_dict(subnet):
         result['route_table']['name'] = id_keys['routeTables']
         result['route_table']['resource_group'] = id_keys['resourceGroups']
     if subnet.service_endpoints:
-        result['service_endpoints'] = [{'service': item.service, 'locations': item.locations} for item in subnet.service_endpoints]
+        result['service_endpoints'] = [{'service': item.service, 'locations': item.locations or []} for item in subnet.service_endpoints]
     return result
 
 
@@ -283,12 +283,14 @@ class AzureRMSubnet(AzureRMModuleBase):
                     oldd = {}
                     for item in self.service_endpoints:
                         name = item['service']
-                        oldd[name] = {'service': name, 'locations': item['locations'].sort()}
+                        locations = item.get('locations') or []
+                        oldd[name] = {'service': name, 'locations': locations.sort()}
                     newd = {}
                     if 'service_endpoints' in results:
                         for item in results['service_endpoints']:
                             name = item['service']
-                            newd[name] = {'service': name, 'locations': item['locations'].sort()}
+                            locations = item.get('locations') or []
+                            newd[name] = {'service': name, 'locations': locations.sort()}
                     if newd != oldd:
                         changed = True
                         results['service_endpoints'] = self.service_endpoints