Template name
ACS-SMC-CreateAndVerifyInstance
Template description
Creates instances as destination instances and runs commands to verify the destination instances in Server Migration Center (SMC).
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
zoneId | The zone ID. | String | Yes | ||
hostName | The name of the host on which the instances are to be created. | String | Yes | Regular expression for string verification: ^(?!. | |
imageId | The ID of the image from which the instances are to be created. | String | Yes | ||
instanceType | The instance type of the instances that are to be created. | String | Yes | ||
privateIp | The internal IP address of the instances to be created. | String | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
systemDiskSize | The size of the system disk. | Number | No | 19 | |
instancesCount | The number of instances to be created. | Number | No | 1 | |
isDeleteInstance | Specifies whether to delete the instances after they are verified. | Boolean | No | True | |
commandType | The type of the Cloud Assistant commands that are used to verify the instances. | String | No | RunShellScript | |
commandContent | The content of the Cloud Assistant commands that are used to verify the instances. | String | No | "" | |
timeout | The timeout period of the commands. | Number | No | 600 | |
workingDir | The directory in which the commands are run. | String | No | /root | |
passwordInherit | Specifies whether to use the password preset in the image. | Boolean | No | False | |
rateControl | The rate control settings. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS). | String | No | "" |
Output parameters
Parameter | Description | Type |
instanceCheckResults | List |
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DeleteInstance",
"ecs:DeleteSecurityGroup",
"ecs:DescribeCloudAssistantStatus",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:InstallCloudAssistant",
"ecs:RebootInstance",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"vpc:DeleteVSwitch",
"vpc:DeleteVpc",
"vpc:DescribeVSwitches",
"vpc:DescribeVpcs"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-SMC-CreateAndVerifyInstance at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Create and verify instance by commands
name-en: ACS-SMC-CreateAndVerifyInstance
Parameters:
regionId:
Type: String
Label:
en: RegionId
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Label:
en: ZoneId
Description:
en: The target zone id of VSwitch to create
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
Type: String
AssociationPropertyMetadata:
RegionId: regionId
hostName:
Label:
en: HostName
Type: String
AllowedPattern: '^(?!\.|\-)(?!.*\.\.|.*\-\-)(?!.*_).*(?<!\.|\-)$'
MinLength: 2
imageId:
Label:
en: ImageId
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
instanceType:
Label:
en: InstanceType
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
privateIp:
Label:
en: PrivateIp
Type: String
systemDiskSize:
Label:
en: SystemDiskSize
Type: Number
Default: 19
MinValue: 19
MaxValue: 500
instancesCount:
Label:
en: InstancesCount
Type: Number
Default: 1
MinValue: 1
MaxValue: 999
isDeleteInstance:
Label:
en: IsDeleteInstance
Type: Boolean
Default: true
commandType:
Label:
en: CommandType
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
Type: String
AssociationProperty: Code
Default: ''
timeout:
Label:
en: Timeout
Type: Number
Default: 600
workingDir:
Label:
en: WorkingDir
Type: String
Default: /root
passwordInherit:
Description:
en: To use the PasswordInherit parameter, the Password parameter must be empty and you must make sure that the selected image has a password configured(default:false)
Label:
en: IsUsePasswordInherit
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: describeImages
Action: 'ACS::ExecuteAPI'
Description:
en: Query the image ostype by image id
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ imageId }}'
Outputs:
osType:
ValueSelector: 'Images.Image[0].OSType'
Type: String
- Name: converConstant
Action: 'ACS::ECS::SMCConversionConstantByJqScript'
Description:
en: Automatically convert to available CidrBlock according to PrivateIp
Properties:
parameter: '{{ privateIp }}'
jqScript:
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10.0.0.0/8" elif .[0]=="172" then "172.16.0.0/12" elif .[0]=="192" then "192.168.0.0/16" else "" end'
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10."+.[1]+".0.0/16" elif .[0]=="172" then "172."+.[1]+"."+.[2]+".0/24" elif .[0]=="192" then "192.168."+.[2]+".0/24" else "" end'
Outputs:
vswCidrBlock:
Type: String
ValueSelector: secondValue
vpcCidrBlock:
Type: String
ValueSelector: firstValue
- Name: createStack
Action: 'ACS::ExecuteAPI'
Description:
en: Create a resource stack
Properties:
Service: ROS
API: CreateStack
Parameters:
RegionId: '{{ regionId }}'
StackName: 'OOS-{{ACS::ExecutionId}}'
TimeoutInMinutes: 10
DisableRollback: false
Parameters:
- ParameterKey: hostName
ParameterValue: '{{ hostName }}'
- ParameterKey: privateIp
ParameterValue: '{{ privateIp }}'
- ParameterKey: instanceType
ParameterValue: '{{ instanceType }}'
- ParameterKey: zoneId
ParameterValue: '{{ zoneId }}'
- ParameterKey: regionId
ParameterValue: '{{ regionId }}'
- ParameterKey: imageId
ParameterValue: '{{imageId}}'
- ParameterKey: executionId
ParameterValue: '{{ ACS::ExecutionId }}'
- ParameterKey: instancesCount
ParameterValue: '{{ instancesCount }}'
- ParameterKey: systemDiskSize
ParameterValue: '{{ systemDiskSize }}'
- ParameterKey: passwordInherit
ParameterValue: '{{ passwordInherit }}'
TemplateBody:
'Fn::If':
- 'Fn::Equals':
- windows
- '{{ describeImages.osType }}'
- |
{
"Description": "Create VPC ECS instance",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"passwordInherit": {
"Type": "Boolean"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "3389/3389",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
- |
{
"Description": "Create VPC ECS instance",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"passwordInherit": {
"Type": "Boolean"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "22/22",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
Description:
en: Wait for the stack status CREATE_COMPLETE
OnSuccess: doInstanceCheck
OnError: queryStackStatusReason
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
- CREATE_ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
instanceIds:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
- Name: doInstanceCheck
Action: 'ACS::ECS::SMCVerifyInstanceByRunCommand'
OnSuccess: 'ACS::END'
OnError: deleteStack
Description:
en: Execute cloud assistant command to check Instance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
isDeleteInstance: '{{ isDeleteInstance }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
workingDir: '{{ workingDir }}'
timeout: '{{ timeout }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ untilStackReady.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
- Name: queryStackStatusReason
Action: 'ACS::ExecuteAPI'
Description:
en: Query the reson of failed created stack
OnError: deleteStack
OnSuccess: deleteStack
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{ createStack.StackId }}'
Outputs:
statusReason:
Type: String
ValueSelector: StatusReason
- Name: deleteStack
Description:
en: Delete the stack
OnSuccess: 'ACS::END'
Action: 'ACS::ExecuteApi'
Properties:
Service: ROS
API: DeleteStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
Outputs:
instanceCheckResults:
Type: List
Value: '{{ doInstanceCheck.commandOutputs }}'