-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::ECS::EncryptSystemDisk.yml
213 lines (213 loc) · 5.61 KB
/
ACS::ECS::EncryptSystemDisk.yml
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS::ECS::EncryptSystemDisk
name-zh-cn: 加密系统盘
en: Encrypt system disk
zh-cn: 加密系统盘
Parameters:
regionId:
Label:
en: RegionId
zh-cn: 地域ID
Type: String
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
instanceId:
Label:
en: InstanceId
zh-cn: 实例ID
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
KMSKeyId:
Label:
en: KMSKeyId
zh-cn: 加密镜像使用的KMS密钥ID
Type: String
Tasks:
- Name: waitInstanceReady
Action: ACS::WaitFor
Description:
en: Waits the ECS instance status to running or stopped
zh-cn: 等待实例到running或者stopped状态
Properties:
Service: ECS
API: DescribeInstances
Parameters:
RegionId: '{{ regionId }}'
InstanceIds:
- '{{ instanceId }}'
DesiredValues:
- Running
- Stopped
PropertySelector: Instances.Instance[].Status
Outputs:
keyPairName:
Type: String
ValueSelector: Instances.Instance[].KeyPairName
- Name: describeDisk
Action: ACS::ExecuteAPI
Description:
en: Query the disk info
zh-cn: 获取磁盘信息
Properties:
Service: ECS
API: DescribeDisks
Parameters:
RegionId: '{{ regionId }}'
InstanceId: '{{ instanceId }}'
DiskType: system
Outputs:
diskId:
Type: String
ValueSelector: Disks.Disk[].DiskId
encrypted:
Type: Boolean
ValueSelector: Disks.Disk[].Encrypted
- Name: whetherToEncrypt
Action: ACS::Choice
Description:
en: Choose the next task according to whether the disk is encrypted
zh-cn: 根据磁盘是否加密选择下一个任务
Properties:
DefaultTask: createSnapshot
Choices:
- When:
Fn::Equals:
- '{{ describeDisk.encrypted }}'
- true
NextTask: ACS::END
- Name: createSnapshot
Action: ACS::ECS::CreateSnapshot
Description:
en: Creates a snapshot for the system disk
zh-cn: 为系统盘创建快照
Properties:
regionId: '{{ regionId }}'
diskId: '{{ describeDisk.diskId }}'
snapshotName: 'Snapshot-{{ ACS::ExecutionId }}'
Outputs:
snapshotId:
Type: String
ValueSelector: snapshotId
- Name: createImage
Action: ACS::ExecuteAPI
Description:
en: Creates a custom image
zh-cn: 创建一份自定义镜像
Properties:
Service: ECS
API: CreateImage
Parameters:
RegionId: '{{ regionId }}'
ImageName: 'CreateImage-{{ ACS::ExecutionId }}'
SnapshotId: '{{ createSnapshot.snapshotId }}'
Outputs:
imageId:
Type: String
ValueSelector: ImageId
- Name: untilImageReady
Action: ACS::WaitFor
Description:
en: Waits for the image to be available
zh-cn: 等待创建的镜像可用
Retries: 296
MaxRetryInterval: 300
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ createImage.imageId }}'
Status: Creating,Waiting,Available,UnAvailable,CreateFailed,Deprecated
DesiredValues:
- Available
PropertySelector: Images.Image[].Status
- Name: copyImage
Action: ACS::ExecuteAPI
Description:
en: Copies image
zh-cn: 复制镜像
Properties:
Service: ECS
API: CopyImage
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ createImage.imageId }}'
DestinationRegionId: '{{ regionId }}'
KMSKeyId: '{{ KMSKeyId }}'
Encrypted: true
Outputs:
imageId:
ValueSelector: ImageId
Type: String
- Name: untilCopyImageReady
Action: ACS::WaitFor
Description:
en: Waits for copied image available
zh-cn: 等待复制的镜像可用
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ copyImage.imageId }}'
DesiredValues:
- Available
PropertySelector: 'Images.Image[].Status'
Retries: 296
MaxRetryInterval: 300
- Name: replaceSystemDisk
Action: ACS::ECS::ReplaceSystemDisk
OnError: ACS::NEXT
Description:
en: Replaces the system disk of ECS instances
zh-cn: 更换系统盘
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ instanceId }}'
imageId: '{{ copyImage.imageId }}'
keyPairName:
Fn::If:
- Fn::Equals:
- Null
- '{{ waitInstanceReady.keyPairName }}'
- ''
- '{{ waitInstanceReady.keyPairName }}'
passwordInherit: false
- Name: deleteImage
Action: ACS::ExecuteAPI
Description:
en: Deletes the image
zh-cn: 删除镜像
Properties:
Service: ECS
API: DeleteImage
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ ACS::TaskLoopItem }}'
Force: true
Loop:
Items:
- '{{ createImage.imageId }}'
- '{{ copyImage.imageId }}'
- Name: deleteSnapshot
Action: ACS::ExecuteAPI
Description:
en: Deletes the snapshot
zh-cn: 删除快照
Properties:
Service: ECS
API: DeleteSnapshot
Parameters:
RegionId: '{{ regionId }}'
SnapshotId: '{{ createSnapshot.snapshotId }}'
Outputs:
systemDiskEncryptedInstance:
Type: List
Value:
Fn::If:
- Fn::Equals:
- '{{ describeDisk.encrypted }}'
- true
- '{{ instanceId }}'
- null