Parameters

更新时间:
复制 MD 格式

The Parameters section of a template defines input values that users specify at stack creation time, making templates flexible and reusable.

Syntax

Each parameter has a name and a set of properties. Parameter names can contain only letters and digits and must be unique within a template. Use the Label property to define an alias.

The following table describes the supported properties.

Property

Required

Description

Type

Yes

The parameter data type. Valid values:

  • String: a string. Example: "ecs.s1.medium".

  • Number: an integer or a floating-point number. Example: 3.14.

  • CommaDelimitedList: a comma-separated list of values. Use Fn::Select to retrieve values by index. Example: "80, foo, bar".

  • Json: a JSON string. Example: {"foo": "bar"} or [1, 2, 3].

  • Boolean: a boolean value. Example: true or false.

  • ALIYUN::OOS::Parameter::Value: a common parameter that is stored in Parameter Store of CloudOps Orchestration Service (OOS). For more information, see Manage common parameters. Example: my_image.

  • ALIYUN::OOS::SecretParameter::Value: an encrypted parameter stored in OOS Parameter Store (Encryption parameters). Example: my_password.

Note

AllowedPattern does not support the ALIYUN::OOS::Parameter::Value and ALIYUN::OOS::SecretParameter::Value types.

Default

No

The default value of a parameter. If no value is specified at stack creation, ROS uses this default. If no default is defined, an error is reported.

Note

If the default is set to null, the parameter is treated as empty and validation is skipped.

AllowedValues

No

The valid values of a parameter.

AllowedPattern

No

A regular expression for validating String-type parameters. Applying this property to non-String parameters causes an error.

Prepend two backslashes (\\) before each of the following special characters:

*.?+-$^[ ]( ){ }|\/
Note

A hyphen (-) used as the first or last character in a range does not need escaping. Example: [a-z-].

MaxLength

No

Maximum number of characters allowed for a String-type parameter.

MinLength

No

Minimum number of characters required for a String-type parameter.

MaxValue

No

Maximum numeric value allowed for a Number-type parameter.

MinValue

No

Minimum numeric value allowed for a Number-type parameter.

NoEcho

No

When set to true, ROS masks the parameter value with asterisks (*) in stack creation and stack detail views.

Confirm

No

Requires the parameter value to be entered twice when NoEcho is set to true. Default value: false.

Note

The Confirm property can be set to true only for String-type parameters whose NoEcho property is true.

Description

The description of a parameter. Supports localized values:

  • zh-cn: Chinese description.

  • en: English description.

Note

The console displays the description that matches the current language setting.

ConstraintDescription

No

The error message displayed when a parameter constraint is violated.

Label

No

A UTF-8 encoded alias for the parameter. In template-based web forms, Label values map to parameter names.

AssociationProperty

No

Automatically validates parameter values and provides a list of valid options.

For more information about the AssociationProperty values supported by ROS and the examples, see AssociationProperty and AssociationPropertyMetadata.

AssociationPropertyMetadata

No

A map that constrains AssociationProperty and filters matched items.

This property is of the Map type. For more information about the correspondence between AssociationProperty and AssociationPropertyMetadata and the examples, see AssociationProperty and AssociationPropertyMetadata.

TextArea

No

Whether the parameter supports line breaks. Valid values:

  • true

  • false (default)

In the following example, the Content parameter supports line breaks:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Content:
    Type: String
    TextArea: true
Outputs:
  TestContent:
    Value:
      Ref: Content

Required

No

Whether the parameter is required. Valid values:

  • true: The parameter is required.

  • false: The parameter is optional.

In the following example, the ECSInstanceId parameter is required.

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  CreateNewECS:
    Type: Boolean
    Label: Whether to Create New Instance
    Default: false
  ECSInstanceId:
    Type: String
    Required: true  # Use Required to specify whether the parameter is required (frontend effect).
    Default: Null
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateNewECS}
            - false
Note

The Required property affects only the frontend display and does not enforce backend validation.

Placeholder

No

A hint displayed in the input field for a parameter.

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Placeholder:
    Type: String
    Placeholder:
      en: Placeholder

Example: Define the InstanceType parameter

Suppose you create a stack for a web application that contains one SLB instance, two ECS instances, and one ApsaraDB RDS instance. You can choose different ECS instance types based on workload requirements. The following code defines the InstanceType parameter in a template:

Parameters:
  InstanceType:
    Type: String
    AllowedValues:
      - ecs.t1.small
      - ecs.s1.medium
      - ecs.m1.medium
      - ecs.c1.large
    Default: ecs.t1.small
    Label: ECS Instance Type
    Description: Select an instance type. Default value: ecs.t1.small. Valid values: ecs.t1.small, ecs.s1.medium, ecs.m1.medium, and ecs.c1.large.

With this definition, you can select a different InstanceType value each time you create a stack. If the InstanceType parameter is omitted, the default ecs.t1.small is used.

The following code references the InstanceType parameter in a resource definition:

Webserver:
  Type: ALIYUN::ECS::Instance
  InstanceType:
    Ref: InstanceType