To efficiently query parameters in Resource Orchestration Service (ROS) templates, you can use the Parameter Store feature of Operation Orchestration Service (OOS) to create the parameters and then reference the parameters in the ROS templates.

Background information

OOS Parameter Store allows you to store common parameters and encryption parameters. Encryption parameters are used by Key Management Service (KMS) to encrypt the stored values. This topic describes how to create parameters by using OOS Parameter Store, reference the parameters in an ROS template, and then use the template to create a stack. In this example, a group of Elastic Compute Service (ECS) instances and the parameters that are described in the following table are created.

Parameter Key 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.

Note When you create parameters to be referenced in a template, you must select the region where you want to create a stack by using the template. For example, if you want to use a template to create a stack in the China (Hangzhou) region, you must select the China (Hangzhou) region when you create the parameters to be referenced in the template.

Step 1: Create parameters in the OOS console

  1. Log on to the OOS console.
  2. In the left-side navigation pane, click Parameter Store.
  3. In the upper-left corner of the page, select the region where you want to create parameters from the drop-down list.
    The region that you select for the parameters must be the same as the region in which to create the stack. In this example, select the China (Hangzhou) region.
  4. Create the ImageId common parameter.
    1. On the Parameter Store page, click the Common Parameters tab and then click Create Common Parameter.
    2. On the Create Common Parameter page, set Parameter Name, Value, and Parameter Type.
      In this example, set the parameters to the following values:
      • Parameter Name: my_image
      • Parameter Type: String
      • Value: centos_7_9_x64_20G_alibase_2020****.vhd
    3. Click Create.
      After the parameter is created, you can click the name of the ImageId parameter on the Common Parameters tab to view the parameter details. On the Description tab, you can view the parameter details such as the name, version, type, and value.
  5. Create the SecurityGroupIds common parameter.
    1. On the Parameter Store page, click the Common Parameters tab and then click Create Common Parameter.
    2. On the Create Common Parameter page, set Parameter Name, Value, and Parameter Type.
      In this example, set the parameters to the following values:
      • Parameter Name: security_group_ids
      • Parameter Type: StringList
      • Value: sg-group1,sg-group2
    3. Click Create.
      After the parameter is created, you can click the name of the SecurityGroupIds parameter on the Common Parameters tab to view the parameter details. On the Description tab, you can view the parameter details such as the name, version, type, and value.
  6. Create the Password encryption parameter.
    1. On the Parameter Store page, click the Encryption Parameters tab and then click Create Encryption Parameter.
    2. On the Create Encryption Parameter page, set Parameter Name, Value, and KMS Key ID.
      In this example, set the parameters to the following values:
      • Parameter Name: Password
      • KMS Key ID: Default Service CMK
      • Value: MyPassword1
    3. Click Create.
      After the parameter is created, you can click the name of the Password parameter on the Encryption Parameters tab to view the parameter details. On the Description tab, you can click Show next to Value to view the value of the Password parameter.

Step 2: Write an ROS template

After the parameters are created, write an ROS template and reference the parameters in the Parameters or Resources section of the template.

  • Reference the parameters in the Parameters section

    For a common parameter, the Type property must be set to ALIYUN::OOS::Parameter::Value. For an encryption parameter, the Type property must be set to ALIYUN::OOS::SecretParameter::Value.

    The following code provides an example on how to reference the ImageId parameter value of the latest version:

    "Parameters": {
      "ImageId":{
        "Type":"ALIYUN::OOS::Parameter::Value",
        "Default": "my_image"
      }
    }

    To reference the value of version 1, set the parameter to my_image:1.

  • Reference the parameters in the Resources section

    You can reference the parameters in the Properties section of a resource. Format: {{resolve:<Parameter type>:<Parameter key>:<Parameter version>}}.

    • (Required) Parameter type

      The category of the parameter. Valid values:

      • oos: common parameter
      • oos-secret: encryption parameter
    • (Required) Parameter key

      The key of the parameter.

    • (Optional) Parameter version

      The version of the parameter. If you do not specify the parameter version, the latest version is used.

    The following code provides an example on how to reference the ImageId parameter value of the latest version and the Password parameter value of version 2:

    "Resources": {
      "ECS": {
        "Type": "ALIYUN::ECS::Instance",
        "Properties": {
          "ImageId": "{{resolve:oos:my_image}}",
          "Password": "{{resolve:oos-secret:Password:2}}",
          ...
        }
      }
    }

Most functions are available when parameters are referenced in templates. For more information, see Functions. Unavailable functions include Ref, Fn::GetAtt, Fn::GetStackOutput, and Fn::Calculate.

In this example, the following template is created:

{
  "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",
          "InstanceIds"
        ]
      }
    }
  }
}

The parameters that are referenced by ROS templates are converted based on OOS parameter types. OOS parameters can be of the String or StringList type. If parameters of the StringList type are referenced in ROS templates, ROS converts the parameters from the StringList type to the List type for the templates. For example, when you use the SecurityGroupIds parameter whose type is StringList and whose value is sg-group1,sg-group2 to create a resource of the ALIYUN::ECS::InstanceGroup type, the value of the SecurityGroupIds parameter is converted to ["sg-group1", "sg-group2"].

Step 3: Create a stack in the ROS console

In the ROS console, use the template that you created in Step 2 to create a stack. In this example, the template is used to create a group of ECS instances. For more information, see Create a stack.

After the stack is created, you can perform the following operations to check whether the parameters are correctly referenced in the template: In the left-side navigation pane of the ROS console, click Stacks. On the Stacks page, find the stack and click the stack name. On the page that appears, click the Parameters tab to view the parameters and corresponding values.