From b9b52fe3e15e927f51bcde6dfb6d2a43d3534f18 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 17 Mar 2020 10:59:09 -0700 Subject: [PATCH] GA ILB global access (#3253) (#171) Signed-off-by: Modular Magician --- .../modules/gcp_compute_forwarding_rule.py | 26 +++++++++++++++++++ .../gcp_compute_forwarding_rule_info.py | 6 +++++ 2 files changed, 32 insertions(+) diff --git a/plugins/modules/gcp_compute_forwarding_rule.py b/plugins/modules/gcp_compute_forwarding_rule.py index 1193200..215e21c 100644 --- a/plugins/modules/gcp_compute_forwarding_rule.py +++ b/plugins/modules/gcp_compute_forwarding_rule.py @@ -179,6 +179,13 @@ options: required: false type: str version_added: '2.7' + allow_global_access: + description: + - If true, clients can access ILB from all regions. + - Otherwise only allows from the local region the ILB is located at. + required: false + type: bool + version_added: '2.10' all_ports: description: - For internal TCP/UDP load balancing (i.e. load balancing scheme is INTERNAL @@ -423,6 +430,12 @@ target: - The forwarded traffic must be of a type appropriate to the target object. returned: success type: str +allowGlobalAccess: + description: + - If true, clients can access ILB from all regions. + - Otherwise only allows from the local region the ILB is located at. + returned: success + type: bool allPorts: description: - For internal TCP/UDP load balancing (i.e. load balancing scheme is INTERNAL and @@ -494,6 +507,7 @@ def main(): ports=dict(type='list', elements='str'), subnetwork=dict(type='dict'), target=dict(type='str'), + allow_global_access=dict(type='bool'), all_ports=dict(type='bool'), network_tier=dict(type='str'), service_label=dict(type='str'), @@ -545,6 +559,8 @@ def update(module, link, kind, fetch): def update_fields(module, request, response): if response.get('target') != request.get('target'): target_update(module, request, response) + if response.get('allowGlobalAccess') != request.get('allowGlobalAccess'): + allow_global_access_update(module, request, response) def target_update(module, request, response): @@ -555,6 +571,14 @@ def target_update(module, request, response): ) +def allow_global_access_update(module, request, response): + auth = GcpSession(module, 'compute') + auth.patch( + ''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/forwardingRules/{name}"]).format(**module.params), + {u'allowGlobalAccess': module.params.get('allow_global_access')}, + ) + + def delete(module, link, kind): auth = GcpSession(module, 'compute') return wait_for_operation(module, auth.delete(link)) @@ -574,6 +598,7 @@ def resource_to_request(module): u'ports': module.params.get('ports'), u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink'), u'target': module.params.get('target'), + u'allowGlobalAccess': module.params.get('allow_global_access'), u'allPorts': module.params.get('all_ports'), u'networkTier': module.params.get('network_tier'), u'serviceLabel': module.params.get('service_label'), @@ -655,6 +680,7 @@ def response_to_hash(module, response): u'ports': response.get(u'ports'), u'subnetwork': response.get(u'subnetwork'), u'target': response.get(u'target'), + u'allowGlobalAccess': response.get(u'allowGlobalAccess'), u'allPorts': response.get(u'allPorts'), u'networkTier': module.params.get('network_tier'), u'serviceLabel': response.get(u'serviceLabel'), diff --git a/plugins/modules/gcp_compute_forwarding_rule_info.py b/plugins/modules/gcp_compute_forwarding_rule_info.py index d720341..efa9a54 100644 --- a/plugins/modules/gcp_compute_forwarding_rule_info.py +++ b/plugins/modules/gcp_compute_forwarding_rule_info.py @@ -240,6 +240,12 @@ resources: - The forwarded traffic must be of a type appropriate to the target object. returned: success type: str + allowGlobalAccess: + description: + - If true, clients can access ILB from all regions. + - Otherwise only allows from the local region the ILB is located at. + returned: success + type: bool allPorts: description: - For internal TCP/UDP load balancing (i.e. load balancing scheme is INTERNAL