adding subnet service endpoints (#47549)

adding subnet service endpoints
This commit is contained in:
Zim Kalinowski 2018-10-25 13:43:47 +08:00 committed by GitHub
parent d79b6c8406
commit 1724b633f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View file

@ -68,6 +68,20 @@ options:
- The str can be the name or resource id of the route table. - The str can be the name or resource id of the route table.
- The dict can contains C(name) and C(resource_group) of the route_table. - The dict can contains C(name) and C(resource_group) of the route_table.
version_added: "2.7" version_added: "2.7"
service_endpoints:
description:
- An array of service endpoints.
type: list
suboptions:
service:
description:
- The type of the endpoint service.
required: True
locations:
description:
- A list of locations.
type: list
version_added: "2.8"
extends_documentation_fragment: extends_documentation_fragment:
- azure - azure
@ -169,6 +183,8 @@ def subnet_to_dict(subnet):
result['route_table']['id'] = subnet.route_table.id result['route_table']['id'] = subnet.route_table.id
result['route_table']['name'] = id_keys['routeTables'] result['route_table']['name'] = id_keys['routeTables']
result['route_table']['resource_group'] = id_keys['resourceGroups'] 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]
return result return result
@ -183,7 +199,10 @@ class AzureRMSubnet(AzureRMModuleBase):
virtual_network_name=dict(type='str', required=True, aliases=['virtual_network']), virtual_network_name=dict(type='str', required=True, aliases=['virtual_network']),
address_prefix_cidr=dict(type='str', aliases=['address_prefix']), address_prefix_cidr=dict(type='str', aliases=['address_prefix']),
security_group=dict(type='raw', aliases=['security_group_name']), security_group=dict(type='raw', aliases=['security_group_name']),
route_table=dict(type='raw') route_table=dict(type='raw'),
service_endpoints=dict(
type='list'
)
) )
required_if = [ required_if = [
@ -202,6 +221,7 @@ class AzureRMSubnet(AzureRMModuleBase):
self.address_prefix_cidr = None self.address_prefix_cidr = None
self.security_group = None self.security_group = None
self.route_table = None self.route_table = None
self.service_endpoints = None
super(AzureRMSubnet, self).__init__(self.module_arg_spec, super(AzureRMSubnet, self).__init__(self.module_arg_spec,
supports_check_mode=True, supports_check_mode=True,
@ -257,6 +277,21 @@ class AzureRMSubnet(AzureRMModuleBase):
changed = True changed = True
results['route_table']['id'] = self.route_table results['route_table']['id'] = self.route_table
self.log("CHANGED: subnet {0} route_table to {1}".format(self.name, route_table['name'])) self.log("CHANGED: subnet {0} route_table to {1}".format(self.name, route_table['name']))
if self.service_endpoints:
oldd = {}
for item in self.service_endpoints:
name = item['service']
oldd[name] = {'service': name, 'locations': item['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()}
if newd != oldd:
changed = True
results['service_endpoints'] = self.service_endpoints
elif self.state == 'absent': elif self.state == 'absent':
changed = True changed = True
except CloudError: except CloudError:
@ -291,6 +326,9 @@ class AzureRMSubnet(AzureRMModuleBase):
if self.route_table: if self.route_table:
subnet.route_table = self.network_models.RouteTable(id=self.route_table) subnet.route_table = self.network_models.RouteTable(id=self.route_table)
if self.service_endpoints:
subnet.service_endpoints = self.service_endpoints
self.results['state'] = self.create_or_update_subnet(subnet) self.results['state'] = self.create_or_update_subnet(subnet)
elif self.state == 'absent' and changed: elif self.state == 'absent' and changed:
# delete subnet # delete subnet

View file

@ -62,6 +62,11 @@
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0.0/16" address_prefix_cidr: "10.1.0.0/16"
security_group: secgroupfoo security_group: secgroupfoo
service_endpoints:
- service: Microsoft.Sql
locations:
- eastus
- westus
tags: tags:
testing: testing testing: testing
delete: on-fini delete: on-fini
@ -73,6 +78,11 @@
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
address_prefix_cidr: "10.1.0.0/16" address_prefix_cidr: "10.1.0.0/16"
security_group: secgroupfoo security_group: secgroupfoo
service_endpoints:
- service: Microsoft.Sql
locations:
- eastus
- westus
tags: tags:
testing: testing testing: testing
delete: on-fini delete: on-fini