When you create a template, you can add the Parameters section to improve the flexibility and reusability of the template. You can replace specific parameter values based on your business requirements when you use the template to create a stack.
Syntax
Each parameter consists of a parameter name and properties. A parameter name can contain only letters and digits and must be unique in the same template. You can use the Label property to define the alias of a parameter.
The following table describes the properties that are supported in the Parameters section.
Property | Required | Description |
Type | Yes | The data type of a parameter. Valid values:
Note You cannot use AllowedPattern to verify parameters of the |
Default | No | The default value of a parameter. If you do not specify a value for a template parameter when you create a stack, Resource Orchestration Service (ROS) checks whether a default value is defined for the parameter in the template. If a default value is defined in the template, ROS uses the default value. Otherwise, an error is reported. Note You can set the default value of a parameter in the template to |
AllowedValues | No | The valid values of a parameter. |
AllowedPattern | No | A regular expression that represents the allowed pattern for the specified String-type parameters. If you do not specify a String-type parameter, an error is reported. If you use one or more of the following special characters, add two backslashes (\\) as an escape character before each special character:
Note You do not need to add an escape character before a hyphen (-) that is used as the first or last special character in a value range. Example: [a-z-]. |
MaxLength | No | An integer value that specifies the largest number of characters allowed for a String-type parameter. |
MinLength | No | An integer value that specifies the smallest number of characters allowed for a String-type parameter. |
MaxValue | No | A numeric value that specifies the largest numeric value allowed for a Number-type parameter. |
MinValue | No | A numeric value that specifies the smallest numeric value allowed for a Number-type parameter. |
NoEcho | No | If you set the NoEcho property of a parameter to |
Confirm | No | Specifies whether to enter the value of a parameter for a second time if the NoEcho property of the parameter is set to Note You can set the Confirm property to |
Description | A string that describes a parameter. Valid values:
Note The description of the specified language is displayed only based on the language in the console. | |
ConstraintDescription | No | A string that explains the constraint of a parameter when the constraint is violated. |
Label | No | The alias of a parameter. The alias is encoded in UTF-8. When web forms are generated based on templates, the value of |
AssociationProperty | No | A property of Parameters. This property is used to automatically verify the validity of values of a parameter and provide a set of valid values for the parameter. For more information about the AssociationProperty values supported by ROS and the examples, see AssociationProperty and AssociationPropertyMetadata. |
AssociationPropertyMetadata | No | A metadata map that specifies the constraint of AssociationProperty and is used to filter 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 | Specifies whether a parameter supports line breaks. Valid values:
In the following example, the Content parameter supports line breaks:
|
Required | No | Specifies whether a parameter is required. Valid values:
In the following example, the ECSInstanceId parameter is required.
Note The Required property affects only the display effect of the parameter on the front end but does not affect the verification for the parameter. |
Placeholder | No | The custom hint displayed in a field for a parameter.
|
Example: Create a stack to create a web application
For example, you want to create a stack to create a web application. The stack contains one Server Load Balancer (SLB) instance, two Elastic Compute Service (ECS) instances, and one ApsaraDB RDS instance. If the web application is under heavy workloads, you can use ECS instances of advanced instance types when you create the stack. If the web application is under regular workloads, you can use ECS instances of basic instance types when you create the stack. The following sample code provides an example on how to define properties for 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.
If you use the preceding sample code to define properties for the InstanceType parameter, you can select a different value from a set of valid values for the InstanceType parameter each time you create a stack based on the template. If you leave the InstanceType parameter empty, the default value ecs.t1.small
is used.
The following sample code provides an example on how to reference the InstanceType parameter when you define a resource:
Webserver:
Type: ALIYUN::ECS::Instance
InstanceType:
Ref: InstanceType