If you frequently use the same parameter values in your Resource Orchestration Service (ROS) templates, you can store them in Operation Orchestration Service (OOS) Parameter Store. You can then reference these parameters by name in your ROS templates.
Background
OOS Parameter Store lets you store values as either common parameters or encryption parameters. Key Management Service (KMS) encrypts the encryption parameters. This topic uses an example of creating an ECS instance group to show you how to create parameters in OOS Parameter Store and reference them in a ROS template. This example creates the following parameters:
Parameter | Parameter name | Category | Type | Value |
ImageId | my_image | common parameter | String | centos_7_9_x64_20G_alibase_2020****.vhd |
SecurityGroupIds | security_group_ids | common parameter | StringList | sg-group1,sg-group2 |
Password | Password | encryption parameter | String | MyPassword1 |
For more information about the parameters, see ALIYUN::ECS::InstanceGroup.
You must create parameters in the same region as the stack that uses them. For example, if you plan to create a stack in the China (Hangzhou) region, you must also create the parameters in that region.
Step 1: Create parameters in the OOS console
Log on to the OOS console.
In the left-side navigation pane, click Parameter Store.
In the region drop-down list in the top navigation bar, select the region where you want to create the parameters.
NoteThe parameters must be in the same region as your stack. In this example, select China (Hangzhou).
Create the
my_imagecommon parameter.On the Parameter Store page, click the Common Parameters tab, and then click Create Common Parameter.
On the Create Common Parameter page, configure Parameter Name and Value, and select a Parameter Type.
For this example, use the following settings:
Parameter Name: my_image.
Parameter Type: String.
Value: centos_7_9_x64_20G_alibase_2020****.vhd.
Click Create.
After the parameter is created, you can click its name on the Common Parameters tab and view its details, such as name, version, type, and value, on the Description tab.
Create the
security_group_idscommon parameter.On the Parameter Store page, click the Common Parameters tab, and then click Create Common Parameter.
On the Create Common Parameter page, configure Parameter Name and Value, and select a Parameter Type.
For this example, use the following settings:
Parameter Name: security_group_ids.
Parameter Type: StringList.
Value: sg-group1,sg-group2.
Click Create.
After the parameter is created, you can click its name on the Common Parameters tab and view its details, such as name, version, type, and value, on the Description tab.
Create the
Passwordencryption parameter.On the Parameter Store page, click the Encryption Parameters tab, and then click Create Encryption Parameter.
On the Create Encryption Parameter page, configure Parameter Name and Value, and select a KMS Key ID.
For this example, use the following settings:
Parameter Name: Password.
KMS Key ID: Default Service CMK.
Value: MyPassword1.
Click Create.
After the parameter is created, you can click the parameter name on the Encryption Parameters tab. On the Description tab, click Show next to Value to view the value of the Password parameter.
Step 2: Write a ROS template
After you create the parameters, you can write a ROS template and reference the parameters in the Parameters or Resources section:
Reference parameters in the
ParameterssectionSet the
TypetoALIYUN::OOS::Parameter::Valuefor a common parameter orALIYUN::OOS::SecretParameter::Valuefor an encryption parameter.For example, the following code defines a template parameter named
ImageIdthat references the latest version of themy_imagecommon parameter.Parameters: ImageId: Type: ALIYUN::OOS::Parameter::Value Default: my_imageYou can also reference a specific version, such as version 1, by setting the parameter to
my_image:1.Reference parameters in the
ResourcessectionYou can reference a parameter in the
Propertiesof a resource by using the following format:{{resolve:<parameter-type>:<parameter-name>:<version-number>}}.parameter-type(Required)The type of the parameter. Valid values:
oos: a common parameter.oos-secret: an encryption parameter.
parameter-name(Required)The name of the parameter.
version-number(Optional)The parameter version. If you do not specify this field, the latest version is used.
For example, the following code shows how to reference the latest version of the
my_imagecommon parameter for theImageIdproperty and version 2 of thePasswordencryption parameter.Resources: ECS: Type: ALIYUN::ECS::Instance Properties: ImageId: '{{resolve:oos:my_image}}' Password: '{{resolve:oos-secret:Password:2}}' ...: null
You can use most intrinsic functions when you reference parameters in a template. For more information, see Functions. The following functions are not supported: Ref, Fn::GetAtt, Fn::GetStackOutput, and Fn::Calculate.
The following template is used in this example:
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
InstanceType:
Type: String
Default: ecs.c6.large
ImageId:
Type: ALIYUN::OOS::Parameter::Value
Default: my_image
Vpc:
Type: String
VSwitch:
Type: String
Resources:
ECS:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ImageId:
Ref: ImageId
InstanceType:
Ref: InstanceType
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupIds: '{{resolve:oos:security_group_ids:1}}'
Password: '{{resolve:oos-secret:Password}}'
MaxAmount: 1
Outputs:
InstanceIds:
Value:
Fn::GetAtt:
- ECS
- InstanceIdsROS automatically converts the data type of the referenced parameter based on its type in OOS. Parameter Store supports the String and StringList types. If you reference a parameter of the StringList type, ROS converts it to a List for use in the template. For example, the security_group_ids parameter is a StringList with a value of sg-group1,sg-group2. When you use this parameter to create an ALIYUN::ECS::InstanceGroup resource, ROS resolves the value to ["sg-group1", "sg-group2"].
Step 3: Create a stack in the ROS console
In the ROS console, use the sample template from Step 2 to create a stack that creates an ECS instance group. For detailed instructions, see Create a stack.
After the stack is created, you can verify that the parameters were referenced correctly. In the left-side navigation pane of the ROS console, click Stacks. On the Stacks page, find and click the name of your stack. On the stack details page, click the Parameters tab to view the parameters and their resolved values.