Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add labels and updates to DNS managed zone
Browse files Browse the repository at this point in the history
  • Loading branch information
drebes authored and rambleraptor committed Sep 5, 2019
1 parent 5e762dc commit 912e155
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
49 changes: 26 additions & 23 deletions plugins/modules/gcp_dns_managed_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
description:
- A mutable string of at most 1024 characters associated with this resource for
the user's convenience. Has no effect on the managed zone's function.
required: false
required: true
dns_name:
description:
- The DNS name of this managed zone, for instance "example.com.".
required: false
required: true
name:
description:
- User assigned name for this resource.
Expand All @@ -68,6 +68,11 @@
is a set of DNS name servers that all host the same ManagedZones. Most users
will leave this field unset.
required: false
labels:
description:
- A set of key/value label pairs to assign to this ManagedZone.
required: false
version_added: 2.8
extends_documentation_fragment: gcp
notes:
- 'API Reference: U(https://cloud.google.com/dns/api/v1/managedZones)'
Expand Down Expand Up @@ -128,6 +133,11 @@
- This is in RFC3339 text format.
returned: success
type: str
labels:
description:
- A set of key/value label pairs to assign to this ManagedZone.
returned: success
type: dict
'''

################################################################################
Expand All @@ -151,10 +161,8 @@ def main():
description=dict(required=True, type='str'),
dns_name=dict(required=True, type='str'),
name=dict(required=True, type='str'),
name_server_set=dict(type='str'),
labels=dict(type='dict'),
visibility=dict(default='public', type='str', choices=['private', 'public']),
private_visibility_config=dict(type='dict', options=dict(networks=dict(type='list', elements='dict', options=dict(network_url=dict(type='str'))))),
name_server_set=dict(type='list', elements='str'),
labels=dict(type='dict')
)
)

Expand All @@ -170,7 +178,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module), kind)
update(module, self_link(module), kind, fetch)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
Expand All @@ -195,28 +203,27 @@ def create(module, link, kind):


def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
if (
response.get('description') != request.get('description')
or response.get('labels') != request.get('labels')
or response.get('privateVisibilityConfig') != request.get('privateVisibilityConfig')
):
if response.get('description') != request.get('description') or response.get('labels') != request.get('labels'):
description_update(module, request, response)


def description_update(module, request, response):
auth = GcpSession(module, 'dns')
auth.patch(
''.join(["https://www.googleapis.com/dns/v1/", "projects/{project}/managedZones/{name}"]).format(**module.params),
''.join([
"https://www.googleapis.com/dns/v1/",
"projects/{project}/managedZones/{name}"
]).format(**module.params),
{
u'description': module.params.get('description'),
u'labels': module.params.get('labels'),
u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(module.params.get('private_visibility_config', {}), module).to_request(),
},
u'labels': module.params.get('labels')
}
)


Expand All @@ -232,9 +239,7 @@ def resource_to_request(module):
u'dnsName': module.params.get('dns_name'),
u'name': module.params.get('name'),
u'nameServerSet': module.params.get('name_server_set'),
u'labels': module.params.get('labels'),
u'visibility': module.params.get('visibility'),
u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(module.params.get('private_visibility_config', {}), module).to_request(),
u'labels': module.params.get('labels')
}
return_vals = {}
for k, v in request.items():
Expand Down Expand Up @@ -307,9 +312,7 @@ def response_to_hash(module, response):
u'nameServers': response.get(u'nameServers'),
u'nameServerSet': response.get(u'nameServerSet'),
u'creationTime': response.get(u'creationTime'),
u'labels': response.get(u'labels'),
u'visibility': response.get(u'visibility'),
u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(response.get(u'privateVisibilityConfig', {}), module).from_response(),
u'labels': response.get(u'labels')
}


Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/gcp_dns_managed_zone_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
- This is in RFC3339 text format.
returned: success
type: str
labels:
description:
- A set of key/value label pairs to assign to this ManagedZone.
returned: success
type: dict
'''

################################################################################
Expand Down

0 comments on commit 912e155

Please sign in to comment.