From 2a6c1e408e9fd9d94a3f476491849c2279dd0ca3 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 21 Sep 2018 10:57:51 -0700 Subject: [PATCH] Pubsub + DNS Facts (#75) /cc @rambleraptor --- .../gcp_compute_backend_bucket_facts.py | 6 +- .../gcp_compute_backend_service_facts.py | 6 +- plugins/modules/gcp_compute_firewall_facts.py | 6 +- .../gcp_compute_global_address_facts.py | 6 +- ...cp_compute_global_forwarding_rule_facts.py | 6 +- .../modules/gcp_compute_health_check_facts.py | 6 +- .../gcp_compute_http_health_check_facts.py | 6 +- .../gcp_compute_https_health_check_facts.py | 6 +- plugins/modules/gcp_compute_image_facts.py | 6 +- .../gcp_compute_instance_template_facts.py | 6 +- plugins/modules/gcp_compute_network_facts.py | 6 +- plugins/modules/gcp_compute_route_facts.py | 6 +- .../gcp_compute_ssl_certificate_facts.py | 6 +- .../modules/gcp_compute_ssl_policy_facts.py | 6 +- .../gcp_compute_target_http_proxy_facts.py | 6 +- .../gcp_compute_target_https_proxy_facts.py | 6 +- .../gcp_compute_target_ssl_proxy_facts.py | 6 +- .../gcp_compute_target_tcp_proxy_facts.py | 6 +- plugins/modules/gcp_compute_url_map_facts.py | 6 +- plugins/modules/gcp_dns_managed_zone_facts.py | 166 +++++++---------- .../gcp_dns_resource_record_set_facts.py | 118 ++++++------ plugins/modules/gcp_pubsub_subscription.py | 6 +- .../modules/gcp_pubsub_subscription_facts.py | 172 +++++++----------- plugins/modules/gcp_pubsub_topic_facts.py | 59 +++--- .../gcp_container_node_pool/tasks/main.yml | 8 +- .../tasks/main.yml | 26 +++ .../gcp_pubsub_subscription/tasks/main.yml | 4 +- .../gcp_pubsub_topic/tasks/main.yml | 4 +- tests/integration/gcp_sql_user/tasks/main.yml | 4 + 29 files changed, 366 insertions(+), 315 deletions(-) diff --git a/plugins/modules/gcp_compute_backend_bucket_facts.py b/plugins/modules/gcp_compute_backend_bucket_facts.py index c310bed..6239d87 100644 --- a/plugins/modules/gcp_compute_backend_bucket_facts.py +++ b/plugins/modules/gcp_compute_backend_bucket_facts.py @@ -131,7 +131,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_backend_service_facts.py b/plugins/modules/gcp_compute_backend_service_facts.py index f452ac1..f1319f4 100644 --- a/plugins/modules/gcp_compute_backend_service_facts.py +++ b/plugins/modules/gcp_compute_backend_service_facts.py @@ -213,7 +213,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_firewall_facts.py b/plugins/modules/gcp_compute_firewall_facts.py index 37befb1..cc8b30e 100644 --- a/plugins/modules/gcp_compute_firewall_facts.py +++ b/plugins/modules/gcp_compute_firewall_facts.py @@ -234,7 +234,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_global_address_facts.py b/plugins/modules/gcp_compute_global_address_facts.py index a5a1deb..3c008df 100644 --- a/plugins/modules/gcp_compute_global_address_facts.py +++ b/plugins/modules/gcp_compute_global_address_facts.py @@ -126,7 +126,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_global_forwarding_rule_facts.py b/plugins/modules/gcp_compute_global_forwarding_rule_facts.py index 18e1d56..b6f9851 100644 --- a/plugins/modules/gcp_compute_global_forwarding_rule_facts.py +++ b/plugins/modules/gcp_compute_global_forwarding_rule_facts.py @@ -178,7 +178,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_health_check_facts.py b/plugins/modules/gcp_compute_health_check_facts.py index cdf1299..9c5f83d 100644 --- a/plugins/modules/gcp_compute_health_check_facts.py +++ b/plugins/modules/gcp_compute_health_check_facts.py @@ -302,7 +302,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_http_health_check_facts.py b/plugins/modules/gcp_compute_http_health_check_facts.py index f0ebf72..45014c8 100644 --- a/plugins/modules/gcp_compute_http_health_check_facts.py +++ b/plugins/modules/gcp_compute_http_health_check_facts.py @@ -148,7 +148,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_https_health_check_facts.py b/plugins/modules/gcp_compute_https_health_check_facts.py index 66814ea..a9c7d5b 100644 --- a/plugins/modules/gcp_compute_https_health_check_facts.py +++ b/plugins/modules/gcp_compute_https_health_check_facts.py @@ -148,7 +148,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_image_facts.py b/plugins/modules/gcp_compute_image_facts.py index a253bc8..2ec2007 100644 --- a/plugins/modules/gcp_compute_image_facts.py +++ b/plugins/modules/gcp_compute_image_facts.py @@ -290,7 +290,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_instance_template_facts.py b/plugins/modules/gcp_compute_instance_template_facts.py index 6ee30d6..9471378 100644 --- a/plugins/modules/gcp_compute_instance_template_facts.py +++ b/plugins/modules/gcp_compute_instance_template_facts.py @@ -472,7 +472,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_network_facts.py b/plugins/modules/gcp_compute_network_facts.py index 61bea06..f1bce60 100644 --- a/plugins/modules/gcp_compute_network_facts.py +++ b/plugins/modules/gcp_compute_network_facts.py @@ -151,7 +151,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_route_facts.py b/plugins/modules/gcp_compute_route_facts.py index 21af987..b1108df 100644 --- a/plugins/modules/gcp_compute_route_facts.py +++ b/plugins/modules/gcp_compute_route_facts.py @@ -151,7 +151,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_ssl_certificate_facts.py b/plugins/modules/gcp_compute_ssl_certificate_facts.py index 215e8ae..2169eb0 100644 --- a/plugins/modules/gcp_compute_ssl_certificate_facts.py +++ b/plugins/modules/gcp_compute_ssl_certificate_facts.py @@ -115,7 +115,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_ssl_policy_facts.py b/plugins/modules/gcp_compute_ssl_policy_facts.py index 1d04b82..bc85282 100644 --- a/plugins/modules/gcp_compute_ssl_policy_facts.py +++ b/plugins/modules/gcp_compute_ssl_policy_facts.py @@ -153,7 +153,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_target_http_proxy_facts.py b/plugins/modules/gcp_compute_target_http_proxy_facts.py index 4f3537a..9675bd0 100644 --- a/plugins/modules/gcp_compute_target_http_proxy_facts.py +++ b/plugins/modules/gcp_compute_target_http_proxy_facts.py @@ -109,7 +109,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_target_https_proxy_facts.py b/plugins/modules/gcp_compute_target_https_proxy_facts.py index 1c95e46..6330dd8 100644 --- a/plugins/modules/gcp_compute_target_https_proxy_facts.py +++ b/plugins/modules/gcp_compute_target_https_proxy_facts.py @@ -132,7 +132,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_target_ssl_proxy_facts.py b/plugins/modules/gcp_compute_target_ssl_proxy_facts.py index ef787de..fadec07 100644 --- a/plugins/modules/gcp_compute_target_ssl_proxy_facts.py +++ b/plugins/modules/gcp_compute_target_ssl_proxy_facts.py @@ -128,7 +128,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_target_tcp_proxy_facts.py b/plugins/modules/gcp_compute_target_tcp_proxy_facts.py index fa86523..6ec9554 100644 --- a/plugins/modules/gcp_compute_target_tcp_proxy_facts.py +++ b/plugins/modules/gcp_compute_target_tcp_proxy_facts.py @@ -114,7 +114,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_compute_url_map_facts.py b/plugins/modules/gcp_compute_url_map_facts.py index 49782b0..930ef0d 100644 --- a/plugins/modules/gcp_compute_url_map_facts.py +++ b/plugins/modules/gcp_compute_url_map_facts.py @@ -210,7 +210,11 @@ import json def main(): - module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + filters=dict(type='list', elements='str') + ) + ) if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] diff --git a/plugins/modules/gcp_dns_managed_zone_facts.py b/plugins/modules/gcp_dns_managed_zone_facts.py index 6e729da..04618a2 100644 --- a/plugins/modules/gcp_dns_managed_zone_facts.py +++ b/plugins/modules/gcp_dns_managed_zone_facts.py @@ -18,123 +18,91 @@ # ---------------------------------------------------------------------------- from __future__ import absolute_import, division, print_function - __metaclass__ = type ################################################################################ # Documentation ################################################################################ -ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'} +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ["preview"], + 'supported_by': 'community'} DOCUMENTATION = ''' --- module: gcp_dns_managed_zone_facts description: -- Gather facts for GCP ManagedZone + - Gather facts for GCP ManagedZone short_description: Gather facts for GCP ManagedZone -version_added: 2.8 +version_added: 2.7 author: Google Inc. (@googlecloudplatform) requirements: -- python >= 2.6 -- requests >= 2.18.4 -- google-auth >= 1.3.0 + - python >= 2.6 + - requests >= 2.18.4 + - google-auth >= 1.3.0 options: - dns_name: - description: - - Restricts the list to return only zones with this domain name. + dns_name: + description: + Restricts the list to return only zones with this domain name. extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a managed zone facts" +- name: a managed zone facts gcp_dns_managed_zone_facts: - dns_name: test.somewild2.example.com. - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + dns_name: test.somewild2.example.com. + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' items: - description: List of items - returned: always - type: complex - contains: - description: - 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. - returned: success - type: str - dnsName: - description: - - The DNS name of this managed zone, for instance "example.com.". - returned: success - type: str - id: - description: - - Unique identifier for the resource; defined by the server. - returned: success - type: int - name: - description: - - User assigned name for this resource. - - Must be unique within the project. - returned: success - type: str - nameServers: - description: - - Delegate your managed_zone to these virtual name servers; defined by the server - . - returned: success - type: list - nameServerSet: - description: - - Optionally specifies the NameServerSet for this ManagedZone. A NameServerSet - is a set of DNS name servers that all host the same ManagedZones. Most users - will leave this field unset. - returned: success - type: str - creationTime: - description: - - The time that this resource was created on the server. - - 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 - 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 + description: List of items + returned: always + type: complex + contains: + description: + 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. + returned: success + type: str + dns_name: + description: + - The DNS name of this managed zone, for instance "example.com.". + returned: success + type: str + id: + description: + - Unique identifier for the resource; defined by the server. + returned: success + type: int + name: + description: + - User assigned name for this resource. + - Must be unique within the project. + returned: success + type: str + name_servers: + description: + - Delegate your managed_zone to these virtual name servers; defined by the server + . + returned: success + type: list + name_server_set: + description: + - Optionally specifies the NameServerSet for this ManagedZone. A NameServerSet is + a set of DNS name servers that all host the same ManagedZones. Most users will leave + this field unset. + returned: success + type: list + creation_time: + description: + - The time that this resource was created on the server. + - This is in RFC3339 text format. + returned: success + type: str ''' ################################################################################ @@ -149,9 +117,13 @@ import json def main(): - module = GcpModule(argument_spec=dict(dns_name=dict(type='list', elements='str'))) + module = GcpModule( + argument_spec=dict( + dns_name=dict(type='list', elements='str') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite'] items = fetch_list(module, collection(module), module.params['dns_name']) @@ -159,7 +131,9 @@ def main(): items = items.get('managedZones') else: items = [] - return_value = {'items': items} + return_value = { + 'items': items + } module.exit_json(**return_value) diff --git a/plugins/modules/gcp_dns_resource_record_set_facts.py b/plugins/modules/gcp_dns_resource_record_set_facts.py index 1e3e691..fff1607 100644 --- a/plugins/modules/gcp_dns_resource_record_set_facts.py +++ b/plugins/modules/gcp_dns_resource_record_set_facts.py @@ -18,81 +18,78 @@ # ---------------------------------------------------------------------------- from __future__ import absolute_import, division, print_function - __metaclass__ = type ################################################################################ # Documentation ################################################################################ -ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'} +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ["preview"], + 'supported_by': 'community'} DOCUMENTATION = ''' --- module: gcp_dns_resource_record_set_facts description: -- Gather facts for GCP ResourceRecordSet + - Gather facts for GCP ResourceRecordSet short_description: Gather facts for GCP ResourceRecordSet -version_added: 2.8 +version_added: 2.7 author: Google Inc. (@googlecloudplatform) requirements: -- python >= 2.6 -- requests >= 2.18.4 -- google-auth >= 1.3.0 + - python >= 2.6 + - requests >= 2.18.4 + - google-auth >= 1.3.0 options: - managed_zone: - description: - - Identifies the managed zone addressed by this request. - - 'This field represents a link to a ManagedZone resource in GCP. It can be specified - in two ways. First, you can place a dictionary with key ''name'' and value of - your resource''s name Alternatively, you can add `register: name-of-resource` - to a gcp_dns_managed_zone task and then set this managed_zone field to "{{ name-of-resource - }}"' - required: true + managed_zone: + description: + - Identifies the managed zone addressed by this request. + - Can be the managed zone name or id. + required: true extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a resource record set facts" +- name: a resource record set facts gcp_dns_resource_record_set_facts: - managed_zone: "{{ managed_zone }}" - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + managed_zone: "{{ managed_zone }}" + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' items: - description: List of items - returned: always - type: complex - contains: - name: - description: - - For example, U(www.example.com.) - returned: success - type: str - type: - description: - - One of valid DNS resource types. - returned: success - type: str - ttl: - description: - - Number of seconds that this ResourceRecordSet can be cached by resolvers. - returned: success - type: int - target: - description: - - As defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1) . - returned: success - type: list - managed_zone: - description: - - Identifies the managed zone addressed by this request. - returned: success - type: dict + description: List of items + returned: always + type: complex + contains: + name: + description: + - For example, U(www.example.com.) + returned: success + type: str + type: + description: + - One of valid DNS resource types. + returned: success + type: str + ttl: + description: + - Number of seconds that this ResourceRecordSet can be cached by resolvers. + returned: success + type: int + target: + description: + - As defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1) . + returned: success + type: list + managed_zone: + description: + - Identifies the managed zone addressed by this request. + - Can be the managed zone name or id. + returned: success + type: dict ''' ################################################################################ @@ -107,9 +104,13 @@ import json def main(): - module = GcpModule(argument_spec=dict(managed_zone=dict(required=True, type='dict'))) + module = GcpModule( + argument_spec=dict( + managed_zone=dict(required=True, type='dict') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite'] items = fetch_list(module, collection(module)) @@ -117,13 +118,18 @@ def main(): items = items.get('rrsets') else: items = [] - return_value = {'items': items} + return_value = { + 'items': items + } module.exit_json(**return_value) def collection(module): - res = {'project': module.params['project'], 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')} - return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**res) + res = { + 'project': module.params['project'], + 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name') + } + return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets".format(**res) def fetch_list(module, link): diff --git a/plugins/modules/gcp_pubsub_subscription.py b/plugins/modules/gcp_pubsub_subscription.py index 6a9e11a..da1d7f8 100644 --- a/plugins/modules/gcp_pubsub_subscription.py +++ b/plugins/modules/gcp_pubsub_subscription.py @@ -440,8 +440,10 @@ def decode_request(response, module): def encode_request(request, module): - request['topic'] = '/'.join(['projects', module.params['project'], 'topics', request['topic']]) - request['name'] = '/'.join(['projects', module.params['project'], 'subscriptions', module.params['name']]) + request['topic'] = '/'.join(['projects', module.params['project'], + 'topics', module.params['topic']['name']]) + request['name'] = '/'.join(['projects', module.params['project'], + 'subscriptions', module.params['name']]) return request diff --git a/plugins/modules/gcp_pubsub_subscription_facts.py b/plugins/modules/gcp_pubsub_subscription_facts.py index 30e39be..93e102c 100644 --- a/plugins/modules/gcp_pubsub_subscription_facts.py +++ b/plugins/modules/gcp_pubsub_subscription_facts.py @@ -18,132 +18,87 @@ # ---------------------------------------------------------------------------- from __future__ import absolute_import, division, print_function - __metaclass__ = type ################################################################################ # Documentation ################################################################################ -ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'} +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ["preview"], + 'supported_by': 'community'} DOCUMENTATION = ''' --- module: gcp_pubsub_subscription_facts description: -- Gather facts for GCP Subscription + - Gather facts for GCP Subscription short_description: Gather facts for GCP Subscription -version_added: 2.8 +version_added: 2.7 author: Google Inc. (@googlecloudplatform) requirements: -- python >= 2.6 -- requests >= 2.18.4 -- google-auth >= 1.3.0 -options: {} + - python >= 2.6 + - requests >= 2.18.4 + - google-auth >= 1.3.0 extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a subscription facts" +- name: a subscription facts gcp_pubsub_subscription_facts: - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' items: - description: List of items - returned: always - type: complex - contains: - name: - description: - - Name of the subscription. - returned: success - type: str - topic: - description: - - A reference to a Topic resource. - returned: success - type: dict - labels: - description: - - A set of key/value label pairs to assign to this Subscription. - returned: success - type: dict - pushConfig: - description: - - If push delivery is used with this subscription, this field is used to configure - it. An empty pushConfig signifies that the subscriber will pull and ack messages - using API methods. - returned: success - type: complex - contains: - pushEndpoint: - description: - - A URL locating the endpoint to which messages should be pushed. - - For example, a Webhook endpoint might use "U(https://example.com/push".) - returned: success - type: str - attributes: - description: - - Endpoint configuration attributes. - - Every endpoint has a set of API supported attributes that can be used - to control different aspects of the message delivery. - - The currently supported attribute is x-goog-version, which you can use - to change the format of the pushed message. This attribute indicates the - version of the data expected by the endpoint. This controls the shape - of the pushed message (i.e., its fields and metadata). The endpoint version - is based on the version of the Pub/Sub API. - - If not present during the subscriptions.create call, it will default to - the version of the API used to make such call. If not present during a - subscriptions.modifyPushConfig call, its value will not be changed. subscriptions.get - calls will always return a valid version, even if the subscription was - created without this attribute. - - 'The possible values for this attribute are: - v1beta1: uses the push - format defined in the v1beta1 Pub/Sub API.' - - "- v1 or v1beta2: uses the push format defined in the v1 Pub/Sub API." - returned: success - type: dict - ackDeadlineSeconds: - description: - - This value is the maximum time after a subscriber receives a message before - the subscriber should acknowledge the message. After message delivery but - before the ack deadline expires and before the message is acknowledged, it - is an outstanding message and will not be delivered again during that time - (on a best-effort basis). - - For pull subscriptions, this value is used as the initial value for the ack - deadline. To override this value for a given message, call subscriptions.modifyAckDeadline - with the corresponding ackId if using pull. The minimum custom deadline you - can specify is 10 seconds. The maximum custom deadline you can specify is - 600 seconds (10 minutes). - - If this parameter is 0, a default value of 10 seconds is used. - - For push delivery, this value is also used to set the request timeout for - the call to the push endpoint. - - If the subscriber never acknowledges the message, the Pub/Sub system will - eventually redeliver the message. - returned: success - type: int - messageRetentionDuration: - description: - - How long to retain unacknowledged messages in the subscription's backlog, - from the moment a message is published. If retainAckedMessages is true, then - this also configures the retention of acknowledged messages, and thus configures - how far back in time a subscriptions.seek can be done. Defaults to 7 days. - Cannot be more than 7 days (`"604800s"`) or less than 10 minutes (`"600s"`). - - 'A duration in seconds with up to nine fractional digits, terminated by ''s''. - Example: `"600.5s"`.' - returned: success - type: str - retainAckedMessages: - description: - - Indicates whether to retain acknowledged messages. If `true`, then messages - are not expunged from the subscription's backlog, even if they are acknowledged, - until they fall out of the messageRetentionDuration window. - returned: success - type: bool + description: List of items + returned: always + type: complex + contains: + name: + description: + - Name of the subscription. + returned: success + type: str + topic: + description: + - A reference to a Topic resource. + returned: success + type: dict + push_config: + description: + - If push delivery is used with this subscription, this field is used to configure + it. An empty pushConfig signifies that the subscriber will pull and ack messages + using API methods. + returned: success + type: complex + contains: + push_endpoint: + description: + - A URL locating the endpoint to which messages should be pushed. + - For example, a Webhook endpoint might use "U(https://example.com/push".) + returned: success + type: str + ack_deadline_seconds: + description: + - This value is the maximum time after a subscriber receives a message before the + subscriber should acknowledge the message. After message delivery but before the + ack deadline expires and before the message is acknowledged, it is an outstanding + message and will not be delivered again during that time (on a best-effort basis). + - For pull subscriptions, this value is used as the initial value for the ack deadline. + To override this value for a given message, call subscriptions.modifyAckDeadline + with the corresponding ackId if using pull. The minimum custom deadline you can + specify is 10 seconds. The maximum custom deadline you can specify is 600 seconds + (10 minutes). + - If this parameter is 0, a default value of 10 seconds is used. + - For push delivery, this value is also used to set the request timeout for the call + to the push endpoint. + - If the subscriber never acknowledges the message, the Pub/Sub system will eventually + redeliver the message. + returned: success + type: int ''' ################################################################################ @@ -158,9 +113,12 @@ import json def main(): - module = GcpModule(argument_spec=dict()) + module = GcpModule( + argument_spec=dict( + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub'] items = fetch_list(module, collection(module)) @@ -168,7 +126,9 @@ def main(): items = items.get('subscriptions') else: items = [] - return_value = {'items': items} + return_value = { + 'items': items + } module.exit_json(**return_value) diff --git a/plugins/modules/gcp_pubsub_topic_facts.py b/plugins/modules/gcp_pubsub_topic_facts.py index 466d8a6..a8363e3 100644 --- a/plugins/modules/gcp_pubsub_topic_facts.py +++ b/plugins/modules/gcp_pubsub_topic_facts.py @@ -18,56 +18,50 @@ # ---------------------------------------------------------------------------- from __future__ import absolute_import, division, print_function - __metaclass__ = type ################################################################################ # Documentation ################################################################################ -ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'} +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ["preview"], + 'supported_by': 'community'} DOCUMENTATION = ''' --- module: gcp_pubsub_topic_facts description: -- Gather facts for GCP Topic + - Gather facts for GCP Topic short_description: Gather facts for GCP Topic -version_added: 2.8 +version_added: 2.7 author: Google Inc. (@googlecloudplatform) requirements: -- python >= 2.6 -- requests >= 2.18.4 -- google-auth >= 1.3.0 -options: {} + - python >= 2.6 + - requests >= 2.18.4 + - google-auth >= 1.3.0 extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a topic facts" +- name: a topic facts gcp_pubsub_topic_facts: - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' items: - description: List of items - returned: always - type: complex - contains: - name: - description: - - Name of the topic. - returned: success - type: str - labels: - description: - - A set of key/value label pairs to assign to this Topic. - returned: success - type: dict + description: List of items + returned: always + type: complex + contains: + name: + description: + - Name of the topic. + returned: success + type: str ''' ################################################################################ @@ -82,9 +76,12 @@ import json def main(): - module = GcpModule(argument_spec=dict()) + module = GcpModule( + argument_spec=dict( + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub'] items = fetch_list(module, collection(module)) @@ -92,7 +89,9 @@ def main(): items = items.get('topics') else: items = [] - return_value = {'items': items} + return_value = { + 'items': items + } module.exit_json(**return_value) diff --git a/tests/integration/gcp_container_node_pool/tasks/main.yml b/tests/integration/gcp_container_node_pool/tasks/main.yml index 775d6a4..8e6df91 100644 --- a/tests/integration/gcp_container_node_pool/tasks/main.yml +++ b/tests/integration/gcp_container_node_pool/tasks/main.yml @@ -51,8 +51,10 @@ - result.changed == true - name: verify that node_pool was created gcp_container_node_pool_facts: + filters: + - name = {{ resource_name }} cluster: "{{ cluster }}" - location: us-central1-a + zone: us-central1-a project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" @@ -97,8 +99,10 @@ - result.changed == true - name: verify that node_pool was deleted gcp_container_node_pool_facts: + filters: + - name = {{ resource_name }} cluster: "{{ cluster }}" - location: us-central1-a + zone: us-central1-a project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" diff --git a/tests/integration/gcp_dns_resource_record_set/tasks/main.yml b/tests/integration/gcp_dns_resource_record_set/tasks/main.yml index 6871ea5..3daaccc 100644 --- a/tests/integration/gcp_dns_resource_record_set/tasks/main.yml +++ b/tests/integration/gcp_dns_resource_record_set/tasks/main.yml @@ -56,6 +56,19 @@ that: - result.changed == true - "result.kind == 'dns#resourceRecordSet'" +- name: verify that resource_record_set was created + gcp_dns_resource_record_set_facts: + managed_zone: "{{ managed_zone }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/ndev.clouddns.readwrite + register: results +- name: verify that command succeeded + assert: + that: + - results['items'] | length >= 2 # ---------------------------------------------------------------------------- - name: create a resource record set that already exists gcp_dns_resource_record_set: @@ -96,6 +109,19 @@ that: - result.changed == true - result.has_key('kind') == False +- name: verify that resource_record_set was deleted + gcp_dns_resource_record_set_facts: + managed_zone: "{{ managed_zone }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/ndev.clouddns.readwrite + register: results +- name: verify that command succeeded + assert: + that: + - results['items'] | length >= 2 # ---------------------------------------------------------------------------- - name: delete a resource record set that does not exist gcp_dns_resource_record_set: diff --git a/tests/integration/gcp_pubsub_subscription/tasks/main.yml b/tests/integration/gcp_pubsub_subscription/tasks/main.yml index 2b6607b..eceedbb 100644 --- a/tests/integration/gcp_pubsub_subscription/tasks/main.yml +++ b/tests/integration/gcp_pubsub_subscription/tasks/main.yml @@ -56,7 +56,7 @@ - name: verify that command succeeded assert: that: - - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length == 1 # ---------------------------------------------------------------------------- - name: create a subscription that already exists gcp_pubsub_subscription: @@ -98,7 +98,7 @@ - name: verify that command succeeded assert: that: - - "\"{{resource_name}}\" not in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length == 0 # ---------------------------------------------------------------------------- - name: delete a subscription that does not exist gcp_pubsub_subscription: diff --git a/tests/integration/gcp_pubsub_topic/tasks/main.yml b/tests/integration/gcp_pubsub_topic/tasks/main.yml index c26ecfb..8d1a063 100644 --- a/tests/integration/gcp_pubsub_topic/tasks/main.yml +++ b/tests/integration/gcp_pubsub_topic/tasks/main.yml @@ -44,7 +44,7 @@ - name: verify that command succeeded assert: that: - - "'test-topic1' in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length == 1 # ---------------------------------------------------------------------------- - name: create a topic that already exists gcp_pubsub_topic: @@ -82,7 +82,7 @@ - name: verify that command succeeded assert: that: - - "'test-topic1' not in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length == 0 # ---------------------------------------------------------------------------- - name: delete a topic that does not exist gcp_pubsub_topic: diff --git a/tests/integration/gcp_sql_user/tasks/main.yml b/tests/integration/gcp_sql_user/tasks/main.yml index ac8f8b5..8aea7e5 100644 --- a/tests/integration/gcp_sql_user/tasks/main.yml +++ b/tests/integration/gcp_sql_user/tasks/main.yml @@ -57,6 +57,8 @@ - "result.kind == 'sql#user'" - name: verify that user was created gcp_sql_user_facts: + filters: + - name = test-user instance: "{{ instance }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -104,6 +106,8 @@ - result.has_key('kind') == False - name: verify that user was deleted gcp_sql_user_facts: + filters: + - name = test-user instance: "{{ instance }}" project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}"