diff --git a/plugins/modules/gcp_container_cluster.py b/plugins/modules/gcp_container_cluster.py index d0aa3fc..5cf5f61 100644 --- a/plugins/modules/gcp_container_cluster.py +++ b/plugins/modules/gcp_container_cluster.py @@ -276,7 +276,7 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a cluster gcp_container_cluster: - name: "test_object" + name: my-cluster initial_node_count: 2 master_auth: username: cluster_admin diff --git a/plugins/modules/gcp_container_cluster_facts.py b/plugins/modules/gcp_container_cluster_facts.py index a19f874..9fe28fa 100644 --- a/plugins/modules/gcp_container_cluster_facts.py +++ b/plugins/modules/gcp_container_cluster_facts.py @@ -18,375 +18,338 @@ # ---------------------------------------------------------------------------- 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_container_cluster_facts description: -- Gather facts for GCP Cluster + - Gather facts for GCP Cluster short_description: Gather facts for GCP Cluster version_added: 2.8 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: - location: - description: - - The location where the cluster is deployed. - required: true - aliases: - - region - - zone - version_added: 2.8 + zone: + description: + - The zone where the cluster is deployed. + required: true extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a cluster facts" +- name: a cluster facts gcp_container_cluster_facts: - location: us-central1-a - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + zone: us-central1-a + 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: - - The name of this cluster. The name must be unique within this project and - location, and can be up to 40 characters. Must be Lowercase letters, numbers, - and hyphens only. Must start with a letter. Must end with a number or a letter. - returned: success - type: str - description: - description: - - An optional description of this cluster. - returned: success - type: str - initialNodeCount: - description: - - The number of nodes to create in this cluster. You must ensure that your Compute - Engine resource quota is sufficient for this number of instances. You must - also have available firewall and routes quota. For requests, this field should - only be used in lieu of a "nodePool" object, since this configuration (along - with the "nodeConfig") will be used to create a "NodePool" object with an - auto-generated name. Do not use this and a nodePool at the same time. - returned: success - type: int - nodeConfig: - description: - - Parameters used in creating the cluster's nodes. - - For requests, this field should only be used in lieu of a "nodePool" object, - since this configuration (along with the "initialNodeCount") will be used - to create a "NodePool" object with an auto-generated name. Do not use this - and a nodePool at the same time. For responses, this field will be populated - with the node configuration of the first node pool. If unspecified, the defaults - are used. - returned: success - type: complex - contains: - machineType: - description: - - The name of a Google Compute Engine machine type (e.g. - - n1-standard-1). If unspecified, the default machine type is n1-standard-1. - returned: success - type: str - diskSizeGb: - description: - - Size of the disk attached to each node, specified in GB. The smallest - allowed disk size is 10GB. If unspecified, the default disk size is 100GB. - returned: success - type: int - oauthScopes: - description: - - The set of Google API scopes to be made available on all of the node VMs - under the "default" service account. - - 'The following scopes are recommended, but not required, and by default - are not included: U(https://www.googleapis.com/auth/compute) is required - for mounting persistent storage on your nodes.' - - U(https://www.googleapis.com/auth/devstorage.read_only) is required for - communicating with gcr.io (the Google Container Registry). - - If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring - are enabled, in which case their required scopes will be added. - returned: success - type: list - serviceAccount: - description: - - The Google Cloud Platform Service Account to be used by the node VMs. - If no Service Account is specified, the "default" service account is used. - returned: success - type: str - metadata: - description: - - The metadata key/value pairs assigned to instances in the cluster. - - 'Keys must conform to the regexp [a-zA-Z0-9-_]+ and be less than 128 bytes - in length. These are reflected as part of a URL in the metadata server. - Additionally, to avoid ambiguity, keys must not conflict with any other - metadata keys for the project or be one of the four reserved keys: "instance-template", - "kube-env", "startup-script", and "user-data" Values are free-form strings, - and only have meaning as interpreted by the image running in the instance. - The only restriction placed on them is that each value''s size must be - less than or equal to 32 KB.' - - The total size of all keys and values must be less than 512 KB. - - 'An object containing a list of "key": value pairs.' - - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - returned: success - type: dict - imageType: - description: - - The image type to use for this node. Note that for a given image type, - the latest version of it will be used. - returned: success - type: str - labels: - description: - - 'The map of Kubernetes labels (key/value pairs) to be applied to each - node. These will added in addition to any default label(s) that Kubernetes - may apply to the node. In case of conflict in label keys, the applied - set may differ depending on the Kubernetes version -- it''s best to assume - the behavior is undefined and conflicts should be avoided. For more information, - including usage and the valid values, see: U(http://kubernetes.io/v1.1/docs/user-guide/labels.html) - An object containing a list of "key": value pairs.' - - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - returned: success - type: dict - localSsdCount: - description: - - The number of local SSD disks to be attached to the node. - - 'The limit for this value is dependant upon the maximum number of disks - available on a machine per zone. See: U(https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits) - for more information.' - returned: success - type: int - tags: - description: - - The list of instance tags applied to all nodes. Tags are used to identify - valid sources or targets for network firewalls and are specified by the - client during cluster or node pool creation. Each tag within the list - must comply with RFC1035. - returned: success - type: list - preemptible: - description: - - 'Whether the nodes are created as preemptible VM instances. See: U(https://cloud.google.com/compute/docs/instances/preemptible) - for more information about preemptible VM instances.' - returned: success - type: bool - masterAuth: - description: - - The authentication information for accessing the master endpoint. - returned: success - type: complex - contains: - username: - description: - - The username to use for HTTP basic authentication to the master endpoint. - returned: success - type: str - password: - description: - - The password to use for HTTP basic authentication to the master endpoint. - Because the master endpoint is open to the Internet, you should create - a strong password. - returned: success - type: str - clusterCaCertificate: - description: - - Base64-encoded public certificate that is the root of trust for the cluster. - returned: success - type: str - clientCertificate: - description: - - Base64-encoded public certificate used by clients to authenticate to the - cluster endpoint. - returned: success - type: str - clientKey: - description: - - Base64-encoded private key used by clients to authenticate to the cluster - endpoint. - returned: success - type: str - loggingService: - description: - - 'The logging service the cluster should use to write logs. Currently available - options: logging.googleapis.com - the Google Cloud Logging service.' - - none - no logs will be exported from the cluster. - - if left as an empty string,logging.googleapis.com will be used. - returned: success - type: str - monitoringService: - description: - - The monitoring service the cluster should use to write metrics. - - 'Currently available options: monitoring.googleapis.com - the Google Cloud - Monitoring service.' - - none - no metrics will be exported from the cluster. - - if left as an empty string, monitoring.googleapis.com will be used. - returned: success - type: str - network: - description: - - The name of the Google Compute Engine network to which the cluster is connected. - If left unspecified, the default network will be used. - returned: success - type: str - privateClusterConfig: - description: - - Configuration for a private cluster. - returned: success - type: complex - contains: - enablePrivateNodes: - description: - - Whether nodes have internal IP addresses only. If enabled, all nodes are - given only RFC 1918 private addresses and communicate with the master - via private networking. - returned: success - type: bool - enablePrivateEndpoint: - description: - - Whether the master's internal IP address is used as the cluster endpoint. - returned: success - type: bool - masterIpv4CidrBlock: - description: - - The IP range in CIDR notation to use for the hosted master network. This - range will be used for assigning internal IP addresses to the master or - set of masters, as well as the ILB VIP. This range must not overlap with - any other ranges in use within the cluster's network. - returned: success - type: str - privateEndpoint: - description: - - The internal IP address of this cluster's master endpoint. - returned: success - type: str - publicEndpoint: - description: - - The external IP address of this cluster's master endpoint. - returned: success - type: str - clusterIpv4Cidr: - description: - - The IP address range of the container pods in this cluster, in CIDR notation - (e.g. 10.96.0.0/14). Leave blank to have one automatically chosen or specify - a /14 block in 10.0.0.0/8. - returned: success - type: str - addonsConfig: - description: - - Configurations for the various addons available to run in the cluster. - returned: success - type: complex - contains: - httpLoadBalancing: - description: - - Configuration for the HTTP (L7) load balancing controller addon, which - makes it easy to set up HTTP load balancers for services in a cluster. - returned: success - type: complex - contains: - disabled: - description: - - Whether the HTTP Load Balancing controller is enabled in the cluster. - When enabled, it runs a small pod in the cluster that manages the - load balancers. - returned: success - type: bool - horizontalPodAutoscaling: - description: - - Configuration for the horizontal pod autoscaling feature, which increases - or decreases the number of replica pods a replication controller has based - on the resource usage of the existing pods. - returned: success - type: complex - contains: - disabled: - description: - - Whether the Horizontal Pod Autoscaling feature is enabled in the cluster. - When enabled, it ensures that a Heapster pod is running in the cluster, - which is also used by the Cloud Monitoring service. - returned: success - type: bool - subnetwork: - description: - - The name of the Google Compute Engine subnetwork to which the cluster is connected. - returned: success - type: str - endpoint: - description: - - The IP address of this cluster's master endpoint. - - The endpoint can be accessed from the internet at https://username:password@endpoint/ - See the masterAuth property of this resource for username and password information. - returned: success - type: str - initialClusterVersion: - description: - - The software version of the master endpoint and kubelets used in the cluster - when it was first created. The version can be upgraded over time. - returned: success - type: str - currentMasterVersion: - description: - - The current software version of the master endpoint. - returned: success - type: str - currentNodeVersion: - description: - - The current version of the node software components. If they are currently - at multiple versions because they're in the process of being upgraded, this - reflects the minimum version of all nodes. - returned: success - type: str - createTime: - description: - - The time the cluster was created, in RFC3339 text format. - returned: success - type: str - nodeIpv4CidrSize: - description: - - The size of the address space on each node for hosting containers. - - This is provisioned from within the container_ipv4_cidr range. - returned: success - type: int - servicesIpv4Cidr: - description: - - The IP address range of the Kubernetes services in this cluster, in CIDR notation - (e.g. 1.2.3.4/29). Service addresses are typically put in the last /16 from - the container CIDR. - returned: success - type: str - currentNodeCount: - description: - - The number of nodes currently in the cluster. - returned: success - type: int - expireTime: - description: - - The time the cluster will be automatically deleted in RFC3339 text format. - returned: success - type: str - location: - description: - - The location where the cluster is deployed. - returned: success - type: str + description: List of items + returned: always + type: complex + contains: + name: + description: + - The name of this cluster. The name must be unique within this project and zone, + and can be up to 40 characters. Must be Lowercase letters, numbers, and hyphens + only. Must start with a letter. Must end with a number or a letter. + returned: success + type: str + description: + description: + - An optional description of this cluster. + returned: success + type: str + initialNodeCount: + description: + - The number of nodes to create in this cluster. You must ensure that your Compute + Engine resource quota is sufficient for this number of instances. You must also + have available firewall and routes quota. For requests, this field should only be + used in lieu of a "nodePool" object, since this configuration (along with the "nodeConfig") + will be used to create a "NodePool" object with an auto-generated name. Do not use + this and a nodePool at the same time. + returned: success + type: int + nodeConfig: + description: + - Parameters used in creating the cluster's nodes. + - For requests, this field should only be used in lieu of a "nodePool" object, since + this configuration (along with the "initialNodeCount") will be used to create a + "NodePool" object with an auto-generated name. Do not use this and a nodePool at + the same time. For responses, this field will be populated with the node configuration + of the first node pool. If unspecified, the defaults are used. + returned: success + type: complex + contains: + machineType: + description: + - The name of a Google Compute Engine machine type (e.g. + - n1-standard-1). If unspecified, the default machine type is n1-standard-1. + returned: success + type: str + diskSizeGb: + description: + - Size of the disk attached to each node, specified in GB. The smallest allowed disk + size is 10GB. If unspecified, the default disk size is 100GB. + returned: success + type: int + oauthScopes: + description: + - The set of Google API scopes to be made available on all of the node VMs under the + "default" service account. + - 'The following scopes are recommended, but not required, and by default are not + included: U(https://www.googleapis.com/auth/compute) is required for mounting persistent + storage on your nodes.' + - U(https://www.googleapis.com/auth/devstorage.read_only) is required for communicating + with gcr.io (the Google Container Registry). + - If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are + enabled, in which case their required scopes will be added. + returned: success + type: list + serviceAccount: + description: + - The Google Cloud Platform Service Account to be used by the node VMs. If no Service + Account is specified, the "default" service account is used. + returned: success + type: str + metadata: + description: + - The metadata key/value pairs assigned to instances in the cluster. + - 'Keys must conform to the regexp [a-zA-Z0-9-_]+ and be less than 128 bytes in length. + These are reflected as part of a URL in the metadata server. Additionally, to avoid + ambiguity, keys must not conflict with any other metadata keys for the project or + be one of the four reserved keys: "instance-template", "kube-env", "startup-script", + and "user-data" Values are free-form strings, and only have meaning as interpreted + by the image running in the instance. The only restriction placed on them is that + each value''s size must be less than or equal to 32 KB.' + - The total size of all keys and values must be less than 512 KB. + - 'An object containing a list of "key": value pairs.' + - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' + returned: success + type: dict + imageType: + description: + - The image type to use for this node. Note that for a given image type, the latest + version of it will be used. + returned: success + type: str + labels: + description: + - 'The map of Kubernetes labels (key/value pairs) to be applied to each node. + These will added in addition to any default label(s) that Kubernetes may apply + to the node. In case of conflict in label keys, the applied set may differ + depending on the Kubernetes version -- it''s best to assume the behavior is + undefined and conflicts should be avoided. For more information, including + usage and the valid values, see: + U(http://kubernetes.io/v1.1/docs/user-guide/labels.html) An object containing + a list of "key": value pairs.' + - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' + returned: success + type: dict + localSsdCount: + description: + - The number of local SSD disks to be attached to the node. + - 'The limit for this value is dependant upon the maximum number of disks available + on a machine per zone. See: U(https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits) for + more information.' + returned: success + type: int + tags: + description: + - The list of instance tags applied to all nodes. Tags are used to identify valid + sources or targets for network firewalls and are specified by the client during + cluster or node pool creation. Each tag within the list must comply with RFC1035. + returned: success + type: list + preemptible: + description: + - 'Whether the nodes are created as preemptible VM instances. See: U(https://cloud.google.com/compute/docs/instances/preemptible) + for more inforamtion about preemptible VM instances.' + returned: success + type: bool + masterAuth: + description: + - The authentication information for accessing the master endpoint. + returned: success + type: complex + contains: + username: + description: + - The username to use for HTTP basic authentication to the master endpoint. + returned: success + type: str + password: + description: + - The password to use for HTTP basic authentication to the master endpoint. Because + the master endpoint is open to the Internet, you should create a strong password. + returned: success + type: str + clusterCaCertificate: + description: + - Base64-encoded public certificate that is the root of trust for the cluster. + returned: success + type: str + clientCertificate: + description: + - Base64-encoded public certificate used by clients to authenticate to the cluster + endpoint. + returned: success + type: str + clientKey: + description: + - Base64-encoded private key used by clients to authenticate to the cluster endpoint. + returned: success + type: str + loggingService: + description: + - 'The logging service the cluster should use to write logs. Currently available options: logging.googleapis.com + - the Google Cloud Logging service.' + - none - no logs will be exported from the cluster. + - if left as an empty string,logging.googleapis.com will be used. + returned: success + type: str + monitoringService: + description: + - The monitoring service the cluster should use to write metrics. + - 'Currently available options: monitoring.googleapis.com - the Google Cloud Monitoring + service.' + - none - no metrics will be exported from the cluster. + - if left as an empty string, monitoring.googleapis.com will be used. + returned: success + type: str + network: + description: + - The name of the Google Compute Engine network to which the cluster is connected. + If left unspecified, the default network will be used. + - To ensure it exists and it is operations, configure the network using 'gcompute_network' + resource. + returned: success + type: str + clusterIpv4Cidr: + description: + - The IP address range of the container pods in this cluster, in CIDR notation (e.g. + 10.96.0.0/14). Leave blank to have one automatically chosen or specify a /14 block + in 10.0.0.0/8. + returned: success + type: str + addonsConfig: + description: + - Configurations for the various addons available to run in the cluster. + returned: success + type: complex + contains: + httpLoadBalancing: + description: + - Configuration for the HTTP (L7) load balancing controller addon, which makes it + easy to set up HTTP load balancers for services in a cluster. + returned: success + type: complex + contains: + disabled: + description: + - Whether the HTTP Load Balancing controller is enabled in the cluster. When enabled, + it runs a small pod in the cluster that manages the load balancers. + returned: success + type: bool + horizontalPodAutoscaling: + description: + - Configuration for the horizontal pod autoscaling feature, which increases or decreases + the number of replica pods a replication controller has based on the resource usage + of the existing pods. + returned: success + type: complex + contains: + disabled: + description: + - Whether the Horizontal Pod Autoscaling feature is enabled in the cluster. When enabled, + it ensures that a Heapster pod is running in the cluster, which is also used by + the Cloud Monitoring service. + returned: success + type: bool + subnetwork: + description: + - The name of the Google Compute Engine subnetwork to which the cluster is connected. + returned: success + type: str + location: + description: + - The list of Google Compute Engine locations in which the cluster's nodes should + be located. + returned: success + type: list + endpoint: + description: + - The IP address of this cluster's master endpoint. + - The endpoint can be accessed from the internet at https://username:password@endpoint/ See + the masterAuth property of this resource for username and password information. + returned: success + type: str + initialClusterVersion: + description: + - The software version of the master endpoint and kubelets used in the cluster when + it was first created. The version can be upgraded over time. + returned: success + type: str + currentMasterVersion: + description: + - The current software version of the master endpoint. + returned: success + type: str + currentNodeVersion: + description: + - The current version of the node software components. If they are currently at multiple + versions because they're in the process of being upgraded, this reflects the minimum + version of all nodes. + returned: success + type: str + createTime: + description: + - The time the cluster was created, in RFC3339 text format. + returned: success + type: str + nodeIpv4CidrSize: + description: + - The size of the address space on each node for hosting containers. + - This is provisioned from within the container_ipv4_cidr range. + returned: success + type: int + servicesIpv4Cidr: + description: + - The IP address range of the Kubernetes services in this cluster, in CIDR notation + (e.g. 1.2.3.4/29). Service addresses are typically put in the last /16 from the + container CIDR. + returned: success + type: str + currentNodeCount: + description: + - The number of nodes currently in the cluster. + returned: success + type: int + expireTime: + description: + - The time the cluster will be automatically deleted in RFC3339 text format. + returned: success + type: str + zone: + description: + - The zone where the cluster is deployed. + returned: success + type: str ''' ################################################################################ @@ -401,9 +364,13 @@ import json def main(): - module = GcpModule(argument_spec=dict(location=dict(required=True, type='str', aliases=['region', 'zone']))) + module = GcpModule( + argument_spec=dict( + zone=dict(required=True, type='str') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] items = fetch_list(module, collection(module)) @@ -411,12 +378,14 @@ def main(): items = items.get('clusters') else: items = [] - return_value = {'items': items} + return_value = { + 'items': items + } module.exit_json(**return_value) def collection(module): - return "https://container.googleapis.com/v1/projects/{project}/locations/{location}/clusters".format(**module.params) + return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters".format(**module.params) def fetch_list(module, link): diff --git a/plugins/modules/gcp_container_node_pool.py b/plugins/modules/gcp_container_node_pool.py index 4fc6fa2..a886ea0 100644 --- a/plugins/modules/gcp_container_node_pool.py +++ b/plugins/modules/gcp_container_node_pool.py @@ -226,7 +226,7 @@ EXAMPLES = ''' - name: create a node pool gcp_container_node_pool: - name: "test_object" + name: my-pool initial_node_count: 4 cluster: "{{ cluster }}" zone: us-central1-a diff --git a/plugins/modules/gcp_container_node_pool_facts.py b/plugins/modules/gcp_container_node_pool_facts.py index aae0324..98b8c30 100644 --- a/plugins/modules/gcp_container_node_pool_facts.py +++ b/plugins/modules/gcp_container_node_pool_facts.py @@ -18,247 +18,241 @@ # ---------------------------------------------------------------------------- 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_container_node_pool_facts description: -- Gather facts for GCP NodePool + - Gather facts for GCP NodePool short_description: Gather facts for GCP NodePool version_added: 2.8 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: - location: - description: - - The location where the node pool is deployed. - required: true - aliases: - - region - - zone - version_added: 2.8 - cluster: - description: - - The cluster this node pool belongs to. - - 'This field represents a link to a Cluster 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_container_cluster task and then set this cluster field to "{{ name-of-resource - }}"' - required: true + zone: + description: + - The zone where the node pool is deployed. + required: true + cluster: + description: + - The cluster this node pool belongs to. + - 'This field represents a link to a Cluster resource in GCP. It can be specified + in two ways. You can add `register: name-of-resource` to a gcp_container_cluster + task and then set this cluster field to "{{ name-of-resource }}" Alternatively, + you can set this cluster to a dictionary with the name key where the value is the + name of your Cluster.' + required: true extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a node pool facts" +- name: a node pool facts gcp_container_node_pool_facts: - cluster: "{{ cluster }}" - location: us-central1-a - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + cluster: "{{ cluster }}" + zone: us-central1-a + 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: - - The name of the node pool. - returned: success - type: str - config: - description: - - The node configuration of the pool. - returned: success - type: complex - contains: - machineType: - description: - - The name of a Google Compute Engine machine type (e.g. - - n1-standard-1). If unspecified, the default machine type is n1-standard-1. - returned: success - type: str - diskSizeGb: - description: - - Size of the disk attached to each node, specified in GB. The smallest - allowed disk size is 10GB. If unspecified, the default disk size is 100GB. - returned: success - type: int - oauthScopes: - description: - - The set of Google API scopes to be made available on all of the node VMs - under the "default" service account. - - 'The following scopes are recommended, but not required, and by default - are not included: U(https://www.googleapis.com/auth/compute) is required - for mounting persistent storage on your nodes.' - - U(https://www.googleapis.com/auth/devstorage.read_only) is required for - communicating with gcr.io (the Google Container Registry). - - If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring - are enabled, in which case their required scopes will be added. - returned: success - type: list - serviceAccount: - description: - - The Google Cloud Platform Service Account to be used by the node VMs. - If no Service Account is specified, the "default" service account is used. - returned: success - type: str - metadata: - description: - - The metadata key/value pairs assigned to instances in the cluster. - - 'Keys must conform to the regexp [a-zA-Z0-9-_]+ and be less than 128 bytes - in length. These are reflected as part of a URL in the metadata server. - Additionally, to avoid ambiguity, keys must not conflict with any other - metadata keys for the project or be one of the four reserved keys: "instance-template", - "kube-env", "startup-script", and "user-data" Values are free-form strings, - and only have meaning as interpreted by the image running in the instance. - The only restriction placed on them is that each value''s size must be - less than or equal to 32 KB.' - - The total size of all keys and values must be less than 512 KB. - - 'An object containing a list of "key": value pairs.' - - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - returned: success - type: dict - imageType: - description: - - The image type to use for this node. Note that for a given image type, - the latest version of it will be used. - returned: success - type: str - labels: - description: - - 'The map of Kubernetes labels (key/value pairs) to be applied to each - node. These will added in addition to any default label(s) that Kubernetes - may apply to the node. In case of conflict in label keys, the applied - set may differ depending on the Kubernetes version -- it''s best to assume - the behavior is undefined and conflicts should be avoided. For more information, - including usage and the valid values, see: U(http://kubernetes.io/v1.1/docs/user-guide/labels.html) - An object containing a list of "key": value pairs.' - - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - returned: success - type: dict - localSsdCount: - description: - - The number of local SSD disks to be attached to the node. - - 'The limit for this value is dependant upon the maximum number of disks - available on a machine per zone. See: U(https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits) - for more information.' - returned: success - type: int - tags: - description: - - The list of instance tags applied to all nodes. Tags are used to identify - valid sources or targets for network firewalls and are specified by the - client during cluster or node pool creation. Each tag within the list - must comply with RFC1035. - returned: success - type: list - preemptible: - description: - - 'Whether the nodes are created as preemptible VM instances. See: U(https://cloud.google.com/compute/docs/instances/preemptible) - for more information about preemptible VM instances.' - returned: success - type: bool - initialNodeCount: - description: - - The initial node count for the pool. You must ensure that your Compute Engine - resource quota is sufficient for this number of instances. You must also have - available firewall and routes quota. - returned: success - type: int - version: - description: - - The version of the Kubernetes of this node. - returned: success - type: str - autoscaling: - description: - - Autoscaler configuration for this NodePool. Autoscaler is enabled only if - a valid configuration is present. - returned: success - type: complex - contains: - enabled: - description: - - Is autoscaling enabled for this node pool. - returned: success - type: bool - minNodeCount: - description: - - Minimum number of nodes in the NodePool. Must be >= 1 and <= maxNodeCount. - returned: success - type: int - maxNodeCount: - description: - - Maximum number of nodes in the NodePool. Must be >= minNodeCount. - - There has to enough quota to scale up the cluster. - returned: success - type: int - management: - description: - - Management configuration for this NodePool. - returned: success - type: complex - contains: - autoUpgrade: - description: - - A flag that specifies whether node auto-upgrade is enabled for the node - pool. If enabled, node auto-upgrade helps keep the nodes in your node - pool up to date with the latest release version of Kubernetes. - returned: success - type: bool - autoRepair: - description: - - A flag that specifies whether the node auto-repair is enabled for the - node pool. If enabled, the nodes in this node pool will be monitored and, - if they fail health checks too many times, an automatic repair action - will be triggered. - returned: success - type: bool - upgradeOptions: - description: - - Specifies the Auto Upgrade knobs for the node pool. - returned: success - type: complex - contains: - autoUpgradeStartTime: - description: - - This field is set when upgrades are about to commence with the approximate - start time for the upgrades, in RFC3339 text format. - returned: success - type: str + description: List of items + returned: always + type: complex + contains: + name: description: - description: - - This field is set when upgrades are about to commence with the description - of the upgrade. - returned: success - type: str - cluster: - description: - - The cluster this node pool belongs to. - returned: success - type: dict - location: - description: - - The location where the node pool is deployed. - returned: success - type: str + - The name of the node pool. + returned: success + type: str + config: + description: + - The node configuration of the pool. + returned: success + type: complex + contains: + machineType: + description: + - The name of a Google Compute Engine machine type (e.g. + - n1-standard-1). If unspecified, the default machine type is n1-standard-1. + returned: success + type: str + diskSizeGb: + description: + - Size of the disk attached to each node, specified in GB. The smallest allowed disk + size is 10GB. If unspecified, the default disk size is 100GB. + returned: success + type: int + oauthScopes: + description: + - The set of Google API scopes to be made available on all of the node VMs under the + "default" service account. + - 'The following scopes are recommended, but not required, and by default are not + included: U(https://www.googleapis.com/auth/compute) is required for mounting persistent + storage on your nodes.' + - U(https://www.googleapis.com/auth/devstorage.read_only) is required for communicating + with gcr.io (the Google Container Registry). + - If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are + enabled, in which case their required scopes will be added. + returned: success + type: list + serviceAccount: + description: + - The Google Cloud Platform Service Account to be used by the node VMs. If no Service + Account is specified, the "default" service account is used. + returned: success + type: str + metadata: + description: + - The metadata key/value pairs assigned to instances in the cluster. + - 'Keys must conform to the regexp [a-zA-Z0-9-_]+ and be less than 128 bytes in length. + These are reflected as part of a URL in the metadata server. Additionally, to avoid + ambiguity, keys must not conflict with any other metadata keys for the project or + be one of the four reserved keys: "instance-template", "kube-env", "startup-script", + and "user-data" Values are free-form strings, and only have meaning as interpreted + by the image running in the instance. The only restriction placed on them is that + each value''s size must be less than or equal to 32 KB.' + - The total size of all keys and values must be less than 512 KB. + - 'An object containing a list of "key": value pairs.' + - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' + returned: success + type: dict + imageType: + description: + - The image type to use for this node. Note that for a given image type, the latest + version of it will be used. + returned: success + type: str + labels: + description: + - 'The map of Kubernetes labels (key/value pairs) to be applied to each node. + These will added in addition to any default label(s) that Kubernetes may apply + to the node. In case of conflict in label keys, the applied set may differ + depending on the Kubernetes version -- it''s best to assume the behavior is + undefined and conflicts should be avoided. For more information, including + usage and the valid values, see: + U(http://kubernetes.io/v1.1/docs/user-guide/labels.html) An object containing + a list of "key": value pairs.' + - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' + returned: success + type: dict + localSsdCount: + description: + - The number of local SSD disks to be attached to the node. + - 'The limit for this value is dependant upon the maximum number of disks available + on a machine per zone. See: U(https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits) for + more information.' + returned: success + type: int + tags: + description: + - The list of instance tags applied to all nodes. Tags are used to identify valid + sources or targets for network firewalls and are specified by the client during + cluster or node pool creation. Each tag within the list must comply with RFC1035. + returned: success + type: list + preemptible: + description: + - 'Whether the nodes are created as preemptible VM instances. See: U(https://cloud.google.com/compute/docs/instances/preemptible) + for more inforamtion about preemptible VM instances.' + returned: success + type: bool + initialNodeCount: + description: + - The initial node count for the pool. You must ensure that your Compute Engine resource + quota is sufficient for this number of instances. You must also have available firewall + and routes quota. + returned: success + type: int + version: + description: + - The version of the Kubernetes of this node. + returned: success + type: str + autoscaling: + description: + - Autoscaler configuration for this NodePool. Autoscaler is enabled only if a valid + configuration is present. + returned: success + type: complex + contains: + enabled: + description: + - Is autoscaling enabled for this node pool. + returned: success + type: bool + minNodeCount: + description: + - Minimum number of nodes in the NodePool. Must be >= 1 and <= maxNodeCount. + returned: success + type: int + maxNodeCount: + description: + - Maximum number of nodes in the NodePool. Must be >= minNodeCount. + - There has to enough quota to scale up the cluster. + returned: success + type: int + management: + description: + - Management configuration for this NodePool. + returned: success + type: complex + contains: + autoUpgrade: + description: + - A flag that specifies whether node auto-upgrade is enabled for the node pool. If + enabled, node auto-upgrade helps keep the nodes in your node pool up to date with + the latest release version of Kubernetes. + returned: success + type: bool + autoRepair: + description: + - A flag that specifies whether the node auto-repair is enabled for the node pool. + If enabled, the nodes in this node pool will be monitored and, if they fail health + checks too many times, an automatic repair action will be triggered. + returned: success + type: bool + upgradeOptions: + description: + - Specifies the Auto Upgrade knobs for the node pool. + returned: success + type: complex + contains: + autoUpgradeStartTime: + description: + - This field is set when upgrades are about to commence with the approximate start + time for the upgrades, in RFC3339 text format. + returned: success + type: str + description: + description: + - This field is set when upgrades are about to commence with the description of the + upgrade. + returned: success + type: str + cluster: + description: + - The cluster this node pool belongs to. + returned: success + type: dict + zone: + description: + - The zone where the node pool is deployed. + returned: success + type: str ''' ################################################################################ @@ -273,9 +267,14 @@ import json def main(): - module = GcpModule(argument_spec=dict(location=dict(required=True, type='str', aliases=['region', 'zone']), cluster=dict(required=True, type='dict'))) + module = GcpModule( + argument_spec=dict( + zone=dict(required=True, type='str'), + cluster=dict(required=True, type='dict') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] items = fetch_list(module, collection(module)) @@ -283,13 +282,19 @@ def main(): items = items.get('nodePools') else: items = [] - return_value = {'items': items} + return_value = { + 'items': items + } module.exit_json(**return_value) def collection(module): - res = {'project': module.params['project'], 'location': module.params['location'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')} - return "https://container.googleapis.com/v1/projects/{project}/zones/{location}/clusters/{cluster}/nodePools".format(**res) + res = { + 'project': module.params['project'], + 'zone': module.params['zone'], + 'cluster': replace_resource_dict(module.params['cluster'], 'name') + } + return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res) def fetch_list(module, link): diff --git a/plugins/modules/gcp_spanner_database_facts.py b/plugins/modules/gcp_spanner_database_facts.py index d3e0c57..bece9c7 100644 --- a/plugins/modules/gcp_spanner_database_facts.py +++ b/plugins/modules/gcp_spanner_database_facts.py @@ -18,75 +18,75 @@ # ---------------------------------------------------------------------------- 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_spanner_database_facts description: -- Gather facts for GCP Database + - Gather facts for GCP Database short_description: Gather facts for GCP Database version_added: 2.8 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: - instance: - description: - - The instance to create the database on. - - 'This field represents a link to a Instance 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_spanner_instance task and then set this instance field to "{{ name-of-resource - }}"' - required: true + instance: + description: + - The instance to create the database on. + - 'This field represents a link to a Instance resource in GCP. It can be specified + in two ways. You can add `register: name-of-resource` to a gcp_spanner_instance + task and then set this instance field to "{{ name-of-resource }}" Alternatively, + you can set this instance to a dictionary with the name key where the value is the + name of your Instance.' + required: true extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a database facts" +- name: a database facts gcp_spanner_database_facts: - instance: "{{ instance }}" - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + instance: "{{ instance }}" + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' -resources: - description: List of resources - returned: always - type: complex - contains: - name: - description: - - A unique identifier for the database, which cannot be changed after the instance - is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9]. - returned: success - type: str - extraStatements: - description: - - 'An optional list of DDL statements to run inside the newly created database. - Statements can create tables, indexes, etc. These statements execute atomically - with the creation of the database: if there is an error in any statement, - the database is not created.' - returned: success - type: list - instance: - description: - - The instance to create the database on. - returned: success - type: dict +items: + description: List of items + returned: always + type: complex + contains: + name: + description: + - A unique identifier for the database, which cannot be changed after the instance + is created. Values are of the form projects//instances/[a-z][-a-z0-9]*[a-z0-9]. + The final segment of the name must be between 6 and 30 characters in length. + returned: success + type: str + extraStatements: + description: + - 'An optional list of DDL statements to run inside the newly created database. Statements + can create tables, indexes, etc. These statements execute atomically with the creation + of the database: if there is an error in any statement, the database is not created.' + returned: success + type: list + instance: + description: + - The instance to create the database on. + returned: success + type: dict ''' ################################################################################ @@ -101,9 +101,13 @@ import json def main(): - module = GcpModule(argument_spec=dict(instance=dict(required=True, type='dict'))) + module = GcpModule( + argument_spec=dict( + instance=dict(required=True, type='dict') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] items = fetch_list(module, collection(module)) @@ -111,12 +115,17 @@ def main(): items = items.get('databases') else: items = [] - return_value = {'resources': items} + return_value = { + 'items': items + } module.exit_json(**return_value) def collection(module): - res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')} + res = { + 'project': module.params['project'], + 'instance': replace_resource_dict(module.params['instance'], 'name') + } return "https://spanner.googleapis.com/v1/projects/{project}/instances/{instance}/databases".format(**res) diff --git a/plugins/modules/gcp_spanner_instance_facts.py b/plugins/modules/gcp_spanner_instance_facts.py index 7c64a9e..3e35b50 100644 --- a/plugins/modules/gcp_spanner_instance_facts.py +++ b/plugins/modules/gcp_spanner_instance_facts.py @@ -18,79 +18,90 @@ # ---------------------------------------------------------------------------- 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_spanner_instance_facts description: -- Gather facts for GCP Instance + - Gather facts for GCP Instance short_description: Gather facts for GCP Instance version_added: 2.8 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 instance facts" +- name: a instance facts gcp_spanner_instance_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 = ''' -resources: - description: List of resources - returned: always - type: complex - contains: - name: - description: - - A unique identifier for the instance, which cannot be changed after the instance - is created. The name must be between 6 and 30 characters in length. - returned: success - type: str - config: - description: - - The name of the instance's configuration (similar but not quite the same as - a region) which defines defines the geographic placement and replication of - your databases in this instance. It determines where your data is stored. - Values are typically of the form `regional-europe-west1` , `us-central` etc. - - In order to obtain a valid list please consult the [Configuration section - of the docs](U(https://cloud.google.com/spanner/docs/instances).) - returned: success - type: str - displayName: - description: - - The descriptive name for this instance as it appears in UIs. Must be unique - per project and between 4 and 30 characters in length. - returned: success - type: str - nodeCount: - description: - - The number of nodes allocated to this instance. - returned: success - type: int - labels: - description: - - 'An object containing a list of "key": value pairs.' - - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - returned: success - type: dict +items: + description: List of items + returned: always + type: complex + contains: + name: + description: + - A unique identifier for the instance, which cannot be changed after the instance + is created. Values are of the form projects//instances/[a-z][-a-z0-9]*[a-z0-9]. + The final segment of the name must be between 6 and 30 characters in length. + returned: success + type: str + config: + description: + - A reference to the instance configuration. + returned: success + type: str + displayName: + description: + - The descriptive name for this instance as it appears in UIs. Must be unique per + project and between 4 and 30 characters in length. + returned: success + type: str + nodeCount: + description: + - The number of nodes allocated to this instance. + returned: success + type: int + labels: + description: + - Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources + into groups that reflect a customer's organizational needs and deployment strategies. + Cloud Labels can be used to filter collections of resources. They can be used to + control how resource metrics are aggregated. And they can be used as arguments to + policy management rules (e.g. route, firewall, load balancing, etc.). + - 'Label keys must be between 1 and 63 characters long and must conform to the following + regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.' + - Label values must be between 0 and 63 characters long and must conform to the regular + expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`. + - No more than 64 labels can be associated with a given resource. + - See U(https://goo.gl/xmQnxf) for more information on and examples of labels. + - 'If you plan to use labels in your own code, please note that additional characters + may be allowed in the future. And so you are advised to use an internal label representation, + such as JSON, which doesn''t rely upon specific characters being disallowed. For + example, representing labels as the string: name + "_" + value would prove problematic + if we were to allow "_" in a future release.' + - 'An object containing a list of "key": value pairs.' + - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' + returned: success + type: dict ''' ################################################################################ @@ -105,9 +116,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/spanner.admin'] items = fetch_list(module, collection(module)) @@ -115,7 +129,9 @@ def main(): items = items.get('instances') else: items = [] - return_value = {'resources': items} + return_value = { + 'items': items + } module.exit_json(**return_value) diff --git a/plugins/modules/gcp_sql_database_facts.py b/plugins/modules/gcp_sql_database_facts.py index 41d96b1..a960306 100644 --- a/plugins/modules/gcp_sql_database_facts.py +++ b/plugins/modules/gcp_sql_database_facts.py @@ -18,78 +18,83 @@ # ---------------------------------------------------------------------------- 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_sql_database_facts description: -- Gather facts for GCP Database + - Gather facts for GCP Database short_description: Gather facts for GCP Database version_added: 2.8 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: - instance: - description: - - The name of the Cloud SQL instance. This does not include the project ID. - required: true + instance: + description: + - The name of the Cloud SQL instance. This does not include the project ID. + - 'This field represents a link to a Instance resource in GCP. It can be specified + in two ways. You can add `register: name-of-resource` to a gcp_sql_instance task + and then set this instance field to "{{ name-of-resource }}" Alternatively, you + can set this instance to a dictionary with the name key where the value is the name + of your Instance.' + required: true extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a database facts" +- name: a database facts gcp_sql_database_facts: - instance: "{{ instance }}" - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + instance: "{{ instance }}" + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' -resources: - description: List of resources - returned: always - type: complex - contains: - charset: - description: - - The MySQL charset value. - returned: success - type: str - collation: - description: - - The MySQL collation value. - returned: success - type: str - name: - description: - - The name of the database in the Cloud SQL instance. - - This does not include the project ID or instance name. - returned: success - type: str - instance: - description: - - The name of the Cloud SQL instance. This does not include the project ID. - returned: success - type: str +items: + description: List of items + returned: always + type: complex + contains: + charset: + description: + - The MySQL charset value. + returned: success + type: str + collation: + description: + - The MySQL collation value. + returned: success + type: str + name: + description: + - The name of the database in the Cloud SQL instance. + - This does not include the project ID or instance name. + returned: success + type: str + instance: + description: + - The name of the Cloud SQL instance. This does not include the project ID. + returned: success + type: dict ''' ################################################################################ # Imports ################################################################################ -from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest +from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict import json ################################################################################ @@ -98,9 +103,13 @@ import json def main(): - module = GcpModule(argument_spec=dict(instance=dict(required=True, type='str'))) + module = GcpModule( + argument_spec=dict( + instance=dict(required=True, type='dict') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] items = fetch_list(module, collection(module)) @@ -108,12 +117,18 @@ def main(): items = items.get('items') else: items = [] - return_value = {'resources': items} + return_value = { + 'items': items + } module.exit_json(**return_value) def collection(module): - return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases".format(**module.params) + res = { + 'project': module.params['project'], + 'instance': replace_resource_dict(module.params['instance'], 'name') + } + return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases".format(**res) def fetch_list(module, link): diff --git a/plugins/modules/gcp_sql_instance_facts.py b/plugins/modules/gcp_sql_instance_facts.py index 7a9bdc5..1722b42 100644 --- a/plugins/modules/gcp_sql_instance_facts.py +++ b/plugins/modules/gcp_sql_instance_facts.py @@ -18,337 +18,302 @@ # ---------------------------------------------------------------------------- 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_sql_instance_facts description: -- Gather facts for GCP Instance + - Gather facts for GCP Instance short_description: Gather facts for GCP Instance version_added: 2.8 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 instance facts" +- name: a instance facts gcp_sql_instance_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 = ''' -resources: - description: List of resources - returned: always - type: complex - contains: - backendType: - description: - - "* FIRST_GEN: First Generation instance. MySQL only." - - "* SECOND_GEN: Second Generation instance or PostgreSQL instance." - - "* EXTERNAL: A database server that is not managed by Google." - returned: success - type: str - connectionName: - description: - - Connection name of the Cloud SQL instance used in connection strings. - returned: success - type: str - databaseVersion: - description: - - The database engine type and version. For First Generation instances, can - be MYSQL_5_5, or MYSQL_5_6. For Second Generation instances, can be MYSQL_5_6 - or MYSQL_5_7. Defaults to MYSQL_5_6. - - 'PostgreSQL instances: POSTGRES_9_6 The databaseVersion property can not be - changed after instance creation.' - returned: success - type: str - failoverReplica: - description: - - The name and status of the failover replica. This property is applicable only - to Second Generation instances. - returned: success - type: complex - contains: - available: - description: - - The availability status of the failover replica. A false status indicates - that the failover replica is out of sync. The master can only failover - to the failover replica when the status is true. - returned: success - type: bool - name: - description: - - The name of the failover replica. If specified at instance creation, a - failover replica is created for the instance. The name doesn't include - the project ID. This property is applicable only to Second Generation - instances. - returned: success - type: str - instanceType: - description: - - The instance type. This can be one of the following. - - "* CLOUD_SQL_INSTANCE: A Cloud SQL instance that is not replicating from a - master." - - "* ON_PREMISES_INSTANCE: An instance running on the customer's premises." - - "* READ_REPLICA_INSTANCE: A Cloud SQL instance configured as a read-replica." - returned: success - type: str - ipAddresses: - description: - - The assigned IP addresses for the instance. - returned: success - type: complex - contains: - ipAddress: - description: - - The IP address assigned. - returned: success - type: str - timeToRetire: - description: - - The due time for this IP to be retired in RFC 3339 format, for example - 2012-11-15T16:19:00.094Z. This field is only available when the IP is - scheduled to be retired. - returned: success - type: str - type: - description: - - The type of this IP address. A PRIMARY address is an address that can - accept incoming connections. An OUTGOING address is the source address - of connections originating from the instance, if supported. - returned: success - type: str - ipv6Address: - description: - - The IPv6 address assigned to the instance. This property is applicable only - to First Generation instances. - returned: success - type: str - masterInstanceName: - description: - - The name of the instance which will act as master in the replication setup. - returned: success - type: str - maxDiskSize: - description: - - The maximum disk size of the instance in bytes. - returned: success - type: int - name: - description: - - Name of the Cloud SQL instance. This does not include the project ID. - returned: success - type: str - region: - description: - - The geographical region. Defaults to us-central or us-central1 depending on - the instance type (First Generation or Second Generation/PostgreSQL). - returned: success - type: str - replicaConfiguration: - description: - - Configuration specific to failover replicas and read replicas. - returned: success - type: complex - contains: - failoverTarget: - description: - - Specifies if the replica is the failover target. If the field is set to - true the replica will be designated as a failover replica. - - In case the master instance fails, the replica instance will be promoted - as the new master instance. - - Only one replica can be specified as failover target, and the replica - has to be in different zone with the master instance. - returned: success - type: bool - mysqlReplicaConfiguration: - description: - - MySQL specific configuration when replicating from a MySQL on-premises - master. Replication configuration information such as the username, password, - certificates, and keys are not stored in the instance metadata. The configuration - information is used only to set up the replication connection and is stored - by MySQL in a file named master.info in the data directory. - returned: success - type: complex - contains: - caCertificate: - description: - - PEM representation of the trusted CA's x509 certificate. - returned: success - type: str - clientCertificate: - description: - - PEM representation of the slave's x509 certificate . - returned: success - type: str - clientKey: - description: - - PEM representation of the slave's private key. The corresponding public - key is encoded in the client's certificate. - returned: success - type: str - connectRetryInterval: - description: - - Seconds to wait between connect retries. MySQL's default is 60 seconds. - returned: success - type: int - dumpFilePath: - description: - - Path to a SQL dump file in Google Cloud Storage from which the slave - instance is to be created. The URI is in the form gs://bucketName/fileName. - Compressed gzip files (.gz) are also supported. Dumps should have - the binlog co-ordinates from which replication should begin. This - can be accomplished by setting --master-data to 1 when using mysqldump. - returned: success - type: str - masterHeartbeatPeriod: - description: - - Interval in milliseconds between replication heartbeats. - returned: success - type: int - password: - description: - - The password for the replication connection. - returned: success - type: str - sslCipher: - description: - - A list of permissible ciphers to use for SSL encryption. - returned: success - type: str - username: - description: - - The username for the replication connection. - returned: success - type: str - verifyServerCertificate: - description: - - Whether or not to check the master's Common Name value in the certificate - that it sends during the SSL handshake. - returned: success - type: bool - replicaNames: - description: - - The replicas of the instance. - returned: success - type: list - serviceAccountEmailAddress: - description: - - The service account email address assigned to the instance. This property - is applicable only to Second Generation instances. - returned: success - type: str - settings: - description: - - The user settings. - returned: success - type: complex - contains: - ipConfiguration: - description: - - The settings for IP Management. This allows to enable or disable the instance - IP and manage which external networks can connect to the instance. The - IPv4 address cannot be disabled for Second Generation instances. - returned: success - type: complex - contains: - ipv4Enabled: - description: - - Whether the instance should be assigned an IP address or not. - returned: success - type: bool - authorizedNetworks: - description: - - The list of external networks that are allowed to connect to the instance - using the IP. In CIDR notation, also known as 'slash' notation (e.g. - 192.168.100.0/24). - returned: success - type: complex - contains: - expirationTime: - description: - - The time when this access control entry expires in RFC 3339 format, - for example 2012-11-15T16:19:00.094Z. - returned: success - type: str +items: + description: List of items + returned: always + type: complex + contains: + backendType: + description: + - "* FIRST_GEN: First Generation instance. MySQL only." + - "* SECOND_GEN: Second Generation instance or PostgreSQL instance." + - "* EXTERNAL: A database server that is not managed by Google." + returned: success + type: str + connectionName: + description: + - Connection name of the Cloud SQL instance used in connection strings. + returned: success + type: str + databaseVersion: + description: + - The database engine type and version. For First Generation instances, can be MYSQL_5_5, + or MYSQL_5_6. For Second Generation instances, can be MYSQL_5_6 or MYSQL_5_7. Defaults + to MYSQL_5_6. + - 'PostgreSQL instances: POSTGRES_9_6 The databaseVersion property can not be changed + after instance creation.' + returned: success + type: str + failoverReplica: + description: + - The name and status of the failover replica. This property is applicable only to + Second Generation instances. + returned: success + type: complex + contains: + available: + description: + - The availability status of the failover replica. A false status indicates that the + failover replica is out of sync. The master can only failover to the falover replica + when the status is true. + returned: success + type: bool name: - description: - - An optional label to identify this entry. - returned: success - type: str - value: - description: - - The whitelisted value for the access control list. For example, - to grant access to a client from an external IP (IPv4 or IPv6) - address or subnet, use that address or subnet here. - returned: success - type: str - requireSsl: - description: - - Whether the mysqld should default to 'REQUIRE X509' for users connecting - over IP. - returned: success - type: bool - tier: - description: - - The tier or machine type for this instance, for example db-n1-standard-1. - For MySQL instances, this field determines whether the instance is Second - Generation (recommended) or First Generation. - returned: success - type: str - availabilityType: - description: - - The availabilityType define if your postgres instance is run zonal or - regional. - returned: success - type: str - backupConfiguration: - description: - - The daily backup configuration for the instance. - returned: success - type: complex - contains: - enabled: - description: - - Enable Autobackup for your instance. - returned: success - type: bool - binaryLogEnabled: - description: - - Whether binary log is enabled. If backup configuration is disabled, - binary log must be disabled as well. MySQL only. - returned: success - type: bool - startTime: - description: - - Define the backup start time in UTC (HH:MM) . - returned: success - type: str - settingsVersion: - description: - - The version of instance settings. This is a required field for update - method to make sure concurrent updates are handled properly. During update, - use the most recent settingsVersion value for this instance and do not - try to update this value. - returned: success - type: int + description: + - The name of the failover replica. If specified at instance creation, a failover + replica is created for the instance. The name doesn't include the project ID. This + property is applicable only to Second Generation instances. + returned: success + type: str + instanceType: + description: + - The instance type. This can be one of the following. + - "* CLOUD_SQL_INSTANCE: A Cloud SQL instance that is not replicating from a master." + - "* ON_PREMISES_INSTANCE: An instance running on the customer's premises." + - "* READ_REPLICA_INSTANCE: A Cloud SQL instance configured as a read-replica." + returned: success + type: str + ipAddresses: + description: + - The assigned IP addresses for the instance. + returned: success + type: complex + contains: + ipAddress: + description: + - The IP address assigned. + returned: success + type: str + timeToRetire: + description: + - The due time for this IP to be retired in RFC 3339 format, for example 2012-11-15T16:19:00.094Z. + This field is only available when the IP is scheduled to be retired. + returned: success + type: str + type: + description: + - The type of this IP address. A PRIMARY address is an address that can accept incoming + connections. An OUTGOING address is the source address of connections originating + from the instance, if supported. + returned: success + type: str + ipv6Address: + description: + - The IPv6 address assigned to the instance. This property is applicable only to First + Generation instances. + returned: success + type: str + masterInstanceName: + description: + - The name of the instance which will act as master in the replication setup. + returned: success + type: str + maxDiskSize: + description: + - The maximum disk size of the instance in bytes. + returned: success + type: int + name: + description: + - Name of the Cloud SQL instance. This does not include the project ID. + returned: success + type: str + region: + description: + - The geographical region. Defaults to us-central or us-central1 depending on the + instance type (First Generation or Second Generation/PostgreSQL). + returned: success + type: str + replicaConfiguration: + description: + - Configuration specific to failover replicas and read replicas. + returned: success + type: complex + contains: + failoverTarget: + description: + - Specifies if the replica is the failover target. If the field is set to true the + replica will be designated as a failover replica. + - In case the master instance fails, the replica instance will be promoted as the + new master instance. + - Only one replica can be specified as failover target, and the replica has to be + in different zone with the master instance. + returned: success + type: bool + mysqlReplicaConfiguration: + description: + - MySQL specific configuration when replicating from a MySQL on-premises master. Replication + configuration information such as the username, password, certificates, and keys + are not stored in the instance metadata. The configuration information is used + only to set up the replication connection and is stored by MySQL in a file named + master.info in the data directory. + returned: success + type: complex + contains: + caCertificate: + description: + - PEM representation of the trusted CA's x509 certificate. + returned: success + type: str + clientCertificate: + description: + - PEM representation of the slave's x509 certificate . + returned: success + type: str + clientKey: + description: + - PEM representation of the slave's private key. The corresponsing public key is encoded + in the client's asf asd certificate. + returned: success + type: str + connectRetryInterval: + description: + - Seconds to wait between connect retries. MySQL's default is 60 seconds. + returned: success + type: int + dumpFilePath: + description: + - Path to a SQL dump file in Google Cloud Storage from which the slave instance is + to be created. The URI is in the form gs://bucketName/fileName. Compressed gzip + files (.gz) are also supported. Dumps should have the binlog co-ordinates from which + replication should begin. This can be accomplished by setting --master-data to 1 + when using mysqldump. + returned: success + type: str + masterHeartbeatPeriod: + description: + - Interval in milliseconds between replication heartbeats. + returned: success + type: int + password: + description: + - The password for the replication connection. + returned: success + type: str + sslCipher: + description: + - A list of permissible ciphers to use for SSL encryption. + returned: success + type: str + username: + description: + - The username for the replication connection. + returned: success + type: str + verifyServerCertificate: + description: + - Whether or not to check the master's Common Name value in the certificate that it + sends during the SSL handshake. + returned: success + type: bool + replicaNames: + description: + - The replicas of the instance. + returned: success + type: list + serviceAccountEmailAddress: + description: + - The service account email address assigned to the instance. This property is applicable + only to Second Generation instances. + returned: success + type: str + settings: + description: + - The user settings. + returned: success + type: complex + contains: + ipConfiguration: + description: + - The settings for IP Management. This allows to enable or disable the instance IP + and manage which external networks can connect to the instance. The IPv4 address + cannot be disabled for Second Generation instances. + returned: success + type: complex + contains: + ipv4Enabled: + description: + - Whether the instance should be assigned an IP address or not. + returned: success + type: bool + authorizedNetworks: + description: + - The list of external networks that are allowed to connect to the instance using + the IP. In CIDR notation, also known as 'slash' notation (e.g. 192.168.100.0/24). + returned: success + type: complex + contains: + expirationTime: + description: + - The time when this access control entry expires in RFC 3339 format, for example + 2012-11-15T16:19:00.094Z. + returned: success + type: str + name: + description: + - An optional label to identify this entry. + returned: success + type: str + value: + description: + - The whitelisted value for the access control list. For example, to grant access + to a client from an external IP (IPv4 or IPv6) address or subnet, use that address + or subnet here. + returned: success + type: str + requireSsl: + description: + - Whether the mysqld should default to 'REQUIRE X509' for users connecting over IP. + returned: success + type: bool + tier: + description: + - The tier or machine type for this instance, for example db-n1-standard-1. For MySQL + instances, this field determines whether the instance is Second Generation (recommended) + or First Generation. + returned: success + type: str + settingsVersion: + description: + - The version of instance settings. This is a required field for update method to + make sure concurrent updates are handled properly. During update, use the most + recent settingsVersion value for this instance and do not try to update this value. + returned: success + type: int ''' ################################################################################ @@ -363,9 +328,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/sqlservice.admin'] items = fetch_list(module, collection(module)) @@ -373,7 +341,9 @@ def main(): items = items.get('items') else: items = [] - return_value = {'resources': items} + return_value = { + 'items': items + } module.exit_json(**return_value) diff --git a/plugins/modules/gcp_sql_user_facts.py b/plugins/modules/gcp_sql_user_facts.py index 5b151ef..63f5862 100644 --- a/plugins/modules/gcp_sql_user_facts.py +++ b/plugins/modules/gcp_sql_user_facts.py @@ -18,78 +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_sql_user_facts description: -- Gather facts for GCP User + - Gather facts for GCP User short_description: Gather facts for GCP User version_added: 2.8 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: - instance: - description: - - The name of the Cloud SQL instance. This does not include the project ID. - - 'This field represents a link to a Instance 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_sql_instance task and then set this instance field to "{{ name-of-resource - }}"' - required: true + instance: + description: + - The name of the Cloud SQL instance. This does not include the project ID. + - 'This field represents a link to a Instance resource in GCP. It can be specified + in two ways. You can add `register: name-of-resource` to a gcp_sql_instance task + and then set this instance field to "{{ name-of-resource }}" Alternatively, you + can set this instance to a dictionary with the name key where the value is the name + of your Instance.' + required: true extends_documentation_fragment: gcp ''' EXAMPLES = ''' -- name: " a user facts" +- name: a user facts gcp_sql_user_facts: - instance: "{{ instance }}" - project: test_project - auth_kind: serviceaccount - service_account_file: "/tmp/auth.pem" - state: facts + instance: "{{ instance }}" + project: test_project + auth_kind: serviceaccount + service_account_file: "/tmp/auth.pem" ''' RETURN = ''' -resources: - description: List of resources - returned: always - type: complex - contains: - host: - description: - - The host name from which the user can connect. For insert operations, host - defaults to an empty string. For update operations, host is specified as part - of the request URL. The host name cannot be updated after insertion. - returned: success - type: str - name: - description: - - The name of the user in the Cloud SQL instance. - returned: success - type: str - instance: - description: - - The name of the Cloud SQL instance. This does not include the project ID. - returned: success - type: dict - password: - description: - - The password for the user. - returned: success - type: str +items: + description: List of items + returned: always + type: complex + contains: + host: + description: + - The host name from which the user can connect. For insert operations, host defaults + to an empty string. For update operations, host is specified as part of the request + URL. The host name cannot be updated after insertion. + returned: success + type: str + name: + description: + - The name of the user in the Cloud SQL instance. + returned: success + type: str + instance: + description: + - The name of the Cloud SQL instance. This does not include the project ID. + returned: success + type: dict + password: + description: + - The password for the user. + returned: success + type: str ''' ################################################################################ @@ -104,9 +104,13 @@ import json def main(): - module = GcpModule(argument_spec=dict(instance=dict(required=True, type='dict'))) + module = GcpModule( + argument_spec=dict( + instance=dict(required=True, type='dict') + ) + ) - if not module.params['scopes']: + if 'scopes' not in module.params: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] items = fetch_list(module, collection(module)) @@ -114,12 +118,17 @@ def main(): items = items.get('items') else: items = [] - return_value = {'resources': items} + return_value = { + 'items': items + } module.exit_json(**return_value) def collection(module): - res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')} + res = { + 'project': module.params['project'], + 'instance': replace_resource_dict(module.params['instance'], 'name') + } return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users".format(**res) diff --git a/tests/integration/gcp_container_cluster/tasks/main.yml b/tests/integration/gcp_container_cluster/tasks/main.yml index ebf2fa5..fa0e746 100644 --- a/tests/integration/gcp_container_cluster/tasks/main.yml +++ b/tests/integration/gcp_container_cluster/tasks/main.yml @@ -15,35 +15,35 @@ # Pre-test setup - name: delete a cluster gcp_container_cluster: - name: my-cluster - initial_node_count: 2 - master_auth: - username: cluster_admin - password: my-secret-password - node_config: - machine_type: n1-standard-4 - disk_size_gb: 500 - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: absent + name: my-cluster + initial_node_count: 2 + master_auth: + username: cluster_admin + password: my-secret-password + node_config: + machine_type: n1-standard-4 + disk_size_gb: 500 + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent #---------------------------------------------------------- - name: create a cluster gcp_container_cluster: - name: my-cluster - initial_node_count: 2 - master_auth: - username: cluster_admin - password: my-secret-password - node_config: - machine_type: n1-standard-4 - disk_size_gb: 500 - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: present + name: my-cluster + initial_node_count: 2 + master_auth: + username: cluster_admin + password: my-secret-password + node_config: + machine_type: n1-standard-4 + disk_size_gb: 500 + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present register: result - name: assert changed is true assert: @@ -51,7 +51,7 @@ - result.changed == true - name: verify that cluster was created gcp_container_cluster_facts: - location: us-central1-a + zone: us-central1-a project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" @@ -61,23 +61,23 @@ - name: verify that command succeeded assert: that: - - "'my-cluster' in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a cluster that already exists gcp_container_cluster: - name: my-cluster - initial_node_count: 2 - master_auth: - username: cluster_admin - password: my-secret-password - node_config: - machine_type: n1-standard-4 - disk_size_gb: 500 - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: present + name: my-cluster + initial_node_count: 2 + master_auth: + username: cluster_admin + password: my-secret-password + node_config: + machine_type: n1-standard-4 + disk_size_gb: 500 + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present register: result - name: assert changed is false assert: @@ -86,19 +86,19 @@ #---------------------------------------------------------- - name: delete a cluster gcp_container_cluster: - name: my-cluster - initial_node_count: 2 - master_auth: - username: cluster_admin - password: my-secret-password - node_config: - machine_type: n1-standard-4 - disk_size_gb: 500 - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: absent + name: my-cluster + initial_node_count: 2 + master_auth: + username: cluster_admin + password: my-secret-password + node_config: + machine_type: n1-standard-4 + disk_size_gb: 500 + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent register: result - name: assert changed is true assert: @@ -106,7 +106,7 @@ - result.changed == true - name: verify that cluster was deleted gcp_container_cluster_facts: - location: us-central1-a + zone: us-central1-a project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" service_account_file: "{{ gcp_cred_file }}" @@ -116,23 +116,23 @@ - name: verify that command succeeded assert: that: - - "'my-cluster' not in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length == 0 # ---------------------------------------------------------------------------- - name: delete a cluster that does not exist gcp_container_cluster: - name: my-cluster - initial_node_count: 2 - master_auth: - username: cluster_admin - password: my-secret-password - node_config: - machine_type: n1-standard-4 - disk_size_gb: 500 - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: absent + name: my-cluster + initial_node_count: 2 + master_auth: + username: cluster_admin + password: my-secret-password + node_config: + machine_type: n1-standard-4 + disk_size_gb: 500 + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent register: result - name: assert changed is false assert: diff --git a/tests/integration/gcp_container_node_pool/tasks/main.yml b/tests/integration/gcp_container_node_pool/tasks/main.yml index b5d1623..ed294eb 100644 --- a/tests/integration/gcp_container_node_pool/tasks/main.yml +++ b/tests/integration/gcp_container_node_pool/tasks/main.yml @@ -25,25 +25,25 @@ register: cluster - name: delete a node pool gcp_container_node_pool: - name: my-pool - initial_node_count: 4 - cluster: "{{ cluster }}" - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: absent + name: my-pool + initial_node_count: 4 + cluster: "{{ cluster }}" + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent #---------------------------------------------------------- - name: create a node pool gcp_container_node_pool: - name: my-pool - initial_node_count: 4 - cluster: "{{ cluster }}" - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: present + name: my-pool + initial_node_count: 4 + cluster: "{{ cluster }}" + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present register: result - name: assert changed is true assert: @@ -51,8 +51,6 @@ - result.changed == true - name: verify that node_pool was created gcp_container_node_pool_facts: - filters: - - name = {{ resource_name }} cluster: "{{ cluster }}" zone: us-central1-a project: "{{ gcp_project }}" @@ -64,18 +62,18 @@ - name: verify that command succeeded assert: that: - - "'my-pool' in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a node pool that already exists gcp_container_node_pool: - name: my-pool - initial_node_count: 4 - cluster: "{{ cluster }}" - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: present + name: my-pool + initial_node_count: 4 + cluster: "{{ cluster }}" + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present register: result - name: assert changed is false assert: @@ -84,14 +82,14 @@ #---------------------------------------------------------- - name: delete a node pool gcp_container_node_pool: - name: my-pool - initial_node_count: 4 - cluster: "{{ cluster }}" - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: absent + name: my-pool + initial_node_count: 4 + cluster: "{{ cluster }}" + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent register: result - name: assert changed is true assert: @@ -99,8 +97,6 @@ - result.changed == true - name: verify that node_pool was deleted gcp_container_node_pool_facts: - filters: - - name = {{ resource_name }} cluster: "{{ cluster }}" zone: us-central1-a project: "{{ gcp_project }}" @@ -116,14 +112,14 @@ # ---------------------------------------------------------------------------- - name: delete a node pool that does not exist gcp_container_node_pool: - name: my-pool - initial_node_count: 4 - cluster: "{{ cluster }}" - location: us-central1-a - project: "{{ gcp_project }}" - auth_kind: "{{ gcp_cred_kind }}" - service_account_file: "{{ gcp_cred_file }}" - state: absent + name: my-pool + initial_node_count: 4 + cluster: "{{ cluster }}" + zone: us-central1-a + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_cred_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent register: result - name: assert changed is false assert: diff --git a/tests/integration/gcp_pubsub_subscription/tasks/main.yml b/tests/integration/gcp_pubsub_subscription/tasks/main.yml index 741ff4a..1c132b7 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: - - results['items'] | length == 1 + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a subscription that already exists gcp_pubsub_subscription: diff --git a/tests/integration/gcp_pubsub_topic/tasks/main.yml b/tests/integration/gcp_pubsub_topic/tasks/main.yml index 56fc024..4227a95 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: - - results['items'] | length == 1 + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a topic that already exists gcp_pubsub_topic: diff --git a/tests/integration/gcp_spanner_database/tasks/main.yml b/tests/integration/gcp_spanner_database/tasks/main.yml index c059ad2..9f415ee 100644 --- a/tests/integration/gcp_spanner_database/tasks/main.yml +++ b/tests/integration/gcp_spanner_database/tasks/main.yml @@ -60,7 +60,7 @@ - name: verify that command succeeded assert: that: - - "'webstore' in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a database that already exists gcp_spanner_database: @@ -101,7 +101,7 @@ - name: verify that command succeeded assert: that: - - "'webstore' not in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length == 0 # ---------------------------------------------------------------------------- - name: delete a database that does not exist gcp_spanner_database: diff --git a/tests/integration/gcp_spanner_instance/tasks/main.yml b/tests/integration/gcp_spanner_instance/tasks/main.yml index 15c7206..7c91778 100644 --- a/tests/integration/gcp_spanner_instance/tasks/main.yml +++ b/tests/integration/gcp_spanner_instance/tasks/main.yml @@ -54,7 +54,7 @@ - name: verify that command succeeded assert: that: - - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a instance that already exists gcp_spanner_instance: @@ -102,7 +102,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 instance that does not exist gcp_spanner_instance: diff --git a/tests/integration/gcp_sql_database/tasks/main.yml b/tests/integration/gcp_sql_database/tasks/main.yml index 5321004..a7d1ddd 100644 --- a/tests/integration/gcp_sql_database/tasks/main.yml +++ b/tests/integration/gcp_sql_database/tasks/main.yml @@ -65,7 +65,7 @@ - name: verify that command succeeded assert: that: - - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a database that already exists gcp_sql_database: @@ -110,7 +110,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 database that does not exist gcp_sql_database: diff --git a/tests/integration/gcp_sql_instance/tasks/main.yml b/tests/integration/gcp_sql_instance/tasks/main.yml index af75218..eace727 100644 --- a/tests/integration/gcp_sql_instance/tasks/main.yml +++ b/tests/integration/gcp_sql_instance/tasks/main.yml @@ -59,7 +59,7 @@ - name: verify that command succeeded assert: that: - - results['resources'] | length >= 1 + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a instance that already exists gcp_sql_instance: @@ -113,7 +113,7 @@ - name: verify that command succeeded assert: that: - - results['resources'] | length == 0 + - results['items'] | length == 0 # ---------------------------------------------------------------------------- - name: delete a instance that does not exist gcp_sql_instance: diff --git a/tests/integration/gcp_sql_user/tasks/main.yml b/tests/integration/gcp_sql_user/tasks/main.yml index 013e0b3..66f81ac 100644 --- a/tests/integration/gcp_sql_user/tasks/main.yml +++ b/tests/integration/gcp_sql_user/tasks/main.yml @@ -57,8 +57,6 @@ - "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 }}" @@ -69,7 +67,7 @@ - name: verify that command succeeded assert: that: - - "'test-user' in \"{{ results['items'] | map(attribute='name') | list }}\"" + - results['items'] | length >= 1 # ---------------------------------------------------------------------------- - name: create a user that already exists gcp_sql_user: @@ -106,8 +104,6 @@ - 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 }}"