Parameters

Last Updated: May 16, 2018

Using parameters in templates can improve the flexibility and reusability of the templates. When creating a resource stack, template users can overwrite the parameters in a template to create a resource which meets their business requirements.

For example, a web application requires a resource stack, containing one Server Load Balancer instance, two ECS instances, and one ApsaraDB for RDS instance. If the web application has a higher load, an ECS with higher configuration can be selected during the stack creation. Otherwise, a lower configuration ECS can be selected. In this case, you can define the instance type in the template as the following:

  1. "Parameters" : {
  2. "InstanceType" : {
  3. "Type" : "String",
  4. "AllowedValues":["ecs.t1.small","ecs.s1.medium", "ecs.m1.medium", "ecs.c1.large"],
  5. "Default": "ecs.t1.small",
  6. "Label": "ECS instance type".
  7. "Description": "The ECS instance type options. The default value is ecs.t1.small. Optional values are ecs.t1.small, ecs.s1.medium, ecs.m1.medium, and ecs.c1.large."
  8. }
  9. }

For the InstanceType parameter defined, you can reassign a value to it when using the template to create a resource stack. If you do not set any parameter value, the default value ecs.t1.small is used.

This parameter can be referenced as the following when the resource is defined:

  1. "Webserver" : {
  2. "Type" : "ALIYUN::ECS::Instance",
  3. "InstanceType": {
  4. "Ref": "InstanceType"
  5. }
  6. }

Syntax

Each parameter consists of the parameter name and attributes.

The parameter name must consist of letters and numbers and be unique in the same template. The Label field can be used to define a parameter name.

Parameter attribute list is as follows.

Attribute Required Description
Type Yes

Data type of the parameter.

String

String. For example: "ecs.s1.medium".

Number

Integer or floating point number. For example: 3.14.

CommaDelimitedList

A group of strings or numbers separated by commas, whose values can be indexed by using the Fn::Select function. For example: "80, foo, bar".

Json

A string in the JSON format. For example: { "foo": "bar" }.

Boolean

A Boolean value. For example: true or false.

Default No When creating a resource stack, if you do not specify the value, the ROS system checks whether a default value is defined in the template. If yes, the default value is used. Otherwise, the system reports an error.
AllowedValues No A list containing the allowed values of parameters.
AllowedPattern No A regular expression, used to check whether an entered parameter matches the string type. If the entered is not a string type, the system reports an error.
MaxLength No An integer, used to determine the maximum number of characters allowed for String.
MinLength No An integer, used to determine the minimum number of characters allowed for String.
MaxValue No A numeric value, used to determine the maximum numeric value allowed for Number.
MinValue No A numeric value, used to determine the minimum numeric value allowed for Number.
NoEcho No Defines whether a parameter value is outputted when a stack is queried. If the value is set to true, only asterisks (**) are outputted.
Description No A string, used to describe the parameter.
ConstraintDescription No A string, used to describe a constraint of a parameter when the constraint is violated.
Label No Parameter alias, supporting UTF-8 encoded characters. It can be mapped as label when a web form is generated through the template.
AssociationProperty No
You can use the parameter AssociationProperty to automatically verify the parameter validity and provide options for the parameter.
Format: “ROS resource type:property” (without spaces).
For example: specify "ALIYUN::ECS::Instance:ImageId", indicating this parameter is referenced by the attribute ImageId of ALIYUN::ECS::Instance. Then, the ROS console checks whether the image ID specified for this parameter is available and lists other options in the drop-down box.
Currently ROS only supports the verification of the image ID parameter.

Example

The following example defines two parameters.

The parameter username is of String type, and the default value is "anonymous". The minimum and maximum length that can be specified is 6 characters and 12 characters respectively, and the allowed values are anonymous, user-one, and user-two.

Note: The default value of username must comply with the length restriction and allowed value restriction.

The password parameter is of String type, without any default value. Setting the NoEcho attribute to true prevents the stack query interface from returning the parameter value. The minimum and maximum length that can be specified is one character, and 41 characters respectively. This mode supports lowercase and uppercase letters, and numbers.

  1. "Parameters" : {
  2. "username" : {
  3. "Label": "User name".
  4. "Description": "Enter the user name".
  5. "Default": "anonymous",
  6. "Type" : "String",
  7. "MinLength" : "6",
  8. "MaxLength" : "12",
  9. "AllowedValues": ["anonymous", "user-one", "user-two"]
  10. },
  11. "password" : {
  12. "Label": "Password".
  13. "NoEcho" : "True",
  14. "Description": "Enter the user password".
  15. "Type" : "String",
  16. "MinLength" : "1",
  17. "MaxLength" : "41",
  18. "AllowedPattern" : "[a-zA-Z0-9]*"
  19. }
  20. }

Pseudo parameters

Pseudo parameters are fixed parameters provided by the ROS orchestration engine. They can be referenced like custom parameters, and the values are determined during the orchestration operation. Currently, the following pseudo parameters are supported:

  • ALIYUN::StackName: the name of the current resource stack.
  • ALIYUN::StackId: the ID of the current resource stack.
  • ALIYUN::Region: the region where the current resource stack is in.
  • ALIYUN::AccountId: the user ID of the current resource stack.
  • ALIYUN::NoValue: the attribute that is deleted when the resource is created or updated.
Thank you! We've received your feedback.