-
Notifications
You must be signed in to change notification settings - Fork 37
/
create-stop-vm-connector.yaml
80 lines (79 loc) · 2.55 KB
/
create-stop-vm-connector.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
main:
params: [args]
steps:
- init:
assign:
- project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- zone: "europe-west1-b"
- machineType: "e2-small"
- instanceName: "${args.instanceName}"
- insert_machine:
call: googleapis.compute.v1.instances.insert
args:
project: ${project}
zone: ${zone}
body:
name: ${instanceName}
machineType: ${"zones/" + zone + "/machineTypes/" + machineType}
disks:
- initializeParams:
sourceImage: "projects/debian-cloud/global/images/debian-10-buster-v20201112"
boot: true
autoDelete: true
networkInterfaces:
- network: "global/networks/default"
- assert_running:
call: assert_machine_status
args:
expected_status: "RUNNING"
project: ${project}
zone: ${zone}
instanceName: ${instanceName}
- stop_machine:
call: googleapis.compute.v1.instances.stop
args:
instance: ${instanceName}
project: ${project}
zone: ${zone}
# Optional connector parameters
connector_params:
timeout: 100 # total time is 100s
polling_policy: # optional polling parameters for LRO polling.
initial_delay: 1
multiplier: 1.25
- assert_terminated:
call: assert_machine_status
args:
expected_status: "TERMINATED"
project: ${project}
zone: ${zone}
instanceName: ${instanceName}
assert_machine_status:
params: [expected_status, project, zone, instanceName]
steps:
- get_instance:
call: googleapis.compute.v1.instances.get
args:
instance: ${instanceName}
project: ${project}
zone: ${zone}
result: instance
- compare:
switch:
- condition: ${instance.status == expected_status}
next: end
- fail:
raise: ${"Expected VM status is " + expected_status + ". Got " + instance.status + " instead."}