| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: azure_rm_privateendpointdnszonegroup_info |
| 15 |
|
| 16 |
version_added: "1.10.0" |
| 17 |
|
| 18 |
short_description: Get private endpoint DNS zone group info. |
| 19 |
|
| 20 |
description: |
| 21 |
- Get facts for private endpoint DNS zone groups. |
| 22 |
|
| 23 |
options: |
| 24 |
name: |
| 25 |
description: |
| 26 |
- Limit results to a single private endpoint DNS zone group. |
| 27 |
type: str |
| 28 |
private_endpoint: |
| 29 |
description: |
| 30 |
- Name of private endpoint. |
| 31 |
type: str |
| 32 |
required: true |
| 33 |
resource_group: |
| 34 |
description: |
| 35 |
- Resource group of the private endpoint. |
| 36 |
type: str |
| 37 |
required: true |
| 38 |
|
| 39 |
extends_documentation_fragment: |
| 40 |
- azure.azcollection.azure |
| 41 |
|
| 42 |
author: |
| 43 |
- Ross Bender (@l3ender) |
| 44 |
''' |
| 45 |
|
| 46 |
EXAMPLES = ''' |
| 47 |
- name: Get specific DNS zone groups for a private endpoint |
| 48 |
azure_rm_privateendpointdnszonegroup_info: |
| 49 |
name: "my-zone-group" |
| 50 |
private_endpoint: "my-private-endpoint" |
| 51 |
resource_group: "my-resource-group" |
| 52 |
|
| 53 |
- name: Get all DNS zone groups for a private endpoint |
| 54 |
azure_rm_privateendpointdnszonegroup_info: |
| 55 |
private_endpoint: "my-private-endpoint" |
| 56 |
resource_group: "my-resource-group" |
| 57 |
''' |
| 58 |
|
| 59 |
RETURN = ''' |
| 60 |
groups: |
| 61 |
description: |
| 62 |
- List of private endpoint zone groups. |
| 63 |
returned: always |
| 64 |
type: complex |
| 65 |
contains: |
| 66 |
id: |
| 67 |
description: |
| 68 |
- Resource ID of the private endpoint zone group. |
| 69 |
sample: >- |
| 70 |
/subscriptions/xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/privateEndpoints/myPrivateEndpoint/ |
| 71 |
privateDnsZoneGroups/myZoneGroup |
| 72 |
returned: always |
| 73 |
type: str |
| 74 |
name: |
| 75 |
description: |
| 76 |
- Name of the private endpoint zone group. |
| 77 |
returned: always |
| 78 |
type: str |
| 79 |
sample: myZoneGroup |
| 80 |
private_dns_zone_configs: |
| 81 |
description: |
| 82 |
- List of zone configuration within the zone group. |
| 83 |
returned: always |
| 84 |
type: complex |
| 85 |
contains: |
| 86 |
name: |
| 87 |
description: |
| 88 |
- Name of the zone config. |
| 89 |
returned: always |
| 90 |
type: str |
| 91 |
sample: default |
| 92 |
private_dns_zone_id: |
| 93 |
description: |
| 94 |
- ID of the private DNS zone. |
| 95 |
returned: always |
| 96 |
type: str |
| 97 |
sample: >- |
| 98 |
/subscriptions/xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/ |
| 99 |
privateDnsZones/privatelink.postgres.database.azure.com |
| 100 |
record_sets: |
| 101 |
description: |
| 102 |
- List of DNS records for zone. |
| 103 |
returned: always |
| 104 |
type: complex |
| 105 |
contains: |
| 106 |
fqdn: |
| 107 |
description: |
| 108 |
- Fully qualified domain name of the record. |
| 109 |
returned: always |
| 110 |
type: str |
| 111 |
sample: myPostgreSqlSrv-123.privatelink.postgres.database.azure.com |
| 112 |
ip_addresses: |
| 113 |
description: |
| 114 |
- IP addresses for the record. |
| 115 |
returned: always |
| 116 |
type: list |
| 117 |
sample: ['10.1.0.4'] |
| 118 |
provisioning_state: |
| 119 |
description: |
| 120 |
- Provisioning state of the resource. |
| 121 |
returned: always |
| 122 |
type: str |
| 123 |
sample: Succeeded |
| 124 |
record_set_name: |
| 125 |
description: |
| 126 |
- Name of the record. |
| 127 |
returned: always |
| 128 |
type: str |
| 129 |
sample: myPostgreSqlSrv-123 |
| 130 |
record_type: |
| 131 |
description: |
| 132 |
- Type of record. |
| 133 |
returned: always |
| 134 |
type: str |
| 135 |
sample: A |
| 136 |
ttl: |
| 137 |
description: |
| 138 |
- Time to live value of the record. |
| 139 |
returned: always |
| 140 |
type: int |
| 141 |
sample: 10 |
| 142 |
provisioning_state: |
| 143 |
description: |
| 144 |
- Provisioning state of the resource. |
| 145 |
returned: always |
| 146 |
type: str |
| 147 |
sample: Succeeded |
| 148 |
''' |
| 149 |
|
| 150 |
try: |
| 151 |
from azure.core.exceptions import ResourceNotFoundError |
| 152 |
except Exception: |
| 153 |
|
| 154 |
pass |
| 155 |
|
| 156 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 157 |
|
| 158 |
|
| 159 |
class AzureRMPrivateEndpointDnsZoneGroupInfo(AzureRMModuleBase): |
| 160 |
|
| 161 |
def __init__(self): |
| 162 |
|
| 163 |
self.module_arg_spec = dict( |
| 164 |
name=dict(type="str"), |
| 165 |
private_endpoint=dict(type="str", required=True), |
| 166 |
resource_group=dict(type="str", required=True), |
| 167 |
) |
| 168 |
|
| 169 |
self.results = dict( |
| 170 |
changed=False, |
| 171 |
groups=[], |
| 172 |
) |
| 173 |
|
| 174 |
self.name = None |
| 175 |
self.private_endpoint = None |
| 176 |
self.resource_group = None |
| 177 |
self.results = dict( |
| 178 |
changed=False, |
| 179 |
) |
| 180 |
|
| 181 |
super(AzureRMPrivateEndpointDnsZoneGroupInfo, self).__init__(self.module_arg_spec, |
| 182 |
supports_check_mode=True, |
| 183 |
supports_tags=False, |
| 184 |
facts_module=True) |
| 185 |
|
| 186 |
def exec_module(self, **kwargs): |
| 187 |
for key in list(self.module_arg_spec.keys()): |
| 188 |
setattr(self, key, kwargs[key]) |
| 189 |
|
| 190 |
if self.name is not None: |
| 191 |
self.results["groups"] = self.get_item() |
| 192 |
else: |
| 193 |
self.results["groups"] = self.list_items() |
| 194 |
|
| 195 |
return self.results |
| 196 |
|
| 197 |
def get_item(self): |
| 198 |
self.log("Get properties for {0} in {1}".format(self.name, self.private_endpoint)) |
| 199 |
|
| 200 |
try: |
| 201 |
item = self.network_client.private_dns_zone_groups.get(resource_group_name=self.resource_group, |
| 202 |
private_endpoint_name=self.private_endpoint, |
| 203 |
private_dns_zone_group_name=self.name) |
| 204 |
return [self.zone_to_dict(item)] |
| 205 |
except ResourceNotFoundError: |
| 206 |
self.log("Could not get info for {0} in {1}".format(self.name, self.private_endpoint)) |
| 207 |
|
| 208 |
return [] |
| 209 |
|
| 210 |
def list_items(self): |
| 211 |
self.log("List all in {0}".format(self.private_endpoint)) |
| 212 |
try: |
| 213 |
items = self.network_client.private_dns_zone_groups.list(private_endpoint_name=self.private_endpoint, resource_group_name=self.resource_group) |
| 214 |
return [self.zone_to_dict(item) for item in items] |
| 215 |
except ResourceNotFoundError as exc: |
| 216 |
self.fail("Failed to list all items in {0}: {1}".format(self.private_endpoint, str(exc))) |
| 217 |
|
| 218 |
def zone_to_dict(self, zone): |
| 219 |
zone_dict = zone.as_dict() |
| 220 |
return dict( |
| 221 |
id=zone_dict.get("id"), |
| 222 |
name=zone_dict.get("name"), |
| 223 |
private_dns_zone_configs=[self.zone_config_to_dict(zone_config) for zone_config in zone_dict.get("private_dns_zone_configs", [])], |
| 224 |
provisioning_state=zone_dict.get("provisioning_state"), |
| 225 |
) |
| 226 |
|
| 227 |
def zone_config_to_dict(self, zone_config): |
| 228 |
return dict( |
| 229 |
id=zone_config.get("id"), |
| 230 |
name=zone_config.get("name"), |
| 231 |
private_dns_zone_id=zone_config.get("private_dns_zone_id"), |
| 232 |
record_sets=[self.record_set_to_dict(record_set) for record_set in zone_config.get("record_sets", [])], |
| 233 |
) |
| 234 |
|
| 235 |
def record_set_to_dict(self, record_set): |
| 236 |
return dict( |
| 237 |
fqdn=record_set.get("fqdn"), |
| 238 |
ip_addresses=record_set.get("ip_addresses"), |
| 239 |
provisioning_state=record_set.get("provisioning_state"), |
| 240 |
record_set_name=record_set.get("record_set_name"), |
| 241 |
record_type=record_set.get("record_type"), |
| 242 |
ttl=record_set.get("ttl"), |
| 243 |
) |
| 244 |
|
| 245 |
|
| 246 |
def main(): |
| 247 |
AzureRMPrivateEndpointDnsZoneGroupInfo() |
| 248 |
|
| 249 |
|
| 250 |
if __name__ == "__main__": |
| 251 |
main() |