From e2464b7687fdfe1dd9c42e9d9cb7c0018a93d815 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 1 Apr 2019 10:53:31 -0700 Subject: [PATCH] Terraform: Make private Cloud DNS GA (#224) /cc @drebes --- plugins/modules/gcp_dns_managed_zone.py | 74 ++++++++++++++++++- plugins/modules/gcp_dns_managed_zone_facts.py | 27 +++++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/plugins/modules/gcp_dns_managed_zone.py b/plugins/modules/gcp_dns_managed_zone.py index c6d29a0..5a54812 100644 --- a/plugins/modules/gcp_dns_managed_zone.py +++ b/plugins/modules/gcp_dns_managed_zone.py @@ -73,6 +73,35 @@ options: - A set of key/value label pairs to assign to this ManagedZone. required: false version_added: 2.8 + visibility: + description: + - 'The zone''s visibility: public zones are exposed to the Internet, while private + zones are visible only to Virtual Private Cloud resources.' + - 'Must be one of: `public`, `private`.' + required: false + default: public + version_added: 2.8 + choices: + - private + - public + private_visibility_config: + description: + - For privately visible zones, the set of Virtual Private Cloud resources that + the zone is visible from. + required: false + version_added: 2.8 + suboptions: + networks: + description: + - The list of VPC networks that can see this zone. + required: false + suboptions: + network_url: + description: + - The fully qualified URL of the VPC network to bind to. + - This should be formatted like `U(https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}`) + . + required: false extends_documentation_fragment: gcp notes: - 'API Reference: U(https://cloud.google.com/dns/api/v1/managedZones)' @@ -138,6 +167,33 @@ labels: - A set of key/value label pairs to assign to this ManagedZone. returned: success type: dict +visibility: + description: + - 'The zone''s visibility: public zones are exposed to the Internet, while private + zones are visible only to Virtual Private Cloud resources.' + - 'Must be one of: `public`, `private`.' + returned: success + type: str +privateVisibilityConfig: + description: + - For privately visible zones, the set of Virtual Private Cloud resources that the + zone is visible from. + returned: success + type: complex + contains: + networks: + description: + - The list of VPC networks that can see this zone. + returned: success + type: complex + contains: + networkUrl: + description: + - The fully qualified URL of the VPC network to bind to. + - This should be formatted like `U(https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}`) + . + returned: success + type: str ''' ################################################################################ @@ -163,6 +219,8 @@ def main(): 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'))))), ) ) @@ -208,7 +266,11 @@ def update(module, link, kind, fetch): def update_fields(module, request, response): - if response.get('description') != request.get('description') or response.get('labels') != request.get('labels'): + if ( + response.get('description') != request.get('description') + or response.get('labels') != request.get('labels') + or response.get('privateVisibilityConfig') != request.get('privateVisibilityConfig') + ): description_update(module, request, response) @@ -216,7 +278,11 @@ 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), - {u'description': module.params.get('description'), u'labels': module.params.get('labels')}, + { + u'description': module.params.get('description'), + u'labels': module.params.get('labels'), + u'privateVisibilityConfig': ManagedZonePrivatevisibilityconfig(module.params.get('private_visibility_config', {}), module).to_request(), + }, ) @@ -233,6 +299,8 @@ def resource_to_request(module): 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(), } return_vals = {} for k, v in request.items(): @@ -306,6 +374,8 @@ def response_to_hash(module, response): 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(), } diff --git a/plugins/modules/gcp_dns_managed_zone_facts.py b/plugins/modules/gcp_dns_managed_zone_facts.py index e5a8152..6e729da 100644 --- a/plugins/modules/gcp_dns_managed_zone_facts.py +++ b/plugins/modules/gcp_dns_managed_zone_facts.py @@ -108,6 +108,33 @@ items: - A set of key/value label pairs to assign to this ManagedZone. returned: success type: dict + visibility: + description: + - 'The zone''s visibility: public zones are exposed to the Internet, while private + zones are visible only to Virtual Private Cloud resources.' + - 'Must be one of: `public`, `private`.' + returned: success + type: str + privateVisibilityConfig: + description: + - For privately visible zones, the set of Virtual Private Cloud resources that + the zone is visible from. + returned: success + type: complex + contains: + networks: + description: + - The list of VPC networks that can see this zone. + returned: success + type: complex + contains: + networkUrl: + description: + - The fully qualified URL of the VPC network to bind to. + - This should be formatted like `U(https://www.googleapis.com/compute/v1/projects/{project}/global/networks/{network}`) + . + returned: success + type: str ''' ################################################################################