JSON模板代码示例如下所示:
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "When instance is labeled with the specified tag, Tags will be propagated to the related resources.",
"zh-cn": "当实例绑定特定标签时,传播标签到与实例相关的云盘、弹性网卡、弹性公网IP资源",
"name-zh-cn": "当实例绑定特定标签时,传播标签到与实例相关的云盘、弹性网卡、弹性公网IP资源",
"categories": [
"event-trigger"
]
},
"Parameters": {
"TagKey": {
"Type": "String",
"Description": "Tag key for tag instance"
},
"TagValue": {
"Type": "String",
"Description": "Tag value for tag instance"
},
"OOSAssumeRole": {
"Description": {
"en": "The RAM role to be assumed by OOS.",
"zh-cn": "OOS扮演的RAM角色"
},
"Type": "String",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{ OOSAssumeRole }}",
"Tasks": [
{
"Name": "eventTrigger",
"Description": {
"en": "Monitor the ECS instance TAG event.",
"zh-cn": "监控实例标签变化"
},
"Action": "ACS::EventTrigger",
"Properties": {
"Product": "tag",
"Name": [
"Tag:ChangeOnResource"
],
"Level": [
"INFO"
],
"Content": {
"product": [
"ecs"
],
"resourceType": [
"instance"
]
}
},
"Outputs": {
"instanceId": {
"ValueSelector": ".content.resourceId",
"Type": "String"
},
"isTag": {
"ValueSelector": ".content.addedTags|select(.{{TagKey}}==\"{{TagValue}}\") |[.] |all|tostring",
"Type": "String"
}
}
},
{
"Name": "whetherNeedTag",
"Action": "ACS::Choice",
"Description": {
"zh-cn": "判断是否需要传播的标签",
"en": "Determine whether the tag needs to be propagated"
},
"Properties": {
"DefaultTask": "describeInstancesFinally",
"Choices": [
{
"When": {
"Fn::Equals": [
"true",
"{{ eventTrigger.isTag }}"
]
},
"NextTask": "describeInstances"
}
]
}
},
{
"Name": "describeInstances",
"Action": "ACS::ExecuteAPI",
"Description": {
"zh-cn": "查询实例,获取与实例相关的弹性网卡、弹性公网IP资源",
"en": "Query the instance to obtain the network interface and elastic public network IP resources related to the instance."
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ ACS::RegionId }}",
"InstanceIds": [
"{{ eventTrigger.instanceId }}"
]
}
},
"Outputs": {
"eips": {
"Type": "List",
"ValueSelector": "Instances.Instance[].EipAddress.AllocationId"
},
"enis": {
"Type": "List",
"ValueSelector": "Instances.Instance[].NetworkInterfaces.NetworkInterface[].NetworkInterfaceId"
}
}
},
{
"Name": "describeDisks",
"Action": "ACS::ExecuteAPI",
"Description": {
"zh-cn": "根据实例ID获取云盘信息",
"en": "Obtain disk ids based on instance id."
},
"Properties": {
"Service": "ECS",
"API": "DescribeDisks",
"Parameters": {
"RegionId": "{{ ACS::RegionId }}",
"InstanceId": "{{ eventTrigger.instanceId }}"
}
},
"Outputs": {
"diskIds": {
"Type": "List",
"ValueSelector": "Disks.Disk[].DiskId"
}
}
},
{
"Name": "tagResourcesDisks",
"Action": "ACS::ExecuteAPI",
"Description": {
"zh-cn": "标记云盘",
"en": "Tag disks"
},
"Properties": {
"Service": "ECS",
"API": "TagResources",
"Parameters": {
"RegionId": "{{ ACS::RegionId }}",
"ResourceIds": [
"{{ ACS::TaskLoopItem }}"
],
"ResourceType": "disk",
"Tags": [
{
"Key": "{{TagKey}}",
"Value": "{{TagValue}}"
}
]
}
},
"Loop": {
"RateControl": {
"Mode": "Batch",
"MaxErrors": 0,
"Batch": [
50
],
"BatchPauseOption": "Automatic",
"ConcurrencyInBatches": [
1
]
},
"Items": "{{ describeDisks.diskIds }}"
}
},
{
"Name": "tagResourcesEnis",
"Action": "ACS::ExecuteAPI",
"Description": {
"zh-cn": "标记弹性网卡",
"en": "Tag network interface."
},
"Properties": {
"Service": "ECS",
"API": "TagResources",
"Parameters": {
"RegionId": "{{ ACS::RegionId }}",
"ResourceIds": [
"{{ ACS::TaskLoopItem }}"
],
"ResourceType": "eni",
"Tags": [
{
"Key": "{{TagKey}}",
"Value": "{{TagValue}}"
}
]
}
},
"Loop": {
"RateControl": {
"Mode": "Batch",
"MaxErrors": 0,
"Batch": [
50
],
"BatchPauseOption": "Automatic",
"ConcurrencyInBatches": [
1
]
},
"Items": "{{ describeInstances.enis }}"
}
},
{
"Name": "tagResourcesEips",
"Action": "ACS::ExecuteAPI",
"Description": {
"zh-cn": "标记弹性公网IP",
"en": "Tag eips"
},
"Properties": {
"Service": "VPC",
"API": "TagResources",
"Parameters": {
"RegionId": "{{ ACS::RegionId }}",
"ResourceIds": [
"{{ ACS::TaskLoopItem }}"
],
"ResourceType": "eip",
"Tags": [
{
"Key": "{{TagKey}}",
"Value": "{{TagValue}}"
}
]
}
},
"Loop": {
"RateControl": {
"Mode": "Batch",
"MaxErrors": 1,
"Batch": [
50
],
"BatchPauseOption": "Automatic",
"ConcurrencyInBatches": [
1
]
},
"Items": "{{ describeInstances.eips }}"
}
},
{
"Name": "describeInstancesFinally",
"Action": "ACS::ExecuteAPI",
"Description": {
"zh-cn": "查询实例状态",
"en": "Views the ECS instances Status."
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ ACS::RegionId }}",
"InstanceIds": [
"{{ eventTrigger.instanceId }}"
]
}
},
"Outputs": {
"status": {
"Type": "String",
"ValueSelector": "Instances.Instance[].Status"
}
}
}
],
"Outputs": {
"instanceId": {
"Value": "{{ eventTrigger.instanceId}}",
"Type": "String"
},
"diskIds": {
"Value": "{{ describeDisks.diskIds }}",
"Type": "String"
},
"eips": {
"Value": "{{ describeInstances.eips }}",
"Type": "String"
},
"enis": {
"Value": "{{ describeInstances.enis }}",
"Type": "String"
}
}
}