Best practices for common parameters

更新时间:
复制 MD 格式

If multiple template executions use the same parameter values, you can use the parameter store feature of CloudOps Orchestration Service (OOS) to assign values to named parameters. When you create an execution, you need to only select a parameter from the parameter store — no repeated searches required. Common parameters let you reference the latest Alibaba Cloud resource values, such as ECS image IDs, directly in your templates without hardcoding values that change over time.

Use common parameters in OOS templates

OOS provides a set of common parameters managed by Alibaba Cloud. Unlike custom parameters you define yourself, common parameters are always kept up to date — for example, they always point to the latest OS images available for Elastic Compute Service (ECS) instances.

image.png

Without common parameters, every time you create an ECS instance you must look up the current image ID (such as centos_8_5_x64_20G_alibase_20220428.vhd) and paste it into your template manually. When a newer image is released, the ID changes and your template becomes stale.

With common parameters, you reference a stable parameter name instead. Alibaba Cloud resolves it to the current value at execution time.

Approach 1: Declare as a template parameter

Declare the common parameter as a template parameter, then reference it by name inside the task. When you create an execution in the OOS console, select the common parameter from the parameter picker — no manual image ID entry required.

The following template uses latestCentos8ImageId to hold the common parameter name aliyun/services/ecs/images/linux/almalinux-latest/almalinux_9_2_x64. OOS resolves this to the latest AlmaLinux 9.2 image at run time.

Description: Example template, run instance
FormatVersion: OOS-2019-06-01
Parameters:
  latestCentos8ImageId:
    Type: String
  regionId:
    Type: String
    Label:
      en: RegionId
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceType:
    Label:
      en: InstanceType
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      RegionId: regionId
  securityGroupId:
    Label:
      en: SecurityGroupId
    Type: String
    AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
    AssociationPropertyMetadata:
      RegionId: regionId
  vSwitchId:
    Label:
      en: VSwitchId
    Type: String
    AssociationProperty: ALIYUN::VPC::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      RegionId: regionId
      Filters:
        - SecurityGroupId: securityGroupId
Tasks:
  - Name: runInstances
    Action: ACS::ECS::RunInstances
    Description:
      en: Creates one or more ECS instances.
    Properties:
      imageId: '{{ latestCentOS8ImageId }}'
      instanceType: '{{ instanceType }}'
      securityGroupId: '{{ securityGroupId }}'
      vSwitchId: '{{ vSwitchId }}'
      amount: 1
    Outputs:
      instanceId:
        ValueSelector: instanceIds[0]
        Type: String

When creating an execution, enter the common parameter value in the latestCentos8ImageId field using the format {{oos:Common parameter name}} — for example:

{{oos:aliyun/services/ecs/images/linux/almalinux-latest/almalinux_9_2_x64}}

Or click the Select Parameter icon next to the field and choose the parameter from the list.

截屏2023-05-12 11.48.30.png

Approach 2: Inline reference in the task

Embed the common parameter directly in the task properties using the {{oos:Common parameter name}} syntax. This removes the need for a separate template parameter declaration.

Description: Example template, run instance
FormatVersion: OOS-2019-06-01
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceType:
    Label:
      en: InstanceType
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      RegionId: regionId
  securityGroupId:
    Label:
      en: SecurityGroupId
    Type: String
    AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
    AssociationPropertyMetadata:
      RegionId: regionId
  vSwitchId:
    Label:
      en: VSwitchId
    Type: String
    AssociationProperty: ALIYUN::VPC::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      RegionId: regionId
      Filters:
        - SecurityGroupId: securityGroupId
Tasks:
  - Name: runInstances
    Action: ACS::ECS::RunInstances
    Description:
      en: Creates one or more ECS instances.
    Properties:
      imageId: '{{oos:aliyun/services/ecs/images/linux/almalinux-latest/almalinux_9_2_x64}}'
      instanceType: '{{ instanceType }}'
      securityGroupId: '{{ securityGroupId }}'
      vSwitchId: '{{ vSwitchId }}'
      amount: 1
    Outputs:
      instanceId:
        ValueSelector: instanceIds[0]
        Type: String

Which approach to use

Approach 1: template parameter

Approach 2: inline reference

How it works

Declare a parameter; fill it at execution time via the console picker

Embed {{oos:...}} directly in the task property

Best for

Letting operators select the common parameter at run time

Fixed parameters where a simpler template is preferred

Console experience

Parameter picker shown when creating an execution

No extra field; value is baked into the template

Use common parameters in ROS templates

Resource Orchestration Service (ROS) templates support two equivalent syntaxes for referencing OOS common parameters.

Approach 1: ALIYUN::OOS::Parameter::Value type

Declare the parameter with type ALIYUN::OOS::Parameter::Value and set its default to the common parameter name. ROS resolves the value when the stack is created.

The following template sets ImageId to aliyun/services/ecs/centos-latest/centos_8_5_64, which always resolves to the latest CentOS 8 image.

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  InstanceType:
    Type: String
    Default: ECS.c6.large
  ImageId:
    Type: 'ALIYUN::OOS::Parameter::Value'
    Default: aliyun/services/ecs/centos-latest/centos_8_5_64
  SecurityGroupId:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
    AssociationPropertyMetadata:
      VpcId: '${VpcId}'
  VpcId:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::VPC::VPCId'
    AssociationPropertyMetadata:
      RegionId: '${RegionId}'
Resources:
  ECS:
    Type: 'ALIYUN::ECS::InstanceGroup'
    Properties:
      ImageId:
        Ref: ImageId
      InstanceType:
        Ref: InstanceType
      MaxAmount: 1
      SecurityGroupId:
        Ref: SecurityGroupId
      VpcId:
        Ref: VpcId
      NetworkType: vpc
Outputs:
  InstanceIds:
    Value:
      'Fn::GetAtt':
        - ECS
        - InstanceIds

In the ROS console, enter the common parameter name in the ImageId field when creating the stack.

截屏2023-05-12 14.01.27.png

Approach 2: Inline resolve in the Resources section

Reference the common parameter inline inside the Resources section using the {{resolve:oos:Common parameter name}} syntax. This keeps the parameter declaration out of the Parameters section entirely.

The following template resolves aliyun/services/ecs/centos-latest/centos_8_5_64 directly in the ImageId property:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  InstanceType:
    Type: String
    Default: ECS.c6.large
  SecurityGroupId:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
    AssociationPropertyMetadata:
      VpcId: '${VpcId}'
  VpcId:
    Type: String
    AssociationProperty: 'ALIYUN::ECS::VPC::VPCId'
    AssociationPropertyMetadata:
      RegionId: '${RegionId}'
Resources:
  ECS:
    Type: 'ALIYUN::ECS::InstanceGroup'
    Properties:
      ImageId: '{{resolve:oos:aliyun/services/ecs/centos-latest/centos_8_5_64}}'
      InstanceType:
        Ref: InstanceType
      MaxAmount: 1
      SecurityGroupId:
        Ref: SecurityGroupId
      VpcId:
        Ref: VpcId
      NetworkType: vpc
Outputs:
  InstanceIds:
    Value:
      'Fn::GetAtt':
        - ECS
        - InstanceIds