1---
2# ----------------------------------------------------------------------------
3#
4#     ***     AUTO GENERATED CODE    ***    AUTO GENERATED CODE     ***
5#
6# ----------------------------------------------------------------------------
7#
8#     This file is automatically generated by Magic Modules and manual
9#     changes will be clobbered when the file is regenerated.
10#
11#     Please read more about how to change this file at
12#     https://www.github.com/GoogleCloudPlatform/magic-modules
13#
14# ----------------------------------------------------------------------------
15# Pre-test setup
16- name: create a network
17  gcp_compute_network:
18    name: network-instancetemplate
19    project: "{{ gcp_project }}"
20    auth_kind: "{{ gcp_cred_kind }}"
21    service_account_file: "{{ gcp_cred_file }}"
22    state: present
23  register: network
24- name: create a address
25  gcp_compute_address:
26    name: address-instancetemplate
27    region: us-central1
28    project: "{{ gcp_project }}"
29    auth_kind: "{{ gcp_cred_kind }}"
30    service_account_file: "{{ gcp_cred_file }}"
31    state: present
32  register: address
33- name: create a instance template
34  gcp_compute_instance_template:
35    name: "{{ resource_name }}"
36    properties:
37      disks:
38      - auto_delete: 'true'
39        boot: 'true'
40        initialize_params:
41          source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
42      machine_type: n1-standard-1
43      network_interfaces:
44      - network: "{{ network }}"
45        access_configs:
46        - name: test-config
47          type: ONE_TO_ONE_NAT
48          nat_ip: "{{ address }}"
49    project: "{{ gcp_project }}"
50    auth_kind: "{{ gcp_cred_kind }}"
51    service_account_file: "{{ gcp_cred_file }}"
52    state: present
53  register: instancetemplate
54- name: create a instance group manager
55  gcp_compute_instance_group_manager:
56    name: "{{ resource_name }}"
57    base_instance_name: test1-child
58    instance_template: "{{ instancetemplate }}"
59    target_size: 3
60    zone: us-central1-a
61    project: "{{ gcp_project }}"
62    auth_kind: "{{ gcp_cred_kind }}"
63    service_account_file: "{{ gcp_cred_file }}"
64    state: present
65  register: igm
66- name: delete a autoscaler
67  gcp_compute_autoscaler:
68    name: "{{ resource_name }}"
69    zone: us-central1-a
70    target: "{{ igm }}"
71    autoscaling_policy:
72      max_num_replicas: 5
73      min_num_replicas: 1
74      cool_down_period_sec: 60
75      cpu_utilization:
76        utilization_target: 0.5
77    project: "{{ gcp_project }}"
78    auth_kind: "{{ gcp_cred_kind }}"
79    service_account_file: "{{ gcp_cred_file }}"
80    state: absent
81#----------------------------------------------------------
82- name: create a autoscaler
83  gcp_compute_autoscaler:
84    name: "{{ resource_name }}"
85    zone: us-central1-a
86    target: "{{ igm }}"
87    autoscaling_policy:
88      max_num_replicas: 5
89      min_num_replicas: 1
90      cool_down_period_sec: 60
91      cpu_utilization:
92        utilization_target: 0.5
93    project: "{{ gcp_project }}"
94    auth_kind: "{{ gcp_cred_kind }}"
95    service_account_file: "{{ gcp_cred_file }}"
96    state: present
97  register: result
98- name: assert changed is true
99  assert:
100    that:
101      - result.changed == true
102- name: verify that autoscaler was created
103  gcp_compute_autoscaler_info:
104      filters:
105         - name = {{ resource_name }}
106      zone: us-central1-a
107      project: "{{ gcp_project }}"
108      auth_kind: "{{ gcp_cred_kind }}"
109      service_account_file: "{{ gcp_cred_file }}"
110      scopes:
111        - https://www.googleapis.com/auth/compute
112  register: results
113- name: verify that command succeeded
114  assert:
115    that:
116      - results['resources'] | length == 1
117# ----------------------------------------------------------------------------
118- name: create a autoscaler that already exists
119  gcp_compute_autoscaler:
120    name: "{{ resource_name }}"
121    zone: us-central1-a
122    target: "{{ igm }}"
123    autoscaling_policy:
124      max_num_replicas: 5
125      min_num_replicas: 1
126      cool_down_period_sec: 60
127      cpu_utilization:
128        utilization_target: 0.5
129    project: "{{ gcp_project }}"
130    auth_kind: "{{ gcp_cred_kind }}"
131    service_account_file: "{{ gcp_cred_file }}"
132    state: present
133  register: result
134- name: assert changed is false
135  assert:
136    that:
137      - result.changed == false
138#----------------------------------------------------------
139- name: delete a autoscaler
140  gcp_compute_autoscaler:
141    name: "{{ resource_name }}"
142    zone: us-central1-a
143    target: "{{ igm }}"
144    autoscaling_policy:
145      max_num_replicas: 5
146      min_num_replicas: 1
147      cool_down_period_sec: 60
148      cpu_utilization:
149        utilization_target: 0.5
150    project: "{{ gcp_project }}"
151    auth_kind: "{{ gcp_cred_kind }}"
152    service_account_file: "{{ gcp_cred_file }}"
153    state: absent
154  register: result
155- name: assert changed is true
156  assert:
157    that:
158      - result.changed == true
159- name: verify that autoscaler was deleted
160  gcp_compute_autoscaler_info:
161      filters:
162         - name = {{ resource_name }}
163      zone: us-central1-a
164      project: "{{ gcp_project }}"
165      auth_kind: "{{ gcp_cred_kind }}"
166      service_account_file: "{{ gcp_cred_file }}"
167      scopes:
168        - https://www.googleapis.com/auth/compute
169  register: results
170- name: verify that command succeeded
171  assert:
172    that:
173      - results['resources'] | length == 0
174# ----------------------------------------------------------------------------
175- name: delete a autoscaler that does not exist
176  gcp_compute_autoscaler:
177    name: "{{ resource_name }}"
178    zone: us-central1-a
179    target: "{{ igm }}"
180    autoscaling_policy:
181      max_num_replicas: 5
182      min_num_replicas: 1
183      cool_down_period_sec: 60
184      cpu_utilization:
185        utilization_target: 0.5
186    project: "{{ gcp_project }}"
187    auth_kind: "{{ gcp_cred_kind }}"
188    service_account_file: "{{ gcp_cred_file }}"
189    state: absent
190  register: result
191- name: assert changed is false
192  assert:
193    that:
194      - result.changed == false
195#---------------------------------------------------------
196# Post-test teardown
197# If errors happen, don't crash the playbook!
198- name: delete a instance group manager
199  gcp_compute_instance_group_manager:
200    name: "{{ resource_name }}"
201    base_instance_name: test1-child
202    instance_template: "{{ instancetemplate }}"
203    target_size: 3
204    zone: us-central1-a
205    project: "{{ gcp_project }}"
206    auth_kind: "{{ gcp_cred_kind }}"
207    service_account_file: "{{ gcp_cred_file }}"
208    state: absent
209  register: igm
210  ignore_errors: true
211- name: delete a instance template
212  gcp_compute_instance_template:
213    name: "{{ resource_name }}"
214    properties:
215      disks:
216      - auto_delete: 'true'
217        boot: 'true'
218        initialize_params:
219          source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
220      machine_type: n1-standard-1
221      network_interfaces:
222      - network: "{{ network }}"
223        access_configs:
224        - name: test-config
225          type: ONE_TO_ONE_NAT
226          nat_ip: "{{ address }}"
227    project: "{{ gcp_project }}"
228    auth_kind: "{{ gcp_cred_kind }}"
229    service_account_file: "{{ gcp_cred_file }}"
230    state: absent
231  register: instancetemplate
232  ignore_errors: true
233- name: delete a address
234  gcp_compute_address:
235    name: address-instancetemplate
236    region: us-central1
237    project: "{{ gcp_project }}"
238    auth_kind: "{{ gcp_cred_kind }}"
239    service_account_file: "{{ gcp_cred_file }}"
240    state: absent
241  register: address
242  ignore_errors: true
243- name: delete a network
244  gcp_compute_network:
245    name: network-instancetemplate
246    project: "{{ gcp_project }}"
247    auth_kind: "{{ gcp_cred_kind }}"
248    service_account_file: "{{ gcp_cred_file }}"
249    state: absent
250  register: network
251  ignore_errors: true
252