When you create templates, you may want to associate a parameter with a different set of parameters. If you have a parameter with multiple values, you may want to configure a different set of parameters based on the value that you specify for the parameter. This topic describes how to display a different set of parameters based on the value of a parameter. In this example, the targetPeriodUnit and targetPeriod parameters are displayed based on the value of the targetInstanceChargeType parameter.

Template syntax

You can specify the AssociationProperty and AssociationPropertyMetadata parameters in the Parameters section of a template so that a different set of parameters are displayed based on the value that you specify for a parameter. In this example, the value of the targetInstanceChargeType parameter is specified. For AssociationPropertyMetadata, you must specify functions in Visible to determine whether the different set of parameters are displayed. The following sample code shows how to specify Visible:

Visible: 
  Condition: Object #The one or more conditions based on which the different set of parameters are displayed. 

The following information describes the functions that you can specify for Condition and the examples:

  • Fn::Equals: "Fn::Equals": ['${targetInstanceChargeType}', "PostPaid"].
  • Fn::Not: "Fn::Not": ${condition}.
  • Fn::And: "Fn::And": [${condition1}, ${condition2}, ...].
  • Fn::Or: "Fn::Or": [${condition1}, ${condition2}, ...].

Example

In this example, AssociationProperty is specified to obtain the billing method, and AssociationPropertyMetadata is specified to add filter conditions for a different set of parameters. This way, the ROS console can filter parameters when you create resources.

ROSTemplateFormatVersion: '2015-09-01'
Description:
  en: This template supports single-instance with custom image, including scenarios using existing or creating new VPC, VSwitch, SecurityGroup and creating ECS by prepaid or postpaid model.
Parameters:
  targetInstanceChargeType:
    Description:
      name-en: targetInstanceChargeType
    Type: String
    AssociationProperty: ChargeType
  targetPeriodUnit:
    Description:
      name-en: The unit of the subscription period
    Type: String
    AllowedValues:
      - Week
      - Month
    Default: Month
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${targetInstanceChargeType}
              - PostPaid
  targetPeriod:
    Description:
      name-en: The subscription period of the instance
      en: 'Valid values: Valid values when PeriodUnit is set to Week: 1, 2, 3, and 4. Valid values when PeriodUnit is set to Month: 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36, 48, and 60.'
    Type: Number
    AllowedValues:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      - 12
      - 24
      - 36
      - 48
      - 60
    Default: 1
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${targetInstanceChargeType}
              - PostPaid

Parameters:

  • targetInstanceChargeType: the billing method. The AssociationProperty parameter is set to ChargeType. In this case, the ROS console filters parameters based on the value of the targetInstanceChargeType parameter.
  • targetPeriodUnit: the unit of the subscription billing method. The AssociationPropertyMetadata parameter is set to {"Visible": {"Condition": {"Fn::Not": {"Fn::Equals": ["${targetInstanceChargeType}","PostPaid"]}}}}, which specifies that the targetPeriodUnit parameter is displayed if the targetInstanceChargeType parameter is not set to PostPaid.
    Note The valid values of the targetInstanceChargeType parameter are PrePaid and PostPaid.
  • targetPeriod: the duration of subscription resources that you want to purchase. The AssociationPropertyMetadata parameter is set to {"Visible": {"Condition": {"Fn::Not": {"Fn::Equals": ["${targetInstanceChargeType}","PostPaid"]}}}}, which specifies that the targetPeriod parameter is displayed if the targetInstanceChargeType parameter is not set to PostPaid.

Options in the ROS console

If you select the subscription billing method when you use the preceding template to create a stack, the ROS console displays the parameters in the following figure.

targetInstanceChargeType