-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcomputeengine-example.yaml
82 lines (79 loc) · 3.04 KB
/
computeengine-example.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
81
82
# Copyright 2023 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.
# Example of controlling Compute Engine instances (failover-like setup)
# We'll employ a lock file to prevent this function from running concurrently
concurrency:
bucket: add-a-bucket-here
pipeline:
- type: processor.genericjson
- type: processor.computeengine
output: primary
config:
mode: instances.get
zone: europe-west4-c
instance: failover-primary
- type: output.logger
config:
message: |
Primary instance: {{ primary|json_encode }}
- type: processor.computeengine # Make an instant snapshot of the disk before stopping the instance
canFail: true
config:
mode: disks.instantSnapshots.create
region: europe-west4
disk: projects/example-project/regions/europe-west4/disks/failover-regional-disk-1
snapshotName: "failover-regional-disk-1-{{ ''|utc_strftime('%Y%m%d-%H%M%S') }}"
- type: processor.computeengine # Only keep 3 last snapshots
canFail: true
config:
mode: disks.instantSnapshots.purge
region: europe-west4
snapshotName: "^failover-regional-disk-1-"
maxSnapshots: 3
- type: processor.computeengine # Stop the instance
canFail: true
config:
mode: instances.stop
zone: europe-west4-c
instance: failover-primary
- type: processor.computeengine # Attempt to detach the disk politely
canFail: true
config:
mode: instances.detachdisk
zone: europe-west4-c
instance: failover-primary
disk: projects/example-project/regions/europe-west4/disks/failover-regional-disk-1
# deviceName: failover-regional-disk-1
- type: processor.computeengine # Attach the disk to the other instance, forcibly
config:
mode: instances.attachdisk
zone: europe-west4-b
instance: failover-secondary
disk: projects/example-project/regions/europe-west4/disks/failover-regional-disk-1
deviceName: failover-regional-disk-1
forceAttach: true
- type: processor.computeengine # Start the other instance
canFail: true
config:
mode: instances.start
zone: europe-west4-b
instance: failover-secondary
- type: processor.loadbalancing # Update the backend service with a UMIG containing the spun up instance
config:
mode: regionbackendservice.patch
region: "europe-west4"
backendService: "l4-backend-service"
patch:
backends:
- group: "https://www.googleapis.com/compute/v1/projects/example-project/zones/europe-west4-c/instanceGroups/secondary-mig"