mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-06 10:50:28 -07:00
* region url map * region instance group manager * target http/https proxy * region autoscaler * revert some files * adding min_version on TF * Update products/compute/examples/ansible/region_target_https_proxy.yaml Co-Authored-By: Chris Hawk <41700375+SirGitsalot@users.noreply.github.com> Co-authored-by: Chris Hawk <41700375+SirGitsalot@users.noreply.github.com> Signed-off-by: Modular Magician <magic-modules@google.com> Co-authored-by: Chris Hawk <41700375+SirGitsalot@users.noreply.github.com>
This commit is contained in:
parent
0471d79d2f
commit
1adb69f09a
36 changed files with 10776 additions and 0 deletions
|
@ -35,12 +35,15 @@ ansible-galaxy collection install google.cloud
|
||||||
* Compute Engine Instance (gcp_compute_instance, gcp_compute_instance_facts)
|
* Compute Engine Instance (gcp_compute_instance, gcp_compute_instance_facts)
|
||||||
* Compute Engine InstanceGroup (gcp_compute_instance_group, gcp_compute_instance_group_facts)
|
* Compute Engine InstanceGroup (gcp_compute_instance_group, gcp_compute_instance_group_facts)
|
||||||
* Compute Engine InstanceGroupManager (gcp_compute_instance_group_manager, gcp_compute_instance_group_manager_facts)
|
* Compute Engine InstanceGroupManager (gcp_compute_instance_group_manager, gcp_compute_instance_group_manager_facts)
|
||||||
|
* Compute Engine RegionInstanceGroupManager (gcp_compute_region_instance_group_manager, gcp_compute_region_instance_group_manager_facts)
|
||||||
* Compute Engine InterconnectAttachment (gcp_compute_interconnect_attachment, gcp_compute_interconnect_attachment_facts)
|
* Compute Engine InterconnectAttachment (gcp_compute_interconnect_attachment, gcp_compute_interconnect_attachment_facts)
|
||||||
* Compute Engine Network (gcp_compute_network, gcp_compute_network_facts)
|
* Compute Engine Network (gcp_compute_network, gcp_compute_network_facts)
|
||||||
* Compute Engine NetworkEndpointGroup (gcp_compute_network_endpoint_group, gcp_compute_network_endpoint_group_facts)
|
* Compute Engine NetworkEndpointGroup (gcp_compute_network_endpoint_group, gcp_compute_network_endpoint_group_facts)
|
||||||
* Compute Engine NodeGroup (gcp_compute_node_group, gcp_compute_node_group_facts)
|
* Compute Engine NodeGroup (gcp_compute_node_group, gcp_compute_node_group_facts)
|
||||||
* Compute Engine NodeTemplate (gcp_compute_node_template, gcp_compute_node_template_facts)
|
* Compute Engine NodeTemplate (gcp_compute_node_template, gcp_compute_node_template_facts)
|
||||||
|
* Compute Engine RegionAutoscaler (gcp_compute_region_autoscaler, gcp_compute_region_autoscaler_facts)
|
||||||
* Compute Engine RegionDisk (gcp_compute_region_disk, gcp_compute_region_disk_facts)
|
* Compute Engine RegionDisk (gcp_compute_region_disk, gcp_compute_region_disk_facts)
|
||||||
|
* Compute Engine RegionUrlMap (gcp_compute_region_url_map, gcp_compute_region_url_map_facts)
|
||||||
* Compute Engine RegionHealthCheck (gcp_compute_region_health_check, gcp_compute_region_health_check_facts)
|
* Compute Engine RegionHealthCheck (gcp_compute_region_health_check, gcp_compute_region_health_check_facts)
|
||||||
* Compute Engine Route (gcp_compute_route, gcp_compute_route_facts)
|
* Compute Engine Route (gcp_compute_route, gcp_compute_route_facts)
|
||||||
* Compute Engine Router (gcp_compute_router, gcp_compute_router_facts)
|
* Compute Engine Router (gcp_compute_router, gcp_compute_router_facts)
|
||||||
|
@ -51,6 +54,8 @@ ansible-galaxy collection install google.cloud
|
||||||
* Compute Engine Subnetwork (gcp_compute_subnetwork, gcp_compute_subnetwork_facts)
|
* Compute Engine Subnetwork (gcp_compute_subnetwork, gcp_compute_subnetwork_facts)
|
||||||
* Compute Engine TargetHttpProxy (gcp_compute_target_http_proxy, gcp_compute_target_http_proxy_facts)
|
* Compute Engine TargetHttpProxy (gcp_compute_target_http_proxy, gcp_compute_target_http_proxy_facts)
|
||||||
* Compute Engine TargetHttpsProxy (gcp_compute_target_https_proxy, gcp_compute_target_https_proxy_facts)
|
* Compute Engine TargetHttpsProxy (gcp_compute_target_https_proxy, gcp_compute_target_https_proxy_facts)
|
||||||
|
* Compute Engine RegionTargetHttpProxy (gcp_compute_region_target_http_proxy, gcp_compute_region_target_http_proxy_facts)
|
||||||
|
* Compute Engine RegionTargetHttpsProxy (gcp_compute_region_target_https_proxy, gcp_compute_region_target_https_proxy_facts)
|
||||||
* Compute Engine TargetInstance (gcp_compute_target_instance, gcp_compute_target_instance_facts)
|
* Compute Engine TargetInstance (gcp_compute_target_instance, gcp_compute_target_instance_facts)
|
||||||
* Compute Engine TargetPool (gcp_compute_target_pool, gcp_compute_target_pool_facts)
|
* Compute Engine TargetPool (gcp_compute_target_pool, gcp_compute_target_pool_facts)
|
||||||
* Compute Engine TargetSslProxy (gcp_compute_target_ssl_proxy, gcp_compute_target_ssl_proxy_facts)
|
* Compute Engine TargetSslProxy (gcp_compute_target_ssl_proxy, gcp_compute_target_ssl_proxy_facts)
|
||||||
|
|
750
plugins/modules/gcp_compute_region_autoscaler.py
Normal file
750
plugins/modules/gcp_compute_region_autoscaler.py
Normal file
|
@ -0,0 +1,750 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_autoscaler
|
||||||
|
description:
|
||||||
|
- Represents an Autoscaler resource.
|
||||||
|
- Autoscalers allow you to automatically scale virtual machine instances in managed
|
||||||
|
instance groups according to an autoscaling policy that you define.
|
||||||
|
short_description: Creates a GCP RegionAutoscaler
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Whether the given object should exist in GCP
|
||||||
|
choices:
|
||||||
|
- present
|
||||||
|
- absent
|
||||||
|
default: present
|
||||||
|
type: str
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. The name must be 1-63 characters long and match the regular
|
||||||
|
expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must
|
||||||
|
be a lowercase letter, and all following characters must be a dash, lowercase
|
||||||
|
letter, or digit, except the last character, which cannot be a dash.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
autoscaling_policy:
|
||||||
|
description:
|
||||||
|
- 'The configuration parameters for the autoscaling algorithm. You can define
|
||||||
|
one or more of the policies for an autoscaler: cpuUtilization, customMetricUtilizations,
|
||||||
|
and loadBalancingUtilization.'
|
||||||
|
- If none of these are specified, the default will be to autoscale based on cpuUtilization
|
||||||
|
to 0.6 or 60%.
|
||||||
|
required: true
|
||||||
|
type: dict
|
||||||
|
suboptions:
|
||||||
|
min_num_replicas:
|
||||||
|
description:
|
||||||
|
- The minimum number of replicas that the autoscaler can scale down to. This
|
||||||
|
cannot be less than 0. If not provided, autoscaler will choose a default
|
||||||
|
value depending on maximum number of instances allowed.
|
||||||
|
required: false
|
||||||
|
type: int
|
||||||
|
max_num_replicas:
|
||||||
|
description:
|
||||||
|
- The maximum number of instances that the autoscaler can scale up to. This
|
||||||
|
is required when creating or updating an autoscaler. The maximum number
|
||||||
|
of replicas should not be lower than minimal number of replicas.
|
||||||
|
required: true
|
||||||
|
type: int
|
||||||
|
cool_down_period_sec:
|
||||||
|
description:
|
||||||
|
- The number of seconds that the autoscaler should wait before it starts collecting
|
||||||
|
information from a new instance. This prevents the autoscaler from collecting
|
||||||
|
information when the instance is initializing, during which the collected
|
||||||
|
usage would not be reliable. The default time autoscaler waits is 60 seconds.
|
||||||
|
- Virtual machine initialization times might vary because of numerous factors.
|
||||||
|
We recommend that you test how long an instance may take to initialize.
|
||||||
|
To do this, create an instance and time the startup process.
|
||||||
|
required: false
|
||||||
|
default: '60'
|
||||||
|
type: int
|
||||||
|
cpu_utilization:
|
||||||
|
description:
|
||||||
|
- Defines the CPU utilization policy that allows the autoscaler to scale based
|
||||||
|
on the average CPU utilization of a managed instance group.
|
||||||
|
required: false
|
||||||
|
type: dict
|
||||||
|
suboptions:
|
||||||
|
utilization_target:
|
||||||
|
description:
|
||||||
|
- The target CPU utilization that the autoscaler should maintain.
|
||||||
|
- Must be a float value in the range (0, 1]. If not specified, the default
|
||||||
|
is 0.6.
|
||||||
|
- If the CPU level is below the target utilization, the autoscaler scales
|
||||||
|
down the number of instances until it reaches the minimum number of
|
||||||
|
instances you specified or until the average CPU of your instances reaches
|
||||||
|
the target utilization.
|
||||||
|
- If the average CPU is above the target utilization, the autoscaler scales
|
||||||
|
up until it reaches the maximum number of instances you specified or
|
||||||
|
until the average utilization reaches the target utilization.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
custom_metric_utilizations:
|
||||||
|
description:
|
||||||
|
- Configuration parameters of autoscaling based on a custom metric.
|
||||||
|
elements: dict
|
||||||
|
required: false
|
||||||
|
type: list
|
||||||
|
suboptions:
|
||||||
|
metric:
|
||||||
|
description:
|
||||||
|
- The identifier (type) of the Stackdriver Monitoring metric.
|
||||||
|
- The metric cannot have negative values.
|
||||||
|
- The metric must have a value type of INT64 or DOUBLE.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
utilization_target:
|
||||||
|
description:
|
||||||
|
- The target value of the metric that autoscaler should maintain. This
|
||||||
|
must be a positive value. A utilization metric scales number of virtual
|
||||||
|
machines handling requests to increase or decrease proportionally to
|
||||||
|
the metric.
|
||||||
|
- For example, a good metric to use as a utilizationTarget is U(www.googleapis.com/compute/instance/network/received_bytes_count).
|
||||||
|
- The autoscaler will work to keep this value constant for each of the
|
||||||
|
instances.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
utilization_target_type:
|
||||||
|
description:
|
||||||
|
- Defines how target utilization value is expressed for a Stackdriver
|
||||||
|
Monitoring metric. Either GAUGE, DELTA_PER_SECOND, or DELTA_PER_MINUTE.
|
||||||
|
- 'Some valid choices include: "GAUGE", "DELTA_PER_SECOND", "DELTA_PER_MINUTE"'
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
load_balancing_utilization:
|
||||||
|
description:
|
||||||
|
- Configuration parameters of autoscaling based on a load balancer.
|
||||||
|
required: false
|
||||||
|
type: dict
|
||||||
|
suboptions:
|
||||||
|
utilization_target:
|
||||||
|
description:
|
||||||
|
- Fraction of backend capacity utilization (set in HTTP(s) load balancing
|
||||||
|
configuration) that autoscaler should maintain. Must be a positive float
|
||||||
|
value. If not defined, the default is 0.8.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
target:
|
||||||
|
description:
|
||||||
|
- URL of the managed instance group that this autoscaler will scale.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- URL of the region where the instance group resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- 'API Reference: U(https://cloud.google.com/compute/docs/reference/rest/v1/regionAutoscalers)'
|
||||||
|
- 'Autoscaling Groups of Instances: U(https://cloud.google.com/compute/docs/autoscaler/)'
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: create a network
|
||||||
|
google.cloud.gcp_compute_network:
|
||||||
|
name: network-instancetemplate
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- name: create a address
|
||||||
|
google.cloud.gcp_compute_address:
|
||||||
|
name: address-instancetemplate
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: address
|
||||||
|
|
||||||
|
- name: create a instance template
|
||||||
|
google.cloud.gcp_compute_instance_template:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
properties:
|
||||||
|
disks:
|
||||||
|
- auto_delete: 'true'
|
||||||
|
boot: 'true'
|
||||||
|
initialize_params:
|
||||||
|
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ network }}"
|
||||||
|
access_configs:
|
||||||
|
- name: test-config
|
||||||
|
type: ONE_TO_ONE_NAT
|
||||||
|
nat_ip: "{{ address }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancetemplate
|
||||||
|
|
||||||
|
- name: create a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: igrm
|
||||||
|
|
||||||
|
- name: create a region autoscaler
|
||||||
|
google.cloud.gcp_compute_region_autoscaler:
|
||||||
|
name: my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
autoscaling_policy:
|
||||||
|
min_num_replicas: 1
|
||||||
|
max_num_replicas: 5
|
||||||
|
cool_down_period_sec: 60
|
||||||
|
cpu_utilization:
|
||||||
|
utilization_target: 0.5
|
||||||
|
target: "{{igrm.selfLink}}"
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
state: present
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- Unique identifier for the resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- Creation timestamp in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. The name must be 1-63 characters long and match the regular
|
||||||
|
expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be
|
||||||
|
a lowercase letter, and all following characters must be a dash, lowercase letter,
|
||||||
|
or digit, except the last character, which cannot be a dash.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
autoscalingPolicy:
|
||||||
|
description:
|
||||||
|
- 'The configuration parameters for the autoscaling algorithm. You can define one
|
||||||
|
or more of the policies for an autoscaler: cpuUtilization, customMetricUtilizations,
|
||||||
|
and loadBalancingUtilization.'
|
||||||
|
- If none of these are specified, the default will be to autoscale based on cpuUtilization
|
||||||
|
to 0.6 or 60%.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
minNumReplicas:
|
||||||
|
description:
|
||||||
|
- The minimum number of replicas that the autoscaler can scale down to. This
|
||||||
|
cannot be less than 0. If not provided, autoscaler will choose a default value
|
||||||
|
depending on maximum number of instances allowed.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
maxNumReplicas:
|
||||||
|
description:
|
||||||
|
- The maximum number of instances that the autoscaler can scale up to. This
|
||||||
|
is required when creating or updating an autoscaler. The maximum number of
|
||||||
|
replicas should not be lower than minimal number of replicas.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
coolDownPeriodSec:
|
||||||
|
description:
|
||||||
|
- The number of seconds that the autoscaler should wait before it starts collecting
|
||||||
|
information from a new instance. This prevents the autoscaler from collecting
|
||||||
|
information when the instance is initializing, during which the collected
|
||||||
|
usage would not be reliable. The default time autoscaler waits is 60 seconds.
|
||||||
|
- Virtual machine initialization times might vary because of numerous factors.
|
||||||
|
We recommend that you test how long an instance may take to initialize. To
|
||||||
|
do this, create an instance and time the startup process.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
cpuUtilization:
|
||||||
|
description:
|
||||||
|
- Defines the CPU utilization policy that allows the autoscaler to scale based
|
||||||
|
on the average CPU utilization of a managed instance group.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
utilizationTarget:
|
||||||
|
description:
|
||||||
|
- The target CPU utilization that the autoscaler should maintain.
|
||||||
|
- Must be a float value in the range (0, 1]. If not specified, the default
|
||||||
|
is 0.6.
|
||||||
|
- If the CPU level is below the target utilization, the autoscaler scales
|
||||||
|
down the number of instances until it reaches the minimum number of instances
|
||||||
|
you specified or until the average CPU of your instances reaches the target
|
||||||
|
utilization.
|
||||||
|
- If the average CPU is above the target utilization, the autoscaler scales
|
||||||
|
up until it reaches the maximum number of instances you specified or until
|
||||||
|
the average utilization reaches the target utilization.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
customMetricUtilizations:
|
||||||
|
description:
|
||||||
|
- Configuration parameters of autoscaling based on a custom metric.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
metric:
|
||||||
|
description:
|
||||||
|
- The identifier (type) of the Stackdriver Monitoring metric.
|
||||||
|
- The metric cannot have negative values.
|
||||||
|
- The metric must have a value type of INT64 or DOUBLE.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
utilizationTarget:
|
||||||
|
description:
|
||||||
|
- The target value of the metric that autoscaler should maintain. This must
|
||||||
|
be a positive value. A utilization metric scales number of virtual machines
|
||||||
|
handling requests to increase or decrease proportionally to the metric.
|
||||||
|
- For example, a good metric to use as a utilizationTarget is U(www.googleapis.com/compute/instance/network/received_bytes_count).
|
||||||
|
- The autoscaler will work to keep this value constant for each of the instances.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
utilizationTargetType:
|
||||||
|
description:
|
||||||
|
- Defines how target utilization value is expressed for a Stackdriver Monitoring
|
||||||
|
metric. Either GAUGE, DELTA_PER_SECOND, or DELTA_PER_MINUTE.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
loadBalancingUtilization:
|
||||||
|
description:
|
||||||
|
- Configuration parameters of autoscaling based on a load balancer.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
utilizationTarget:
|
||||||
|
description:
|
||||||
|
- Fraction of backend capacity utilization (set in HTTP(s) load balancing
|
||||||
|
configuration) that autoscaler should maintain. Must be a positive float
|
||||||
|
value. If not defined, the default is 0.8.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
target:
|
||||||
|
description:
|
||||||
|
- URL of the managed instance group that this autoscaler will scale.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- URL of the region where the instance group resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import (
|
||||||
|
navigate_hash,
|
||||||
|
GcpSession,
|
||||||
|
GcpModule,
|
||||||
|
GcpRequest,
|
||||||
|
remove_nones_from_dict,
|
||||||
|
replace_resource_dict,
|
||||||
|
)
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main function"""
|
||||||
|
|
||||||
|
module = GcpModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
|
name=dict(required=True, type='str'),
|
||||||
|
description=dict(type='str'),
|
||||||
|
autoscaling_policy=dict(
|
||||||
|
required=True,
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
|
min_num_replicas=dict(type='int'),
|
||||||
|
max_num_replicas=dict(required=True, type='int'),
|
||||||
|
cool_down_period_sec=dict(default=60, type='int'),
|
||||||
|
cpu_utilization=dict(type='dict', options=dict(utilization_target=dict(type='str'))),
|
||||||
|
custom_metric_utilizations=dict(
|
||||||
|
type='list',
|
||||||
|
elements='dict',
|
||||||
|
options=dict(metric=dict(required=True, type='str'), utilization_target=dict(type='str'), utilization_target_type=dict(type='str')),
|
||||||
|
),
|
||||||
|
load_balancing_utilization=dict(type='dict', options=dict(utilization_target=dict(type='str'))),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
target=dict(required=True, type='str'),
|
||||||
|
region=dict(required=True, type='str'),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
state = module.params['state']
|
||||||
|
kind = 'compute#autoscaler'
|
||||||
|
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
if fetch:
|
||||||
|
if state == 'present':
|
||||||
|
if is_different(module, fetch):
|
||||||
|
update(module, self_link(module), kind)
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
delete(module, self_link(module), kind)
|
||||||
|
fetch = {}
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
if state == 'present':
|
||||||
|
fetch = create(module, collection(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
fetch = {}
|
||||||
|
|
||||||
|
fetch.update({'changed': changed})
|
||||||
|
|
||||||
|
module.exit_json(**fetch)
|
||||||
|
|
||||||
|
|
||||||
|
def create(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
|
def update(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
|
def delete(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
|
||||||
|
def resource_to_request(module):
|
||||||
|
request = {
|
||||||
|
u'kind': 'compute#autoscaler',
|
||||||
|
u'region': module.params.get('region'),
|
||||||
|
u'name': module.params.get('name'),
|
||||||
|
u'description': module.params.get('description'),
|
||||||
|
u'autoscalingPolicy': RegionAutoscalerAutoscalingpolicy(module.params.get('autoscaling_policy', {}), module).to_request(),
|
||||||
|
u'target': module.params.get('target'),
|
||||||
|
}
|
||||||
|
return_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if v or v is False:
|
||||||
|
return_vals[k] = v
|
||||||
|
|
||||||
|
return return_vals
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_resource(module, link, kind, allow_not_found=True):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return return_if_object(module, auth.get(link), kind, allow_not_found)
|
||||||
|
|
||||||
|
|
||||||
|
def self_link(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/autoscalers/{name}".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/autoscalers".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if allow_not_found and response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def is_different(module, response):
|
||||||
|
request = resource_to_request(module)
|
||||||
|
response = response_to_hash(module, response)
|
||||||
|
|
||||||
|
# Remove all output-only from response.
|
||||||
|
response_vals = {}
|
||||||
|
for k, v in response.items():
|
||||||
|
if k in request:
|
||||||
|
response_vals[k] = v
|
||||||
|
|
||||||
|
request_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if k in response:
|
||||||
|
request_vals[k] = v
|
||||||
|
|
||||||
|
return GcpRequest(request_vals) != GcpRequest(response_vals)
|
||||||
|
|
||||||
|
|
||||||
|
# Remove unnecessary properties from the response.
|
||||||
|
# This is for doing comparisons with Ansible's current parameters.
|
||||||
|
def response_to_hash(module, response):
|
||||||
|
return {
|
||||||
|
u'id': response.get(u'id'),
|
||||||
|
u'creationTimestamp': response.get(u'creationTimestamp'),
|
||||||
|
u'name': module.params.get('name'),
|
||||||
|
u'description': response.get(u'description'),
|
||||||
|
u'autoscalingPolicy': RegionAutoscalerAutoscalingpolicy(response.get(u'autoscalingPolicy', {}), module).from_response(),
|
||||||
|
u'target': response.get(u'target'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def async_op_url(module, extra_data=None):
|
||||||
|
if extra_data is None:
|
||||||
|
extra_data = {}
|
||||||
|
url = "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/operations/{op_id}"
|
||||||
|
combined = extra_data.copy()
|
||||||
|
combined.update(module.params)
|
||||||
|
return url.format(**combined)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_operation(module, response):
|
||||||
|
op_result = return_if_object(module, response, 'compute#operation')
|
||||||
|
if op_result is None:
|
||||||
|
return {}
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#autoscaler')
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_completion(status, op_result, module):
|
||||||
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
|
while status != 'DONE':
|
||||||
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
|
time.sleep(1.0)
|
||||||
|
op_result = fetch_resource(module, op_uri, 'compute#operation', False)
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
return op_result
|
||||||
|
|
||||||
|
|
||||||
|
def raise_if_errors(response, err_path, module):
|
||||||
|
errors = navigate_hash(response, err_path)
|
||||||
|
if errors is not None:
|
||||||
|
module.fail_json(msg=errors)
|
||||||
|
|
||||||
|
|
||||||
|
class RegionAutoscalerAutoscalingpolicy(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = {}
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
|
u'minNumReplicas': self.request.get('min_num_replicas'),
|
||||||
|
u'maxNumReplicas': self.request.get('max_num_replicas'),
|
||||||
|
u'coolDownPeriodSec': self.request.get('cool_down_period_sec'),
|
||||||
|
u'cpuUtilization': RegionAutoscalerCpuutilization(self.request.get('cpu_utilization', {}), self.module).to_request(),
|
||||||
|
u'customMetricUtilizations': RegionAutoscalerCustommetricutilizationsArray(
|
||||||
|
self.request.get('custom_metric_utilizations', []), self.module
|
||||||
|
).to_request(),
|
||||||
|
u'loadBalancingUtilization': RegionAutoscalerLoadbalancingutilization(
|
||||||
|
self.request.get('load_balancing_utilization', {}), self.module
|
||||||
|
).to_request(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
|
u'minNumReplicas': self.request.get(u'minNumReplicas'),
|
||||||
|
u'maxNumReplicas': self.request.get(u'maxNumReplicas'),
|
||||||
|
u'coolDownPeriodSec': self.request.get(u'coolDownPeriodSec'),
|
||||||
|
u'cpuUtilization': RegionAutoscalerCpuutilization(self.request.get(u'cpuUtilization', {}), self.module).from_response(),
|
||||||
|
u'customMetricUtilizations': RegionAutoscalerCustommetricutilizationsArray(
|
||||||
|
self.request.get(u'customMetricUtilizations', []), self.module
|
||||||
|
).from_response(),
|
||||||
|
u'loadBalancingUtilization': RegionAutoscalerLoadbalancingutilization(
|
||||||
|
self.request.get(u'loadBalancingUtilization', {}), self.module
|
||||||
|
).from_response(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RegionAutoscalerCpuutilization(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = {}
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
return remove_nones_from_dict({u'utilizationTarget': self.request.get('utilization_target')})
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
return remove_nones_from_dict({u'utilizationTarget': self.request.get(u'utilizationTarget')})
|
||||||
|
|
||||||
|
|
||||||
|
class RegionAutoscalerCustommetricutilizationsArray(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = []
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
items = []
|
||||||
|
for item in self.request:
|
||||||
|
items.append(self._request_for_item(item))
|
||||||
|
return items
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
items = []
|
||||||
|
for item in self.request:
|
||||||
|
items.append(self._response_from_item(item))
|
||||||
|
return items
|
||||||
|
|
||||||
|
def _request_for_item(self, item):
|
||||||
|
return remove_nones_from_dict(
|
||||||
|
{u'metric': item.get('metric'), u'utilizationTarget': item.get('utilization_target'), u'utilizationTargetType': item.get('utilization_target_type')}
|
||||||
|
)
|
||||||
|
|
||||||
|
def _response_from_item(self, item):
|
||||||
|
return remove_nones_from_dict(
|
||||||
|
{u'metric': item.get(u'metric'), u'utilizationTarget': item.get(u'utilizationTarget'), u'utilizationTargetType': item.get(u'utilizationTargetType')}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RegionAutoscalerLoadbalancingutilization(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = {}
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
return remove_nones_from_dict({u'utilizationTarget': self.request.get('utilization_target')})
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
return remove_nones_from_dict({u'utilizationTarget': self.request.get(u'utilizationTarget')})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
326
plugins/modules/gcp_compute_region_autoscaler_info.py
Normal file
326
plugins/modules/gcp_compute_region_autoscaler_info.py
Normal file
|
@ -0,0 +1,326 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_autoscaler_info
|
||||||
|
description:
|
||||||
|
- Gather info for GCP RegionAutoscaler
|
||||||
|
short_description: Gather info for GCP RegionAutoscaler
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
filters:
|
||||||
|
description:
|
||||||
|
- A list of filter value pairs. Available filters are listed here U(https://cloud.google.com/sdk/gcloud/reference/topic/filters).
|
||||||
|
- Each additional filter in the list will act be added as an AND condition (filter1
|
||||||
|
and filter2) .
|
||||||
|
type: list
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- URL of the region where the instance group resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: get info on a region autoscaler
|
||||||
|
gcp_compute_region_autoscaler_info:
|
||||||
|
region: us-central1
|
||||||
|
filters:
|
||||||
|
- name = test_object
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
resources:
|
||||||
|
description: List of resources
|
||||||
|
returned: always
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- Unique identifier for the resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- Creation timestamp in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. The name must be 1-63 characters long and match the
|
||||||
|
regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character
|
||||||
|
must be a lowercase letter, and all following characters must be a dash, lowercase
|
||||||
|
letter, or digit, except the last character, which cannot be a dash.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
autoscalingPolicy:
|
||||||
|
description:
|
||||||
|
- 'The configuration parameters for the autoscaling algorithm. You can define
|
||||||
|
one or more of the policies for an autoscaler: cpuUtilization, customMetricUtilizations,
|
||||||
|
and loadBalancingUtilization.'
|
||||||
|
- If none of these are specified, the default will be to autoscale based on
|
||||||
|
cpuUtilization to 0.6 or 60%.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
minNumReplicas:
|
||||||
|
description:
|
||||||
|
- The minimum number of replicas that the autoscaler can scale down to.
|
||||||
|
This cannot be less than 0. If not provided, autoscaler will choose a
|
||||||
|
default value depending on maximum number of instances allowed.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
maxNumReplicas:
|
||||||
|
description:
|
||||||
|
- The maximum number of instances that the autoscaler can scale up to. This
|
||||||
|
is required when creating or updating an autoscaler. The maximum number
|
||||||
|
of replicas should not be lower than minimal number of replicas.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
coolDownPeriodSec:
|
||||||
|
description:
|
||||||
|
- The number of seconds that the autoscaler should wait before it starts
|
||||||
|
collecting information from a new instance. This prevents the autoscaler
|
||||||
|
from collecting information when the instance is initializing, during
|
||||||
|
which the collected usage would not be reliable. The default time autoscaler
|
||||||
|
waits is 60 seconds.
|
||||||
|
- Virtual machine initialization times might vary because of numerous factors.
|
||||||
|
We recommend that you test how long an instance may take to initialize.
|
||||||
|
To do this, create an instance and time the startup process.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
cpuUtilization:
|
||||||
|
description:
|
||||||
|
- Defines the CPU utilization policy that allows the autoscaler to scale
|
||||||
|
based on the average CPU utilization of a managed instance group.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
utilizationTarget:
|
||||||
|
description:
|
||||||
|
- The target CPU utilization that the autoscaler should maintain.
|
||||||
|
- Must be a float value in the range (0, 1]. If not specified, the default
|
||||||
|
is 0.6.
|
||||||
|
- If the CPU level is below the target utilization, the autoscaler scales
|
||||||
|
down the number of instances until it reaches the minimum number of
|
||||||
|
instances you specified or until the average CPU of your instances
|
||||||
|
reaches the target utilization.
|
||||||
|
- If the average CPU is above the target utilization, the autoscaler
|
||||||
|
scales up until it reaches the maximum number of instances you specified
|
||||||
|
or until the average utilization reaches the target utilization.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
customMetricUtilizations:
|
||||||
|
description:
|
||||||
|
- Configuration parameters of autoscaling based on a custom metric.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
metric:
|
||||||
|
description:
|
||||||
|
- The identifier (type) of the Stackdriver Monitoring metric.
|
||||||
|
- The metric cannot have negative values.
|
||||||
|
- The metric must have a value type of INT64 or DOUBLE.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
utilizationTarget:
|
||||||
|
description:
|
||||||
|
- The target value of the metric that autoscaler should maintain. This
|
||||||
|
must be a positive value. A utilization metric scales number of virtual
|
||||||
|
machines handling requests to increase or decrease proportionally
|
||||||
|
to the metric.
|
||||||
|
- For example, a good metric to use as a utilizationTarget is U(www.googleapis.com/compute/instance/network/received_bytes_count).
|
||||||
|
- The autoscaler will work to keep this value constant for each of the
|
||||||
|
instances.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
utilizationTargetType:
|
||||||
|
description:
|
||||||
|
- Defines how target utilization value is expressed for a Stackdriver
|
||||||
|
Monitoring metric. Either GAUGE, DELTA_PER_SECOND, or DELTA_PER_MINUTE.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
loadBalancingUtilization:
|
||||||
|
description:
|
||||||
|
- Configuration parameters of autoscaling based on a load balancer.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
utilizationTarget:
|
||||||
|
description:
|
||||||
|
- Fraction of backend capacity utilization (set in HTTP(s) load balancing
|
||||||
|
configuration) that autoscaler should maintain. Must be a positive
|
||||||
|
float value. If not defined, the default is 0.8.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
target:
|
||||||
|
description:
|
||||||
|
- URL of the managed instance group that this autoscaler will scale.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- URL of the region where the instance group resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest
|
||||||
|
import json
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/autoscalers".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_list(module, link, query):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
|
|
||||||
|
|
||||||
|
def query_options(filters):
|
||||||
|
if not filters:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if len(filters) == 1:
|
||||||
|
return filters[0]
|
||||||
|
else:
|
||||||
|
queries = []
|
||||||
|
for f in filters:
|
||||||
|
# For multiple queries, all queries should have ()
|
||||||
|
if f[0] != '(' and f[-1] != ')':
|
||||||
|
queries.append("(%s)" % ''.join(f))
|
||||||
|
else:
|
||||||
|
queries.append(f)
|
||||||
|
|
||||||
|
return ' '.join(queries)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
679
plugins/modules/gcp_compute_region_instance_group_manager.py
Normal file
679
plugins/modules/gcp_compute_region_instance_group_manager.py
Normal file
|
@ -0,0 +1,679 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_instance_group_manager
|
||||||
|
description:
|
||||||
|
- Creates a managed instance group using the information that you specify in the request.
|
||||||
|
After the group is created, it schedules an action to create instances in the group
|
||||||
|
using the specified instance template. This operation is marked as DONE when the
|
||||||
|
group is created even if the instances in the group have not yet been created. You
|
||||||
|
must separately verify the status of the individual instances.
|
||||||
|
- A managed instance group can have up to 1000 VM instances per group.
|
||||||
|
short_description: Creates a GCP RegionInstanceGroupManager
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Whether the given object should exist in GCP
|
||||||
|
choices:
|
||||||
|
- present
|
||||||
|
- absent
|
||||||
|
default: present
|
||||||
|
type: str
|
||||||
|
base_instance_name:
|
||||||
|
description:
|
||||||
|
- The base instance name to use for instances in this group. The value must be
|
||||||
|
1-58 characters long. Instances are named by appending a hyphen and a random
|
||||||
|
four-character string to the base instance name.
|
||||||
|
- The base instance name must comply with RFC1035.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource. Provide this property when you create
|
||||||
|
the resource.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
instance_template:
|
||||||
|
description:
|
||||||
|
- The instance template that is specified for this managed instance group. The
|
||||||
|
group uses this template to create all new instances in the managed instance
|
||||||
|
group.
|
||||||
|
- 'This field represents a link to a InstanceTemplate resource in GCP. It can
|
||||||
|
be specified in two ways. First, you can place a dictionary with key ''selfLink''
|
||||||
|
and value of your resource''s selfLink Alternatively, you can add `register:
|
||||||
|
name-of-resource` to a gcp_compute_instance_template task and then set this
|
||||||
|
instance_template field to "{{ name-of-resource }}"'
|
||||||
|
required: true
|
||||||
|
type: dict
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name of the managed instance group. The name must be 1-63 characters long,
|
||||||
|
and comply with RFC1035.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
named_ports:
|
||||||
|
description:
|
||||||
|
- Named ports configured for the Instance Groups complementary to this Instance
|
||||||
|
Group Manager.
|
||||||
|
elements: dict
|
||||||
|
required: false
|
||||||
|
type: list
|
||||||
|
suboptions:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name for this named port. The name must be 1-63 characters long, and
|
||||||
|
comply with RFC1035.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
port:
|
||||||
|
description:
|
||||||
|
- The port number, which can be a value between 1 and 65535.
|
||||||
|
required: false
|
||||||
|
type: int
|
||||||
|
target_pools:
|
||||||
|
description:
|
||||||
|
- TargetPool resources to which instances in the instanceGroup field are added.
|
||||||
|
The target pools automatically apply to all of the instances in the managed
|
||||||
|
instance group.
|
||||||
|
elements: dict
|
||||||
|
required: false
|
||||||
|
type: list
|
||||||
|
target_size:
|
||||||
|
description:
|
||||||
|
- The target number of running instances for this managed instance group. Deleting
|
||||||
|
or abandoning instances reduces this number. Resizing the group changes this
|
||||||
|
number.
|
||||||
|
required: false
|
||||||
|
type: int
|
||||||
|
auto_healing_policies:
|
||||||
|
description:
|
||||||
|
- The autohealing policy for this managed instance group .
|
||||||
|
elements: dict
|
||||||
|
required: false
|
||||||
|
type: list
|
||||||
|
suboptions:
|
||||||
|
health_check:
|
||||||
|
description:
|
||||||
|
- The URL for the health check that signals autohealing.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
initial_delay_sec:
|
||||||
|
description:
|
||||||
|
- The number of seconds that the managed instance group waits before it applies
|
||||||
|
autohealing policies to new instances or recently recreated instances .
|
||||||
|
required: false
|
||||||
|
type: int
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region the managed instance group resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: create a network
|
||||||
|
google.cloud.gcp_compute_network:
|
||||||
|
name: network-instancetemplate
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- name: create a address
|
||||||
|
google.cloud.gcp_compute_address:
|
||||||
|
name: address-instancetemplate
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: address
|
||||||
|
|
||||||
|
- name: create a instance template
|
||||||
|
google.cloud.gcp_compute_instance_template:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
properties:
|
||||||
|
disks:
|
||||||
|
- auto_delete: 'true'
|
||||||
|
boot: 'true'
|
||||||
|
initialize_params:
|
||||||
|
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ network }}"
|
||||||
|
access_configs:
|
||||||
|
- name: test-config
|
||||||
|
type: ONE_TO_ONE_NAT
|
||||||
|
nat_ip: "{{ address }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancetemplate
|
||||||
|
|
||||||
|
- name: create a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: test_object
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
state: present
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
baseInstanceName:
|
||||||
|
description:
|
||||||
|
- The base instance name to use for instances in this group. The value must be 1-58
|
||||||
|
characters long. Instances are named by appending a hyphen and a random four-character
|
||||||
|
string to the base instance name.
|
||||||
|
- The base instance name must comply with RFC1035.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- The creation timestamp for this managed instance group in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
currentActions:
|
||||||
|
description:
|
||||||
|
- The list of instance actions and the number of instances in this managed instance
|
||||||
|
group that are scheduled for each of those actions.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
abandoning:
|
||||||
|
description:
|
||||||
|
- The total number of instances in the managed instance group that are scheduled
|
||||||
|
to be abandoned. Abandoning an instance removes it from the managed instance
|
||||||
|
group without deleting it.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
creating:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled to
|
||||||
|
be created or are currently being created. If the group fails to create any
|
||||||
|
of these instances, it tries again until it creates the instance successfully.
|
||||||
|
- If you have disabled creation retries, this field will not be populated; instead,
|
||||||
|
the creatingWithoutRetries field will be populated.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
creatingWithoutRetries:
|
||||||
|
description:
|
||||||
|
- The number of instances that the managed instance group will attempt to create.
|
||||||
|
The group attempts to create each instance only once. If the group fails to
|
||||||
|
create any of these instances, it decreases the group's targetSize value accordingly.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
deleting:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled to
|
||||||
|
be deleted or are currently being deleted.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
none:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are running and
|
||||||
|
have no scheduled actions.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
recreating:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled to
|
||||||
|
be recreated or are currently being being recreated.
|
||||||
|
- Recreating an instance deletes the existing root persistent disk and creates
|
||||||
|
a new disk from the image that is defined in the instance template.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
refreshing:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are being reconfigured
|
||||||
|
with properties that do not require a restart or a recreate action. For example,
|
||||||
|
setting or removing target pools for the instance.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
restarting:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled to
|
||||||
|
be restarted or are currently being restarted.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource. Provide this property when you create
|
||||||
|
the resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- A unique identifier for this resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
instanceGroup:
|
||||||
|
description:
|
||||||
|
- The instance group being managed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
instanceTemplate:
|
||||||
|
description:
|
||||||
|
- The instance template that is specified for this managed instance group. The group
|
||||||
|
uses this template to create all new instances in the managed instance group.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name of the managed instance group. The name must be 1-63 characters long,
|
||||||
|
and comply with RFC1035.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
namedPorts:
|
||||||
|
description:
|
||||||
|
- Named ports configured for the Instance Groups complementary to this Instance
|
||||||
|
Group Manager.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name for this named port. The name must be 1-63 characters long, and comply
|
||||||
|
with RFC1035.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
port:
|
||||||
|
description:
|
||||||
|
- The port number, which can be a value between 1 and 65535.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
targetPools:
|
||||||
|
description:
|
||||||
|
- TargetPool resources to which instances in the instanceGroup field are added.
|
||||||
|
The target pools automatically apply to all of the instances in the managed instance
|
||||||
|
group.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
targetSize:
|
||||||
|
description:
|
||||||
|
- The target number of running instances for this managed instance group. Deleting
|
||||||
|
or abandoning instances reduces this number. Resizing the group changes this number.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
autoHealingPolicies:
|
||||||
|
description:
|
||||||
|
- The autohealing policy for this managed instance group .
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
healthCheck:
|
||||||
|
description:
|
||||||
|
- The URL for the health check that signals autohealing.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
initialDelaySec:
|
||||||
|
description:
|
||||||
|
- The number of seconds that the managed instance group waits before it applies
|
||||||
|
autohealing policies to new instances or recently recreated instances .
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region the managed instance group resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import (
|
||||||
|
navigate_hash,
|
||||||
|
GcpSession,
|
||||||
|
GcpModule,
|
||||||
|
GcpRequest,
|
||||||
|
remove_nones_from_dict,
|
||||||
|
replace_resource_dict,
|
||||||
|
)
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main function"""
|
||||||
|
|
||||||
|
module = GcpModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
|
base_instance_name=dict(required=True, type='str'),
|
||||||
|
description=dict(type='str'),
|
||||||
|
instance_template=dict(required=True, type='dict'),
|
||||||
|
name=dict(required=True, type='str'),
|
||||||
|
named_ports=dict(type='list', elements='dict', options=dict(name=dict(type='str'), port=dict(type='int'))),
|
||||||
|
target_pools=dict(type='list', elements='dict'),
|
||||||
|
target_size=dict(type='int'),
|
||||||
|
auto_healing_policies=dict(type='list', elements='dict', options=dict(health_check=dict(type='str'), initial_delay_sec=dict(type='int'))),
|
||||||
|
region=dict(required=True, type='str'),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
state = module.params['state']
|
||||||
|
kind = 'compute#instanceGroupManager'
|
||||||
|
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
if fetch:
|
||||||
|
if state == 'present':
|
||||||
|
if is_different(module, fetch):
|
||||||
|
update(module, self_link(module), kind)
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
delete(module, self_link(module), kind)
|
||||||
|
fetch = {}
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
if state == 'present':
|
||||||
|
fetch = create(module, collection(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
fetch = {}
|
||||||
|
|
||||||
|
fetch.update({'changed': changed})
|
||||||
|
|
||||||
|
module.exit_json(**fetch)
|
||||||
|
|
||||||
|
|
||||||
|
def create(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
|
def update(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
|
def delete(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
|
||||||
|
def resource_to_request(module):
|
||||||
|
request = {
|
||||||
|
u'kind': 'compute#instanceGroupManager',
|
||||||
|
u'baseInstanceName': module.params.get('base_instance_name'),
|
||||||
|
u'description': module.params.get('description'),
|
||||||
|
u'instanceTemplate': replace_resource_dict(module.params.get(u'instance_template', {}), 'selfLink'),
|
||||||
|
u'name': module.params.get('name'),
|
||||||
|
u'namedPorts': RegionInstanceGroupManagerNamedportsArray(module.params.get('named_ports', []), module).to_request(),
|
||||||
|
u'targetPools': replace_resource_dict(module.params.get('target_pools', []), 'selfLink'),
|
||||||
|
u'targetSize': module.params.get('target_size'),
|
||||||
|
u'autoHealingPolicies': RegionInstanceGroupManagerAutohealingpoliciesArray(module.params.get('auto_healing_policies', []), module).to_request(),
|
||||||
|
}
|
||||||
|
return_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if v or v is False:
|
||||||
|
return_vals[k] = v
|
||||||
|
|
||||||
|
return return_vals
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_resource(module, link, kind, allow_not_found=True):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return return_if_object(module, auth.get(link), kind, allow_not_found)
|
||||||
|
|
||||||
|
|
||||||
|
def self_link(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/instanceGroupManagers/{name}".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/instanceGroupManagers".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if allow_not_found and response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def is_different(module, response):
|
||||||
|
request = resource_to_request(module)
|
||||||
|
response = response_to_hash(module, response)
|
||||||
|
|
||||||
|
# Remove all output-only from response.
|
||||||
|
response_vals = {}
|
||||||
|
for k, v in response.items():
|
||||||
|
if k in request:
|
||||||
|
response_vals[k] = v
|
||||||
|
|
||||||
|
request_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if k in response:
|
||||||
|
request_vals[k] = v
|
||||||
|
|
||||||
|
return GcpRequest(request_vals) != GcpRequest(response_vals)
|
||||||
|
|
||||||
|
|
||||||
|
# Remove unnecessary properties from the response.
|
||||||
|
# This is for doing comparisons with Ansible's current parameters.
|
||||||
|
def response_to_hash(module, response):
|
||||||
|
return {
|
||||||
|
u'baseInstanceName': response.get(u'baseInstanceName'),
|
||||||
|
u'creationTimestamp': response.get(u'creationTimestamp'),
|
||||||
|
u'currentActions': RegionInstanceGroupManagerCurrentactions(response.get(u'currentActions', {}), module).from_response(),
|
||||||
|
u'description': module.params.get('description'),
|
||||||
|
u'id': response.get(u'id'),
|
||||||
|
u'instanceGroup': response.get(u'instanceGroup'),
|
||||||
|
u'instanceTemplate': response.get(u'instanceTemplate'),
|
||||||
|
u'name': response.get(u'name'),
|
||||||
|
u'namedPorts': RegionInstanceGroupManagerNamedportsArray(response.get(u'namedPorts', []), module).from_response(),
|
||||||
|
u'targetPools': response.get(u'targetPools'),
|
||||||
|
u'targetSize': response.get(u'targetSize'),
|
||||||
|
u'autoHealingPolicies': RegionInstanceGroupManagerAutohealingpoliciesArray(response.get(u'autoHealingPolicies', []), module).from_response(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def async_op_url(module, extra_data=None):
|
||||||
|
if extra_data is None:
|
||||||
|
extra_data = {}
|
||||||
|
url = "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/operations/{op_id}"
|
||||||
|
combined = extra_data.copy()
|
||||||
|
combined.update(module.params)
|
||||||
|
return url.format(**combined)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_operation(module, response):
|
||||||
|
op_result = return_if_object(module, response, 'compute#operation')
|
||||||
|
if op_result is None:
|
||||||
|
return {}
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instanceGroupManager')
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_completion(status, op_result, module):
|
||||||
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
|
while status != 'DONE':
|
||||||
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
|
time.sleep(1.0)
|
||||||
|
op_result = fetch_resource(module, op_uri, 'compute#operation', False)
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
return op_result
|
||||||
|
|
||||||
|
|
||||||
|
def raise_if_errors(response, err_path, module):
|
||||||
|
errors = navigate_hash(response, err_path)
|
||||||
|
if errors is not None:
|
||||||
|
module.fail_json(msg=errors)
|
||||||
|
|
||||||
|
|
||||||
|
class RegionInstanceGroupManagerCurrentactions(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = {}
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
return remove_nones_from_dict({})
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
return remove_nones_from_dict({})
|
||||||
|
|
||||||
|
|
||||||
|
class RegionInstanceGroupManagerNamedportsArray(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = []
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
items = []
|
||||||
|
for item in self.request:
|
||||||
|
items.append(self._request_for_item(item))
|
||||||
|
return items
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
items = []
|
||||||
|
for item in self.request:
|
||||||
|
items.append(self._response_from_item(item))
|
||||||
|
return items
|
||||||
|
|
||||||
|
def _request_for_item(self, item):
|
||||||
|
return remove_nones_from_dict({u'name': item.get('name'), u'port': item.get('port')})
|
||||||
|
|
||||||
|
def _response_from_item(self, item):
|
||||||
|
return remove_nones_from_dict({u'name': item.get(u'name'), u'port': item.get(u'port')})
|
||||||
|
|
||||||
|
|
||||||
|
class RegionInstanceGroupManagerAutohealingpoliciesArray(object):
|
||||||
|
def __init__(self, request, module):
|
||||||
|
self.module = module
|
||||||
|
if request:
|
||||||
|
self.request = request
|
||||||
|
else:
|
||||||
|
self.request = []
|
||||||
|
|
||||||
|
def to_request(self):
|
||||||
|
items = []
|
||||||
|
for item in self.request:
|
||||||
|
items.append(self._request_for_item(item))
|
||||||
|
return items
|
||||||
|
|
||||||
|
def from_response(self):
|
||||||
|
items = []
|
||||||
|
for item in self.request:
|
||||||
|
items.append(self._response_from_item(item))
|
||||||
|
return items
|
||||||
|
|
||||||
|
def _request_for_item(self, item):
|
||||||
|
return remove_nones_from_dict({u'healthCheck': item.get('health_check'), u'initialDelaySec': item.get('initial_delay_sec')})
|
||||||
|
|
||||||
|
def _response_from_item(self, item):
|
||||||
|
return remove_nones_from_dict({u'healthCheck': item.get(u'healthCheck'), u'initialDelaySec': item.get(u'initialDelaySec')})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -0,0 +1,354 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_instance_group_manager_info
|
||||||
|
description:
|
||||||
|
- Gather info for GCP RegionInstanceGroupManager
|
||||||
|
short_description: Gather info for GCP RegionInstanceGroupManager
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
filters:
|
||||||
|
description:
|
||||||
|
- A list of filter value pairs. Available filters are listed here U(https://cloud.google.com/sdk/gcloud/reference/topic/filters).
|
||||||
|
- Each additional filter in the list will act be added as an AND condition (filter1
|
||||||
|
and filter2) .
|
||||||
|
type: list
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region the managed instance group resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: get info on a region instance group manager
|
||||||
|
gcp_compute_region_instance_group_manager_info:
|
||||||
|
region: us-central1
|
||||||
|
filters:
|
||||||
|
- name = test_object
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
resources:
|
||||||
|
description: List of resources
|
||||||
|
returned: always
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
baseInstanceName:
|
||||||
|
description:
|
||||||
|
- The base instance name to use for instances in this group. The value must
|
||||||
|
be 1-58 characters long. Instances are named by appending a hyphen and a random
|
||||||
|
four-character string to the base instance name.
|
||||||
|
- The base instance name must comply with RFC1035.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- The creation timestamp for this managed instance group in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
currentActions:
|
||||||
|
description:
|
||||||
|
- The list of instance actions and the number of instances in this managed instance
|
||||||
|
group that are scheduled for each of those actions.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
abandoning:
|
||||||
|
description:
|
||||||
|
- The total number of instances in the managed instance group that are scheduled
|
||||||
|
to be abandoned. Abandoning an instance removes it from the managed instance
|
||||||
|
group without deleting it.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
creating:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled
|
||||||
|
to be created or are currently being created. If the group fails to create
|
||||||
|
any of these instances, it tries again until it creates the instance successfully.
|
||||||
|
- If you have disabled creation retries, this field will not be populated;
|
||||||
|
instead, the creatingWithoutRetries field will be populated.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
creatingWithoutRetries:
|
||||||
|
description:
|
||||||
|
- The number of instances that the managed instance group will attempt to
|
||||||
|
create. The group attempts to create each instance only once. If the group
|
||||||
|
fails to create any of these instances, it decreases the group's targetSize
|
||||||
|
value accordingly.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
deleting:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled
|
||||||
|
to be deleted or are currently being deleted.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
none:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are running
|
||||||
|
and have no scheduled actions.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
recreating:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled
|
||||||
|
to be recreated or are currently being being recreated.
|
||||||
|
- Recreating an instance deletes the existing root persistent disk and creates
|
||||||
|
a new disk from the image that is defined in the instance template.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
refreshing:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are being reconfigured
|
||||||
|
with properties that do not require a restart or a recreate action. For
|
||||||
|
example, setting or removing target pools for the instance.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
restarting:
|
||||||
|
description:
|
||||||
|
- The number of instances in the managed instance group that are scheduled
|
||||||
|
to be restarted or are currently being restarted.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource. Provide this property when you create
|
||||||
|
the resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- A unique identifier for this resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
instanceGroup:
|
||||||
|
description:
|
||||||
|
- The instance group being managed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
instanceTemplate:
|
||||||
|
description:
|
||||||
|
- The instance template that is specified for this managed instance group. The
|
||||||
|
group uses this template to create all new instances in the managed instance
|
||||||
|
group.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name of the managed instance group. The name must be 1-63 characters long,
|
||||||
|
and comply with RFC1035.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
namedPorts:
|
||||||
|
description:
|
||||||
|
- Named ports configured for the Instance Groups complementary to this Instance
|
||||||
|
Group Manager.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name for this named port. The name must be 1-63 characters long, and
|
||||||
|
comply with RFC1035.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
port:
|
||||||
|
description:
|
||||||
|
- The port number, which can be a value between 1 and 65535.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
targetPools:
|
||||||
|
description:
|
||||||
|
- TargetPool resources to which instances in the instanceGroup field are added.
|
||||||
|
The target pools automatically apply to all of the instances in the managed
|
||||||
|
instance group.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
targetSize:
|
||||||
|
description:
|
||||||
|
- The target number of running instances for this managed instance group. Deleting
|
||||||
|
or abandoning instances reduces this number. Resizing the group changes this
|
||||||
|
number.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
autoHealingPolicies:
|
||||||
|
description:
|
||||||
|
- The autohealing policy for this managed instance group .
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
healthCheck:
|
||||||
|
description:
|
||||||
|
- The URL for the health check that signals autohealing.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
initialDelaySec:
|
||||||
|
description:
|
||||||
|
- The number of seconds that the managed instance group waits before it
|
||||||
|
applies autohealing policies to new instances or recently recreated instances
|
||||||
|
.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region the managed instance group resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest
|
||||||
|
import json
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/instanceGroupManagers".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_list(module, link, query):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
|
|
||||||
|
|
||||||
|
def query_options(filters):
|
||||||
|
if not filters:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if len(filters) == 1:
|
||||||
|
return filters[0]
|
||||||
|
else:
|
||||||
|
queries = []
|
||||||
|
for f in filters:
|
||||||
|
# For multiple queries, all queries should have ()
|
||||||
|
if f[0] != '(' and f[-1] != ')':
|
||||||
|
queries.append("(%s)" % ''.join(f))
|
||||||
|
else:
|
||||||
|
queries.append(f)
|
||||||
|
|
||||||
|
return ' '.join(queries)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
434
plugins/modules/gcp_compute_region_target_http_proxy.py
Normal file
434
plugins/modules/gcp_compute_region_target_http_proxy.py
Normal file
|
@ -0,0 +1,434 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_target_http_proxy
|
||||||
|
description:
|
||||||
|
- Represents a RegionTargetHttpProxy resource, which is used by one or more forwarding
|
||||||
|
rules to route incoming HTTP requests to a URL map.
|
||||||
|
short_description: Creates a GCP RegionTargetHttpProxy
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Whether the given object should exist in GCP
|
||||||
|
choices:
|
||||||
|
- present
|
||||||
|
- absent
|
||||||
|
default: present
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. Provided by the client when the resource is created. The
|
||||||
|
name must be 1-63 characters long, and comply with RFC1035. Specifically, the
|
||||||
|
name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
|
which means the first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last character,
|
||||||
|
which cannot be a dash.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
url_map:
|
||||||
|
description:
|
||||||
|
- A reference to the RegionUrlMap resource that defines the mapping from URL to
|
||||||
|
the BackendService.
|
||||||
|
- 'This field represents a link to a RegionUrlMap resource in GCP. It can be specified
|
||||||
|
in two ways. First, you can place a dictionary with key ''selfLink'' and value
|
||||||
|
of your resource''s selfLink Alternatively, you can add `register: name-of-resource`
|
||||||
|
to a gcp_compute_region_url_map task and then set this url_map field to "{{
|
||||||
|
name-of-resource }}"'
|
||||||
|
required: true
|
||||||
|
type: dict
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- 'API Reference: U(https://cloud.google.com/compute/docs/reference/rest/beta/regionTargetHttpProxies)'
|
||||||
|
- 'Official Documentation: U(https://cloud.google.com/compute/docs/load-balancing/http/target-proxies)'
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: create a instance group
|
||||||
|
google.cloud.gcp_compute_instance_group:
|
||||||
|
name: instancegroup-targethttpproxy
|
||||||
|
zone: us-central1-a
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancegroup
|
||||||
|
|
||||||
|
- name: create a HTTP health check
|
||||||
|
google.cloud.gcp_compute_http_health_check:
|
||||||
|
name: httphealthcheck-targethttpproxy
|
||||||
|
healthy_threshold: 10
|
||||||
|
port: 8080
|
||||||
|
timeout_sec: 2
|
||||||
|
unhealthy_threshold: 5
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: healthcheck
|
||||||
|
|
||||||
|
- name: create a backend service
|
||||||
|
google.cloud.gcp_compute_backend_service:
|
||||||
|
name: backendservice-targethttpproxy
|
||||||
|
backends:
|
||||||
|
- group: "{{ instancegroup.selfLink }}"
|
||||||
|
health_checks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
enable_cdn: 'true'
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: backendservice
|
||||||
|
|
||||||
|
- name: create a URL map
|
||||||
|
google.cloud.gcp_compute_url_map:
|
||||||
|
name: urlmap-targethttpproxy
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: urlmap
|
||||||
|
|
||||||
|
- name: create a region target HTTP proxy
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy:
|
||||||
|
name: test_object
|
||||||
|
region: us-central1
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
state: present
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- Creation timestamp in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- The unique identifier for the resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. Provided by the client when the resource is created. The
|
||||||
|
name must be 1-63 characters long, and comply with RFC1035. Specifically, the
|
||||||
|
name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
|
which means the first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last character,
|
||||||
|
which cannot be a dash.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
urlMap:
|
||||||
|
description:
|
||||||
|
- A reference to the RegionUrlMap resource that defines the mapping from URL to
|
||||||
|
the BackendService.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main function"""
|
||||||
|
|
||||||
|
module = GcpModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
|
description=dict(type='str'),
|
||||||
|
name=dict(required=True, type='str'),
|
||||||
|
url_map=dict(required=True, type='dict'),
|
||||||
|
region=dict(required=True, type='str'),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
state = module.params['state']
|
||||||
|
kind = 'compute#targetHttpProxy'
|
||||||
|
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
if fetch:
|
||||||
|
if state == 'present':
|
||||||
|
if is_different(module, fetch):
|
||||||
|
update(module, self_link(module), kind, fetch)
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
delete(module, self_link(module), kind)
|
||||||
|
fetch = {}
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
if state == 'present':
|
||||||
|
fetch = create(module, collection(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
fetch = {}
|
||||||
|
|
||||||
|
fetch.update({'changed': changed})
|
||||||
|
|
||||||
|
module.exit_json(**fetch)
|
||||||
|
|
||||||
|
|
||||||
|
def create(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
|
def update(module, link, kind, fetch):
|
||||||
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
def update_fields(module, request, response):
|
||||||
|
if response.get('urlMap') != request.get('urlMap'):
|
||||||
|
url_map_update(module, request, response)
|
||||||
|
|
||||||
|
|
||||||
|
def url_map_update(module, request, response):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
auth.post(
|
||||||
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/targetHttpProxies/{name}/setUrlMap"]).format(**module.params),
|
||||||
|
{u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def delete(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
|
||||||
|
def resource_to_request(module):
|
||||||
|
request = {
|
||||||
|
u'kind': 'compute#targetHttpProxy',
|
||||||
|
u'region': module.params.get('region'),
|
||||||
|
u'description': module.params.get('description'),
|
||||||
|
u'name': module.params.get('name'),
|
||||||
|
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink'),
|
||||||
|
}
|
||||||
|
return_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if v or v is False:
|
||||||
|
return_vals[k] = v
|
||||||
|
|
||||||
|
return return_vals
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_resource(module, link, kind, allow_not_found=True):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return return_if_object(module, auth.get(link), kind, allow_not_found)
|
||||||
|
|
||||||
|
|
||||||
|
def self_link(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetHttpProxies/{name}".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetHttpProxies".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if allow_not_found and response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def is_different(module, response):
|
||||||
|
request = resource_to_request(module)
|
||||||
|
response = response_to_hash(module, response)
|
||||||
|
|
||||||
|
# Remove all output-only from response.
|
||||||
|
response_vals = {}
|
||||||
|
for k, v in response.items():
|
||||||
|
if k in request:
|
||||||
|
response_vals[k] = v
|
||||||
|
|
||||||
|
request_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if k in response:
|
||||||
|
request_vals[k] = v
|
||||||
|
|
||||||
|
return GcpRequest(request_vals) != GcpRequest(response_vals)
|
||||||
|
|
||||||
|
|
||||||
|
# Remove unnecessary properties from the response.
|
||||||
|
# This is for doing comparisons with Ansible's current parameters.
|
||||||
|
def response_to_hash(module, response):
|
||||||
|
return {
|
||||||
|
u'creationTimestamp': response.get(u'creationTimestamp'),
|
||||||
|
u'description': response.get(u'description'),
|
||||||
|
u'id': response.get(u'id'),
|
||||||
|
u'name': response.get(u'name'),
|
||||||
|
u'urlMap': response.get(u'urlMap'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def async_op_url(module, extra_data=None):
|
||||||
|
if extra_data is None:
|
||||||
|
extra_data = {}
|
||||||
|
url = "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/operations/{op_id}"
|
||||||
|
combined = extra_data.copy()
|
||||||
|
combined.update(module.params)
|
||||||
|
return url.format(**combined)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_operation(module, response):
|
||||||
|
op_result = return_if_object(module, response, 'compute#operation')
|
||||||
|
if op_result is None:
|
||||||
|
return {}
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetHttpProxy')
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_completion(status, op_result, module):
|
||||||
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
|
while status != 'DONE':
|
||||||
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
|
time.sleep(1.0)
|
||||||
|
op_result = fetch_resource(module, op_uri, 'compute#operation', False)
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
return op_result
|
||||||
|
|
||||||
|
|
||||||
|
def raise_if_errors(response, err_path, module):
|
||||||
|
errors = navigate_hash(response, err_path)
|
||||||
|
if errors is not None:
|
||||||
|
module.fail_json(msg=errors)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
229
plugins/modules/gcp_compute_region_target_http_proxy_info.py
Normal file
229
plugins/modules/gcp_compute_region_target_http_proxy_info.py
Normal file
|
@ -0,0 +1,229 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_target_http_proxy_info
|
||||||
|
description:
|
||||||
|
- Gather info for GCP RegionTargetHttpProxy
|
||||||
|
short_description: Gather info for GCP RegionTargetHttpProxy
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
filters:
|
||||||
|
description:
|
||||||
|
- A list of filter value pairs. Available filters are listed here U(https://cloud.google.com/sdk/gcloud/reference/topic/filters).
|
||||||
|
- Each additional filter in the list will act be added as an AND condition (filter1
|
||||||
|
and filter2) .
|
||||||
|
type: list
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: get info on a region target HTTP proxy
|
||||||
|
gcp_compute_region_target_http_proxy_info:
|
||||||
|
region: us-central1
|
||||||
|
filters:
|
||||||
|
- name = test_object
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
resources:
|
||||||
|
description: List of resources
|
||||||
|
returned: always
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- Creation timestamp in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- The unique identifier for the resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. Provided by the client when the resource is created.
|
||||||
|
The name must be 1-63 characters long, and comply with RFC1035. Specifically,
|
||||||
|
the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
|
which means the first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last character,
|
||||||
|
which cannot be a dash.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
urlMap:
|
||||||
|
description:
|
||||||
|
- A reference to the RegionUrlMap resource that defines the mapping from URL
|
||||||
|
to the BackendService.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest
|
||||||
|
import json
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetHttpProxies".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_list(module, link, query):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
|
|
||||||
|
|
||||||
|
def query_options(filters):
|
||||||
|
if not filters:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if len(filters) == 1:
|
||||||
|
return filters[0]
|
||||||
|
else:
|
||||||
|
queries = []
|
||||||
|
for f in filters:
|
||||||
|
# For multiple queries, all queries should have ()
|
||||||
|
if f[0] != '(' and f[-1] != ')':
|
||||||
|
queries.append("(%s)" % ''.join(f))
|
||||||
|
else:
|
||||||
|
queries.append(f)
|
||||||
|
|
||||||
|
return ' '.join(queries)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
502
plugins/modules/gcp_compute_region_target_https_proxy.py
Normal file
502
plugins/modules/gcp_compute_region_target_https_proxy.py
Normal file
|
@ -0,0 +1,502 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_target_https_proxy
|
||||||
|
description:
|
||||||
|
- Represents a RegionTargetHttpsProxy resource, which is used by one or more forwarding
|
||||||
|
rules to route incoming HTTPS requests to a URL map.
|
||||||
|
short_description: Creates a GCP RegionTargetHttpsProxy
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Whether the given object should exist in GCP
|
||||||
|
choices:
|
||||||
|
- present
|
||||||
|
- absent
|
||||||
|
default: present
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
required: false
|
||||||
|
type: str
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. Provided by the client when the resource is created. The
|
||||||
|
name must be 1-63 characters long, and comply with RFC1035. Specifically, the
|
||||||
|
name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
|
which means the first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last character,
|
||||||
|
which cannot be a dash.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
ssl_certificates:
|
||||||
|
description:
|
||||||
|
- A list of RegionSslCertificate resources that are used to authenticate connections
|
||||||
|
between users and the load balancer. Currently, exactly one SSL certificate
|
||||||
|
must be specified.
|
||||||
|
elements: dict
|
||||||
|
required: true
|
||||||
|
type: list
|
||||||
|
url_map:
|
||||||
|
description:
|
||||||
|
- A reference to the RegionUrlMap resource that defines the mapping from URL to
|
||||||
|
the RegionBackendService.
|
||||||
|
- 'This field represents a link to a RegionUrlMap resource in GCP. It can be specified
|
||||||
|
in two ways. First, you can place a dictionary with key ''selfLink'' and value
|
||||||
|
of your resource''s selfLink Alternatively, you can add `register: name-of-resource`
|
||||||
|
to a gcp_compute_region_url_map task and then set this url_map field to "{{
|
||||||
|
name-of-resource }}"'
|
||||||
|
required: true
|
||||||
|
type: dict
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- 'API Reference: U(https://cloud.google.com/compute/docs/reference/rest/beta/regionTargetHttpsProxies)'
|
||||||
|
- 'Official Documentation: U(https://cloud.google.com/compute/docs/load-balancing/http/target-proxies)'
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: create a instance group
|
||||||
|
google.cloud.gcp_compute_instance_group:
|
||||||
|
name: instancegroup-targethttpsproxy
|
||||||
|
zone: us-central1-a
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancegroup
|
||||||
|
|
||||||
|
- name: create a region health check
|
||||||
|
google.cloud.gcp_compute_region_health_check:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
type: HTTPS
|
||||||
|
healthy_threshold: 10
|
||||||
|
timeout_sec: 2
|
||||||
|
unhealthy_threshold: 5
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: healthcheck
|
||||||
|
|
||||||
|
- name: create a region backend service
|
||||||
|
google.cloud.gcp_compute_region_backend_service:
|
||||||
|
name: backendservice-targethttpsproxy
|
||||||
|
region: us-central1
|
||||||
|
backends:
|
||||||
|
- group: "{{ instancegroup.selfLink }}"
|
||||||
|
healthchecks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: backendservice
|
||||||
|
|
||||||
|
- name: create a region URL map
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: urlmap-targethttpsproxy
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: urlmap
|
||||||
|
|
||||||
|
- name: create a SSL certificate
|
||||||
|
google.cloud.gcp_compute_ssl_certificate:
|
||||||
|
name: sslcert-targethttpsproxy
|
||||||
|
description: A certificate for testing. Do not use this certificate in production
|
||||||
|
certificate: |-
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
|
||||||
|
EwJVUzETMBEGA1UECAwKV2FzaGluZ3RvbjERMA8GA1UEBwwIS2lya2xhbmQxFTAT
|
||||||
|
BgNVBAoMDEdvb2dsZSwgSW5jLjEeMBwGA1UECwwVR29vZ2xlIENsb3VkIFBsYXRm
|
||||||
|
b3JtMR8wHQYDVQQDDBZ3d3cubXktc2VjdXJlLXNpdGUuY29tMSEwHwYJKoZIhvcN
|
||||||
|
AQkBFhJuZWxzb25hQGdvb2dsZS5jb20wHhcNMTcwNjI4MDQ1NjI2WhcNMjcwNjI2
|
||||||
|
MDQ1NjI2WjCBsDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xETAP
|
||||||
|
BgNVBAcMCEtpcmtsYW5kMRUwEwYDVQQKDAxHb29nbGUsIEluYy4xHjAcBgNVBAsM
|
||||||
|
FUdvb2dsZSBDbG91ZCBQbGF0Zm9ybTEfMB0GA1UEAwwWd3d3Lm15LXNlY3VyZS1z
|
||||||
|
aXRlLmNvbTEhMB8GCSqGSIb3DQEJARYSbmVsc29uYUBnb29nbGUuY29tMFkwEwYH
|
||||||
|
KoZIzj0CAQYIKoZIzj0DAQcDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ
|
||||||
|
4mzkzTv0dXyB750fOGN02HtkpBOZzzvUARTR10JQoSe2/5PIwaNQME4wHQYDVR0O
|
||||||
|
BBYEFKIQC3A2SDpxcdfn0YLKineDNq/BMB8GA1UdIwQYMBaAFKIQC3A2SDpxcdfn
|
||||||
|
0YLKineDNq/BMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0EAwIDSQAwRgIhALs4vy+O
|
||||||
|
M3jcqgA4fSW/oKw6UJxp+M6a+nGMX+UJR3YgAiEAvvl39QRVAiv84hdoCuyON0lJ
|
||||||
|
zqGNhIPGq2ULqXKK8BY=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
private_key: |-
|
||||||
|
-----BEGIN EC PRIVATE KEY-----
|
||||||
|
MHcCAQEEIObtRo8tkUqoMjeHhsOh2ouPpXCgBcP+EDxZCB/tws15oAoGCCqGSM49
|
||||||
|
AwEHoUQDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ4mzkzTv0dXyB750f
|
||||||
|
OGN02HtkpBOZzzvUARTR10JQoSe2/5PIwQ==
|
||||||
|
-----END EC PRIVATE KEY-----
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: sslcert
|
||||||
|
|
||||||
|
- name: create a region target HTTPS proxy
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy:
|
||||||
|
name: test_object
|
||||||
|
region: us-central1
|
||||||
|
ssl_certificates:
|
||||||
|
- "{{ sslcert }}"
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
state: present
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- Creation timestamp in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- The unique identifier for the resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. Provided by the client when the resource is created. The
|
||||||
|
name must be 1-63 characters long, and comply with RFC1035. Specifically, the
|
||||||
|
name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
|
which means the first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last character,
|
||||||
|
which cannot be a dash.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sslCertificates:
|
||||||
|
description:
|
||||||
|
- A list of RegionSslCertificate resources that are used to authenticate connections
|
||||||
|
between users and the load balancer. Currently, exactly one SSL certificate must
|
||||||
|
be specified.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
urlMap:
|
||||||
|
description:
|
||||||
|
- A reference to the RegionUrlMap resource that defines the mapping from URL to
|
||||||
|
the RegionBackendService.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
from ansible_collections.google.cloud.plugins.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main function"""
|
||||||
|
|
||||||
|
module = GcpModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
|
description=dict(type='str'),
|
||||||
|
name=dict(required=True, type='str'),
|
||||||
|
ssl_certificates=dict(required=True, type='list', elements='dict'),
|
||||||
|
url_map=dict(required=True, type='dict'),
|
||||||
|
region=dict(required=True, type='str'),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
state = module.params['state']
|
||||||
|
kind = 'compute#targetHttpsProxy'
|
||||||
|
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
if fetch:
|
||||||
|
if state == 'present':
|
||||||
|
if is_different(module, fetch):
|
||||||
|
update(module, self_link(module), kind, fetch)
|
||||||
|
fetch = fetch_resource(module, self_link(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
delete(module, self_link(module), kind)
|
||||||
|
fetch = {}
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
if state == 'present':
|
||||||
|
fetch = create(module, collection(module), kind)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
fetch = {}
|
||||||
|
|
||||||
|
fetch.update({'changed': changed})
|
||||||
|
|
||||||
|
module.exit_json(**fetch)
|
||||||
|
|
||||||
|
|
||||||
|
def create(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
|
def update(module, link, kind, fetch):
|
||||||
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
def update_fields(module, request, response):
|
||||||
|
if response.get('sslCertificates') != request.get('sslCertificates'):
|
||||||
|
ssl_certificates_update(module, request, response)
|
||||||
|
if response.get('urlMap') != request.get('urlMap'):
|
||||||
|
url_map_update(module, request, response)
|
||||||
|
|
||||||
|
|
||||||
|
def ssl_certificates_update(module, request, response):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
auth.post(
|
||||||
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/targetHttpsProxies/{name}/setSslCertificates"]).format(
|
||||||
|
**module.params
|
||||||
|
),
|
||||||
|
{u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink')},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def url_map_update(module, request, response):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
auth.post(
|
||||||
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/targetHttpsProxies/{name}/setUrlMap"]).format(**module.params),
|
||||||
|
{u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def delete(module, link, kind):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
|
||||||
|
def resource_to_request(module):
|
||||||
|
request = {
|
||||||
|
u'kind': 'compute#targetHttpsProxy',
|
||||||
|
u'region': module.params.get('region'),
|
||||||
|
u'description': module.params.get('description'),
|
||||||
|
u'name': module.params.get('name'),
|
||||||
|
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink'),
|
||||||
|
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink'),
|
||||||
|
}
|
||||||
|
return_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if v or v is False:
|
||||||
|
return_vals[k] = v
|
||||||
|
|
||||||
|
return return_vals
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_resource(module, link, kind, allow_not_found=True):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return return_if_object(module, auth.get(link), kind, allow_not_found)
|
||||||
|
|
||||||
|
|
||||||
|
def self_link(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetHttpsProxies/{name}".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetHttpsProxies".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if allow_not_found and response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def is_different(module, response):
|
||||||
|
request = resource_to_request(module)
|
||||||
|
response = response_to_hash(module, response)
|
||||||
|
|
||||||
|
# Remove all output-only from response.
|
||||||
|
response_vals = {}
|
||||||
|
for k, v in response.items():
|
||||||
|
if k in request:
|
||||||
|
response_vals[k] = v
|
||||||
|
|
||||||
|
request_vals = {}
|
||||||
|
for k, v in request.items():
|
||||||
|
if k in response:
|
||||||
|
request_vals[k] = v
|
||||||
|
|
||||||
|
return GcpRequest(request_vals) != GcpRequest(response_vals)
|
||||||
|
|
||||||
|
|
||||||
|
# Remove unnecessary properties from the response.
|
||||||
|
# This is for doing comparisons with Ansible's current parameters.
|
||||||
|
def response_to_hash(module, response):
|
||||||
|
return {
|
||||||
|
u'creationTimestamp': response.get(u'creationTimestamp'),
|
||||||
|
u'description': module.params.get('description'),
|
||||||
|
u'id': response.get(u'id'),
|
||||||
|
u'name': module.params.get('name'),
|
||||||
|
u'sslCertificates': response.get(u'sslCertificates'),
|
||||||
|
u'urlMap': response.get(u'urlMap'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def async_op_url(module, extra_data=None):
|
||||||
|
if extra_data is None:
|
||||||
|
extra_data = {}
|
||||||
|
url = "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/operations/{op_id}"
|
||||||
|
combined = extra_data.copy()
|
||||||
|
combined.update(module.params)
|
||||||
|
return url.format(**combined)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_operation(module, response):
|
||||||
|
op_result = return_if_object(module, response, 'compute#operation')
|
||||||
|
if op_result is None:
|
||||||
|
return {}
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetHttpsProxy')
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_completion(status, op_result, module):
|
||||||
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
|
while status != 'DONE':
|
||||||
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
|
time.sleep(1.0)
|
||||||
|
op_result = fetch_resource(module, op_uri, 'compute#operation', False)
|
||||||
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
return op_result
|
||||||
|
|
||||||
|
|
||||||
|
def raise_if_errors(response, err_path, module):
|
||||||
|
errors = navigate_hash(response, err_path)
|
||||||
|
if errors is not None:
|
||||||
|
module.fail_json(msg=errors)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
236
plugins/modules/gcp_compute_region_target_https_proxy_info.py
Normal file
236
plugins/modules/gcp_compute_region_target_https_proxy_info.py
Normal file
|
@ -0,0 +1,236 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Google
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Documentation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: gcp_compute_region_target_https_proxy_info
|
||||||
|
description:
|
||||||
|
- Gather info for GCP RegionTargetHttpsProxy
|
||||||
|
short_description: Gather info for GCP RegionTargetHttpsProxy
|
||||||
|
version_added: '2.10'
|
||||||
|
author: Google Inc. (@googlecloudplatform)
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- requests >= 2.18.4
|
||||||
|
- google-auth >= 1.3.0
|
||||||
|
options:
|
||||||
|
filters:
|
||||||
|
description:
|
||||||
|
- A list of filter value pairs. Available filters are listed here U(https://cloud.google.com/sdk/gcloud/reference/topic/filters).
|
||||||
|
- Each additional filter in the list will act be added as an AND condition (filter1
|
||||||
|
and filter2) .
|
||||||
|
type: list
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- The Google Cloud Platform project to use.
|
||||||
|
type: str
|
||||||
|
auth_kind:
|
||||||
|
description:
|
||||||
|
- The type of credential used.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
choices:
|
||||||
|
- application
|
||||||
|
- machineaccount
|
||||||
|
- serviceaccount
|
||||||
|
service_account_contents:
|
||||||
|
description:
|
||||||
|
- The contents of a Service Account JSON file, either in a dictionary or as a
|
||||||
|
JSON string that represents it.
|
||||||
|
type: jsonarg
|
||||||
|
service_account_file:
|
||||||
|
description:
|
||||||
|
- The path of a Service Account JSON file if serviceaccount is selected as type.
|
||||||
|
type: path
|
||||||
|
service_account_email:
|
||||||
|
description:
|
||||||
|
- An optional service account email address if machineaccount is selected and
|
||||||
|
the user does not wish to use the default email.
|
||||||
|
type: str
|
||||||
|
scopes:
|
||||||
|
description:
|
||||||
|
- Array of scopes to be used
|
||||||
|
type: list
|
||||||
|
env_type:
|
||||||
|
description:
|
||||||
|
- Specifies which Ansible environment you're running this module within.
|
||||||
|
- This should not be set unless you know what you're doing.
|
||||||
|
- This only alters the User Agent string for any API requests.
|
||||||
|
type: str
|
||||||
|
notes:
|
||||||
|
- for authentication, you can set service_account_file using the C(gcp_service_account_file)
|
||||||
|
env variable.
|
||||||
|
- for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL)
|
||||||
|
env variable.
|
||||||
|
- For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.
|
||||||
|
- For authentication, you can set scopes using the C(GCP_SCOPES) env variable.
|
||||||
|
- Environment variables values will only be used if the playbook values are not set.
|
||||||
|
- The I(service_account_email) and I(service_account_file) options are mutually exclusive.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = '''
|
||||||
|
- name: get info on a region target HTTPS proxy
|
||||||
|
gcp_compute_region_target_https_proxy_info:
|
||||||
|
region: us-central1
|
||||||
|
filters:
|
||||||
|
- name = test_object
|
||||||
|
project: test_project
|
||||||
|
auth_kind: serviceaccount
|
||||||
|
service_account_file: "/tmp/auth.pem"
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
resources:
|
||||||
|
description: List of resources
|
||||||
|
returned: always
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
creationTimestamp:
|
||||||
|
description:
|
||||||
|
- Creation timestamp in RFC3339 text format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- An optional description of this resource.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- The unique identifier for the resource.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the resource. Provided by the client when the resource is created.
|
||||||
|
The name must be 1-63 characters long, and comply with RFC1035. Specifically,
|
||||||
|
the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
|
||||||
|
which means the first character must be a lowercase letter, and all following
|
||||||
|
characters must be a dash, lowercase letter, or digit, except the last character,
|
||||||
|
which cannot be a dash.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sslCertificates:
|
||||||
|
description:
|
||||||
|
- A list of RegionSslCertificate resources that are used to authenticate connections
|
||||||
|
between users and the load balancer. Currently, exactly one SSL certificate
|
||||||
|
must be specified.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
urlMap:
|
||||||
|
description:
|
||||||
|
- A reference to the RegionUrlMap resource that defines the mapping from URL
|
||||||
|
to the RegionBackendService.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
region:
|
||||||
|
description:
|
||||||
|
- The region where the regional proxy resides.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
'''
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Imports
|
||||||
|
################################################################################
|
||||||
|
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest
|
||||||
|
import json
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Main
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(module):
|
||||||
|
return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetHttpsProxies".format(**module.params)
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_list(module, link, query):
|
||||||
|
auth = GcpSession(module, 'compute')
|
||||||
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
|
|
||||||
|
|
||||||
|
def query_options(filters):
|
||||||
|
if not filters:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if len(filters) == 1:
|
||||||
|
return filters[0]
|
||||||
|
else:
|
||||||
|
queries = []
|
||||||
|
for f in filters:
|
||||||
|
# For multiple queries, all queries should have ()
|
||||||
|
if f[0] != '(' and f[-1] != ')':
|
||||||
|
queries.append("(%s)" % ''.join(f))
|
||||||
|
else:
|
||||||
|
queries.append(f)
|
||||||
|
|
||||||
|
return ' '.join(queries)
|
||||||
|
|
||||||
|
|
||||||
|
def return_if_object(module, response):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
module.raise_for_status(response)
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
||||||
|
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
4598
plugins/modules/gcp_compute_region_url_map.py
Normal file
4598
plugins/modules/gcp_compute_region_url_map.py
Normal file
File diff suppressed because it is too large
Load diff
1512
plugins/modules/gcp_compute_region_url_map_info.py
Normal file
1512
plugins/modules/gcp_compute_region_url_map_info.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,2 @@
|
||||||
|
cloud/gcp
|
||||||
|
unsupported
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
resource_name: "{{ resource_prefix }}"
|
|
@ -0,0 +1,251 @@
|
||||||
|
---
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Pre-test setup
|
||||||
|
- name: create a network
|
||||||
|
google.cloud.gcp_compute_network:
|
||||||
|
name: network-instancetemplate
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: network
|
||||||
|
- name: create a address
|
||||||
|
google.cloud.gcp_compute_address:
|
||||||
|
name: address-instancetemplate
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: address
|
||||||
|
- name: create a instance template
|
||||||
|
google.cloud.gcp_compute_instance_template:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
properties:
|
||||||
|
disks:
|
||||||
|
- auto_delete: 'true'
|
||||||
|
boot: 'true'
|
||||||
|
initialize_params:
|
||||||
|
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ network }}"
|
||||||
|
access_configs:
|
||||||
|
- name: test-config
|
||||||
|
type: ONE_TO_ONE_NAT
|
||||||
|
nat_ip: "{{ address }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancetemplate
|
||||||
|
- name: create a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: igrm
|
||||||
|
- name: delete a region autoscaler
|
||||||
|
google.cloud.gcp_compute_region_autoscaler:
|
||||||
|
name: my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
autoscaling_policy:
|
||||||
|
min_num_replicas: 1
|
||||||
|
max_num_replicas: 5
|
||||||
|
cool_down_period_sec: 60
|
||||||
|
cpu_utilization:
|
||||||
|
utilization_target: 0.5
|
||||||
|
target: "{{igrm.selfLink}}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: create a region autoscaler
|
||||||
|
google.cloud.gcp_compute_region_autoscaler:
|
||||||
|
name: my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
autoscaling_policy:
|
||||||
|
min_num_replicas: 1
|
||||||
|
max_num_replicas: 5
|
||||||
|
cool_down_period_sec: 60
|
||||||
|
cpu_utilization:
|
||||||
|
utilization_target: 0.5
|
||||||
|
target: "{{igrm.selfLink}}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_autoscaler was created
|
||||||
|
google.cloud.gcp_compute_region_autoscaler_info:
|
||||||
|
filters:
|
||||||
|
- name = my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 1
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: create a region autoscaler that already exists
|
||||||
|
google.cloud.gcp_compute_region_autoscaler:
|
||||||
|
name: my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
autoscaling_policy:
|
||||||
|
min_num_replicas: 1
|
||||||
|
max_num_replicas: 5
|
||||||
|
cool_down_period_sec: 60
|
||||||
|
cpu_utilization:
|
||||||
|
utilization_target: 0.5
|
||||||
|
target: "{{igrm.selfLink}}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: delete a region autoscaler
|
||||||
|
google.cloud.gcp_compute_region_autoscaler:
|
||||||
|
name: my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
autoscaling_policy:
|
||||||
|
min_num_replicas: 1
|
||||||
|
max_num_replicas: 5
|
||||||
|
cool_down_period_sec: 60
|
||||||
|
cpu_utilization:
|
||||||
|
utilization_target: 0.5
|
||||||
|
target: "{{igrm.selfLink}}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_autoscaler was deleted
|
||||||
|
google.cloud.gcp_compute_region_autoscaler_info:
|
||||||
|
filters:
|
||||||
|
- name = my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 0
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: delete a region autoscaler that does not exist
|
||||||
|
google.cloud.gcp_compute_region_autoscaler:
|
||||||
|
name: my-region-autoscaler
|
||||||
|
region: us-central1
|
||||||
|
autoscaling_policy:
|
||||||
|
min_num_replicas: 1
|
||||||
|
max_num_replicas: 5
|
||||||
|
cool_down_period_sec: 60
|
||||||
|
cpu_utilization:
|
||||||
|
utilization_target: 0.5
|
||||||
|
target: "{{igrm.selfLink}}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#---------------------------------------------------------
|
||||||
|
# Post-test teardown
|
||||||
|
# If errors happen, don't crash the playbook!
|
||||||
|
- name: delete a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: igrm
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a instance template
|
||||||
|
google.cloud.gcp_compute_instance_template:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
properties:
|
||||||
|
disks:
|
||||||
|
- auto_delete: 'true'
|
||||||
|
boot: 'true'
|
||||||
|
initialize_params:
|
||||||
|
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ network }}"
|
||||||
|
access_configs:
|
||||||
|
- name: test-config
|
||||||
|
type: ONE_TO_ONE_NAT
|
||||||
|
nat_ip: "{{ address }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: instancetemplate
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a address
|
||||||
|
google.cloud.gcp_compute_address:
|
||||||
|
name: address-instancetemplate
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: address
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a network
|
||||||
|
google.cloud.gcp_compute_network:
|
||||||
|
name: network-instancetemplate
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: network
|
||||||
|
ignore_errors: true
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- include_tasks: autogen.yml
|
|
@ -0,0 +1,2 @@
|
||||||
|
cloud/gcp
|
||||||
|
unsupported
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
resource_name: "{{ resource_prefix }}"
|
|
@ -0,0 +1,206 @@
|
||||||
|
---
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Pre-test setup
|
||||||
|
- name: create a network
|
||||||
|
google.cloud.gcp_compute_network:
|
||||||
|
name: network-instancetemplate
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: network
|
||||||
|
- name: create a address
|
||||||
|
google.cloud.gcp_compute_address:
|
||||||
|
name: address-instancetemplate
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: address
|
||||||
|
- name: create a instance template
|
||||||
|
google.cloud.gcp_compute_instance_template:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
properties:
|
||||||
|
disks:
|
||||||
|
- auto_delete: 'true'
|
||||||
|
boot: 'true'
|
||||||
|
initialize_params:
|
||||||
|
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ network }}"
|
||||||
|
access_configs:
|
||||||
|
- name: test-config
|
||||||
|
type: ONE_TO_ONE_NAT
|
||||||
|
nat_ip: "{{ address }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancetemplate
|
||||||
|
- name: delete a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: create a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_instance_group_manager was created
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 1
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: create a region instance group manager that already exists
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: delete a region instance group manager
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_instance_group_manager was deleted
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 0
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: delete a region instance group manager that does not exist
|
||||||
|
google.cloud.gcp_compute_region_instance_group_manager:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
base_instance_name: test1-child
|
||||||
|
region: us-central1
|
||||||
|
instance_template: "{{ instancetemplate }}"
|
||||||
|
target_size: 3
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#---------------------------------------------------------
|
||||||
|
# Post-test teardown
|
||||||
|
# If errors happen, don't crash the playbook!
|
||||||
|
- name: delete a instance template
|
||||||
|
google.cloud.gcp_compute_instance_template:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
properties:
|
||||||
|
disks:
|
||||||
|
- auto_delete: 'true'
|
||||||
|
boot: 'true'
|
||||||
|
initialize_params:
|
||||||
|
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ network }}"
|
||||||
|
access_configs:
|
||||||
|
- name: test-config
|
||||||
|
type: ONE_TO_ONE_NAT
|
||||||
|
nat_ip: "{{ address }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: instancetemplate
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a address
|
||||||
|
google.cloud.gcp_compute_address:
|
||||||
|
name: address-instancetemplate
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: address
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a network
|
||||||
|
google.cloud.gcp_compute_network:
|
||||||
|
name: network-instancetemplate
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: network
|
||||||
|
ignore_errors: true
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- include_tasks: autogen.yml
|
|
@ -0,0 +1,2 @@
|
||||||
|
cloud/gcp
|
||||||
|
unsupported
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
resource_name: "{{ resource_prefix }}"
|
|
@ -0,0 +1,207 @@
|
||||||
|
---
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Pre-test setup
|
||||||
|
- name: create a instance group
|
||||||
|
google.cloud.gcp_compute_instance_group:
|
||||||
|
name: instancegroup-targethttpproxy
|
||||||
|
zone: us-central1-a
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancegroup
|
||||||
|
- name: create a HTTP health check
|
||||||
|
google.cloud.gcp_compute_http_health_check:
|
||||||
|
name: httphealthcheck-targethttpproxy
|
||||||
|
healthy_threshold: 10
|
||||||
|
port: 8080
|
||||||
|
timeout_sec: 2
|
||||||
|
unhealthy_threshold: 5
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: healthcheck
|
||||||
|
- name: create a backend service
|
||||||
|
google.cloud.gcp_compute_backend_service:
|
||||||
|
name: backendservice-targethttpproxy
|
||||||
|
backends:
|
||||||
|
- group: "{{ instancegroup.selfLink }}"
|
||||||
|
health_checks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
enable_cdn: 'true'
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: backendservice
|
||||||
|
- name: create a URL map
|
||||||
|
google.cloud.gcp_compute_url_map:
|
||||||
|
name: urlmap-targethttpproxy
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: urlmap
|
||||||
|
- name: delete a region target HTTP proxy
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: create a region target HTTP proxy
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_target_http_proxy was created
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 1
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: create a region target HTTP proxy that already exists
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: delete a region target HTTP proxy
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_target_http_proxy was deleted
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 0
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: delete a region target HTTP proxy that does not exist
|
||||||
|
google.cloud.gcp_compute_region_target_http_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#---------------------------------------------------------
|
||||||
|
# Post-test teardown
|
||||||
|
# If errors happen, don't crash the playbook!
|
||||||
|
- name: delete a URL map
|
||||||
|
google.cloud.gcp_compute_url_map:
|
||||||
|
name: urlmap-targethttpproxy
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: urlmap
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a backend service
|
||||||
|
google.cloud.gcp_compute_backend_service:
|
||||||
|
name: backendservice-targethttpproxy
|
||||||
|
backends:
|
||||||
|
- group: "{{ instancegroup.selfLink }}"
|
||||||
|
health_checks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
enable_cdn: 'true'
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: backendservice
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a HTTP health check
|
||||||
|
google.cloud.gcp_compute_http_health_check:
|
||||||
|
name: httphealthcheck-targethttpproxy
|
||||||
|
healthy_threshold: 10
|
||||||
|
port: 8080
|
||||||
|
timeout_sec: 2
|
||||||
|
unhealthy_threshold: 5
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: healthcheck
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a instance group
|
||||||
|
google.cloud.gcp_compute_instance_group:
|
||||||
|
name: instancegroup-targethttpproxy
|
||||||
|
zone: us-central1-a
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: instancegroup
|
||||||
|
ignore_errors: true
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- include_tasks: autogen.yml
|
|
@ -0,0 +1,2 @@
|
||||||
|
cloud/gcp
|
||||||
|
unsupported
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
resource_name: "{{ resource_prefix }}"
|
|
@ -0,0 +1,288 @@
|
||||||
|
---
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Pre-test setup
|
||||||
|
- name: create a instance group
|
||||||
|
google.cloud.gcp_compute_instance_group:
|
||||||
|
name: instancegroup-targethttpsproxy
|
||||||
|
zone: us-central1-a
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: instancegroup
|
||||||
|
- name: create a region health check
|
||||||
|
google.cloud.gcp_compute_region_health_check:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
type: HTTPS
|
||||||
|
healthy_threshold: 10
|
||||||
|
timeout_sec: 2
|
||||||
|
unhealthy_threshold: 5
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: healthcheck
|
||||||
|
- name: create a region backend service
|
||||||
|
google.cloud.gcp_compute_region_backend_service:
|
||||||
|
name: backendservice-targethttpsproxy
|
||||||
|
region: us-central1
|
||||||
|
backends:
|
||||||
|
- group: "{{ instancegroup.selfLink }}"
|
||||||
|
healthchecks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: backendservice
|
||||||
|
- name: create a region URL map
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: urlmap-targethttpsproxy
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: urlmap
|
||||||
|
- name: create a SSL certificate
|
||||||
|
google.cloud.gcp_compute_ssl_certificate:
|
||||||
|
name: sslcert-targethttpsproxy
|
||||||
|
description: A certificate for testing. Do not use this certificate in production
|
||||||
|
certificate: |-
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
|
||||||
|
EwJVUzETMBEGA1UECAwKV2FzaGluZ3RvbjERMA8GA1UEBwwIS2lya2xhbmQxFTAT
|
||||||
|
BgNVBAoMDEdvb2dsZSwgSW5jLjEeMBwGA1UECwwVR29vZ2xlIENsb3VkIFBsYXRm
|
||||||
|
b3JtMR8wHQYDVQQDDBZ3d3cubXktc2VjdXJlLXNpdGUuY29tMSEwHwYJKoZIhvcN
|
||||||
|
AQkBFhJuZWxzb25hQGdvb2dsZS5jb20wHhcNMTcwNjI4MDQ1NjI2WhcNMjcwNjI2
|
||||||
|
MDQ1NjI2WjCBsDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xETAP
|
||||||
|
BgNVBAcMCEtpcmtsYW5kMRUwEwYDVQQKDAxHb29nbGUsIEluYy4xHjAcBgNVBAsM
|
||||||
|
FUdvb2dsZSBDbG91ZCBQbGF0Zm9ybTEfMB0GA1UEAwwWd3d3Lm15LXNlY3VyZS1z
|
||||||
|
aXRlLmNvbTEhMB8GCSqGSIb3DQEJARYSbmVsc29uYUBnb29nbGUuY29tMFkwEwYH
|
||||||
|
KoZIzj0CAQYIKoZIzj0DAQcDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ
|
||||||
|
4mzkzTv0dXyB750fOGN02HtkpBOZzzvUARTR10JQoSe2/5PIwaNQME4wHQYDVR0O
|
||||||
|
BBYEFKIQC3A2SDpxcdfn0YLKineDNq/BMB8GA1UdIwQYMBaAFKIQC3A2SDpxcdfn
|
||||||
|
0YLKineDNq/BMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0EAwIDSQAwRgIhALs4vy+O
|
||||||
|
M3jcqgA4fSW/oKw6UJxp+M6a+nGMX+UJR3YgAiEAvvl39QRVAiv84hdoCuyON0lJ
|
||||||
|
zqGNhIPGq2ULqXKK8BY=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
private_key: |-
|
||||||
|
-----BEGIN EC PRIVATE KEY-----
|
||||||
|
MHcCAQEEIObtRo8tkUqoMjeHhsOh2ouPpXCgBcP+EDxZCB/tws15oAoGCCqGSM49
|
||||||
|
AwEHoUQDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ4mzkzTv0dXyB750f
|
||||||
|
OGN02HtkpBOZzzvUARTR10JQoSe2/5PIwQ==
|
||||||
|
-----END EC PRIVATE KEY-----
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: sslcert
|
||||||
|
- name: delete a region target HTTPS proxy
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
ssl_certificates:
|
||||||
|
- "{{ sslcert }}"
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: create a region target HTTPS proxy
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
ssl_certificates:
|
||||||
|
- "{{ sslcert }}"
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_target_https_proxy was created
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 1
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: create a region target HTTPS proxy that already exists
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
ssl_certificates:
|
||||||
|
- "{{ sslcert }}"
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: delete a region target HTTPS proxy
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
ssl_certificates:
|
||||||
|
- "{{ sslcert }}"
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_target_https_proxy was deleted
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 0
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: delete a region target HTTPS proxy that does not exist
|
||||||
|
google.cloud.gcp_compute_region_target_https_proxy:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
ssl_certificates:
|
||||||
|
- "{{ sslcert }}"
|
||||||
|
url_map: "{{ urlmap }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#---------------------------------------------------------
|
||||||
|
# Post-test teardown
|
||||||
|
# If errors happen, don't crash the playbook!
|
||||||
|
- name: delete a SSL certificate
|
||||||
|
google.cloud.gcp_compute_ssl_certificate:
|
||||||
|
name: sslcert-targethttpsproxy
|
||||||
|
description: A certificate for testing. Do not use this certificate in production
|
||||||
|
certificate: |-
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICqjCCAk+gAwIBAgIJAIuJ+0352Kq4MAoGCCqGSM49BAMCMIGwMQswCQYDVQQG
|
||||||
|
EwJVUzETMBEGA1UECAwKV2FzaGluZ3RvbjERMA8GA1UEBwwIS2lya2xhbmQxFTAT
|
||||||
|
BgNVBAoMDEdvb2dsZSwgSW5jLjEeMBwGA1UECwwVR29vZ2xlIENsb3VkIFBsYXRm
|
||||||
|
b3JtMR8wHQYDVQQDDBZ3d3cubXktc2VjdXJlLXNpdGUuY29tMSEwHwYJKoZIhvcN
|
||||||
|
AQkBFhJuZWxzb25hQGdvb2dsZS5jb20wHhcNMTcwNjI4MDQ1NjI2WhcNMjcwNjI2
|
||||||
|
MDQ1NjI2WjCBsDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xETAP
|
||||||
|
BgNVBAcMCEtpcmtsYW5kMRUwEwYDVQQKDAxHb29nbGUsIEluYy4xHjAcBgNVBAsM
|
||||||
|
FUdvb2dsZSBDbG91ZCBQbGF0Zm9ybTEfMB0GA1UEAwwWd3d3Lm15LXNlY3VyZS1z
|
||||||
|
aXRlLmNvbTEhMB8GCSqGSIb3DQEJARYSbmVsc29uYUBnb29nbGUuY29tMFkwEwYH
|
||||||
|
KoZIzj0CAQYIKoZIzj0DAQcDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ
|
||||||
|
4mzkzTv0dXyB750fOGN02HtkpBOZzzvUARTR10JQoSe2/5PIwaNQME4wHQYDVR0O
|
||||||
|
BBYEFKIQC3A2SDpxcdfn0YLKineDNq/BMB8GA1UdIwQYMBaAFKIQC3A2SDpxcdfn
|
||||||
|
0YLKineDNq/BMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0EAwIDSQAwRgIhALs4vy+O
|
||||||
|
M3jcqgA4fSW/oKw6UJxp+M6a+nGMX+UJR3YgAiEAvvl39QRVAiv84hdoCuyON0lJ
|
||||||
|
zqGNhIPGq2ULqXKK8BY=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
private_key: |-
|
||||||
|
-----BEGIN EC PRIVATE KEY-----
|
||||||
|
MHcCAQEEIObtRo8tkUqoMjeHhsOh2ouPpXCgBcP+EDxZCB/tws15oAoGCCqGSM49
|
||||||
|
AwEHoUQDQgAEHGzpcRJ4XzfBJCCPMQeXQpTXwlblimODQCuQ4mzkzTv0dXyB750f
|
||||||
|
OGN02HtkpBOZzzvUARTR10JQoSe2/5PIwQ==
|
||||||
|
-----END EC PRIVATE KEY-----
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: sslcert
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a region URL map
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: urlmap-targethttpsproxy
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: urlmap
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a region backend service
|
||||||
|
google.cloud.gcp_compute_region_backend_service:
|
||||||
|
name: backendservice-targethttpsproxy
|
||||||
|
region: us-central1
|
||||||
|
backends:
|
||||||
|
- group: "{{ instancegroup.selfLink }}"
|
||||||
|
healthchecks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: backendservice
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a region health check
|
||||||
|
google.cloud.gcp_compute_region_health_check:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
type: HTTPS
|
||||||
|
healthy_threshold: 10
|
||||||
|
timeout_sec: 2
|
||||||
|
unhealthy_threshold: 5
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: healthcheck
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a instance group
|
||||||
|
google.cloud.gcp_compute_instance_group:
|
||||||
|
name: instancegroup-targethttpsproxy
|
||||||
|
zone: us-central1-a
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: instancegroup
|
||||||
|
ignore_errors: true
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- include_tasks: autogen.yml
|
|
@ -0,0 +1,2 @@
|
||||||
|
cloud/gcp
|
||||||
|
unsupported
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
resource_name: "{{ resource_prefix }}"
|
|
@ -0,0 +1,169 @@
|
||||||
|
---
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This file is automatically generated by Magic Modules and manual
|
||||||
|
# changes will be clobbered when the file is regenerated.
|
||||||
|
#
|
||||||
|
# Please read more about how to change this file at
|
||||||
|
# https://www.github.com/GoogleCloudPlatform/magic-modules
|
||||||
|
#
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Pre-test setup
|
||||||
|
- name: create a health check
|
||||||
|
google.cloud.gcp_compute_health_check:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
type: HTTP
|
||||||
|
http_health_check:
|
||||||
|
port: 80
|
||||||
|
check_interval_sec: 1
|
||||||
|
timeout_sec: 1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: healthcheck
|
||||||
|
- name: create a region backend service
|
||||||
|
google.cloud.gcp_compute_region_backend_service:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
health_checks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
protocol: HTTP
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: backendservice
|
||||||
|
- name: delete a region URL map
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: create a region URL map
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_url_map was created
|
||||||
|
google.cloud.gcp_compute_region_url_map_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 1
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: create a region URL map that already exists
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#----------------------------------------------------------
|
||||||
|
- name: delete a region URL map
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is true
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == true
|
||||||
|
- name: verify that region_url_map was deleted
|
||||||
|
google.cloud.gcp_compute_region_url_map_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ resource_name }}
|
||||||
|
region: us-central1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: results
|
||||||
|
- name: verify that command succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- results['resources'] | length == 0
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
- name: delete a region URL map that does not exist
|
||||||
|
google.cloud.gcp_compute_region_url_map:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
default_service: "{{ backendservice }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
- name: assert changed is false
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.changed == false
|
||||||
|
#---------------------------------------------------------
|
||||||
|
# Post-test teardown
|
||||||
|
# If errors happen, don't crash the playbook!
|
||||||
|
- name: delete a region backend service
|
||||||
|
google.cloud.gcp_compute_region_backend_service:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
region: us-central1
|
||||||
|
health_checks:
|
||||||
|
- "{{ healthcheck.selfLink }}"
|
||||||
|
protocol: HTTP
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: backendservice
|
||||||
|
ignore_errors: true
|
||||||
|
- name: delete a health check
|
||||||
|
google.cloud.gcp_compute_health_check:
|
||||||
|
name: "{{ resource_name }}"
|
||||||
|
type: HTTP
|
||||||
|
http_health_check:
|
||||||
|
port: 80
|
||||||
|
check_interval_sec: 1
|
||||||
|
timeout_sec: 1
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
|
state: absent
|
||||||
|
register: healthcheck
|
||||||
|
ignore_errors: true
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- include_tasks: autogen.yml
|
Loading…
Add table
Reference in a new issue