別のパラメーターの値に基づいて、テンプレートのパラメーターを条件付きで表示または非表示にできます。たとえば、課金方法がサブスクリプションの場合にのみ、期間単位とサブスクリプション期間を表示できます。
テンプレート構文
別のパラメーターの値に基づいて表示/非表示を制御するには、パラメーターに AssociationProperty と AssociationPropertyMetadata を指定します。AssociationPropertyMetadata では、関数を使用してパラメーターを表示するかどうかを判定する Visible フィールドを定義します。構文は次のとおりです:
Visible:
Condition: Object # このパラメーターを表示するための条件。
Condition フィールドは、次の関数に対応しています:
テンプレート例
この例では、AssociationProperty を targetInstanceChargeType パラメーターに設定し、これを課金方法の制御パラメーターとします。続いて、依存パラメーターに AssociationPropertyMetadata を使用して、表示条件を定義します。これにより、スタックの作成時に動的なパラメーターのフィルタリングが可能になります。
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 単一 ECS インスタンスをカスタムイメージから作成するためのテンプレート例です。新しいベースリソース (VPC、VSwitch、セキュリティグループ) を作成するか、既存のリソースを使用することができます。ECS インスタンスの課金方法として、サブスクリプションと従量課金の両方に対応しています。
en: An example template for creating a single ECS instance from a custom image. You can either create new base resources (VPC, VSwitch, security group) or use existing ones. Supports both subscription and pay-as-you-go billing methods for the ECS instance.
Parameters:
targetInstanceChargeType:
Description:
name-en: targetInstanceChargeType
name-zh-cn: 課金方法
Type: String
AssociationProperty: ChargeType
targetPeriodUnit:
Description:
name-en: The unit of the subscription period
name-zh-cn: サブスクリプションの期間単位
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
name-zh-cn: サブスクリプション期間
en: 'Valid values: 1, 2, 3, and 4 if PeriodUnit is Week. 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36, 48, and 60 if PeriodUnit is Month.'
zh-cn: '有効値:PeriodUnit が Week の場合:1、2、3、4。PeriodUnit が Month の場合:1、2、3、4、5、6、7、8、9、12、24、36、48、60。'
Type: Number
Default: 1
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${targetInstanceChargeType}
- PostPaid
パラメーター:
targetInstanceChargeType:課金方法。AssociationPropertyがChargeTypeに設定されているため、他のパラメーターの表示/非表示は、このパラメーターの値に依存します。targetPeriodUnit:期間単位。AssociationPropertyMetadataは{"Visible": {"Condition": {"Fn::Not": {"Fn::Equals": ["${targetInstanceChargeType}","PostPaid"]}}}}に設定されています。この条件により、targetInstanceChargeTypeがPostPaidに設定されていない場合にのみ、targetPeriodUnitパラメーターが表示されます。説明targetInstanceChargeTypeパラメーターは、課金方法がサブスクリプションの場合は PrePaid を、従量課金の場合は PostPaid を値として取ります。targetPeriod:サブスクリプション期間。AssociationPropertyMetadata{"Visible": {"Condition": {"Fn::Not": {"Fn::Equals": ["${targetInstanceChargeType}","PostPaid"]}}}}は に設定されています。この条件により、targetInstanceChargeTypeがPostPaidに設定されていない場合にのみ、targetPeriodパラメーターが表示されます。
コンソールでの設定
このテンプレートからサブスクリプションの課金方法でスタックを作成すると、ROS コンソールには次の依存パラメーターが表示されます: [PeriodUnit] ([Week] または [Month] を選択できます) および [Subscription period]。[PeriodUnit] が [Week] に設定されている場合、サブスクリプション期間の有効な値は 1、2、3、4 です。[PeriodUnit] が [Month] に設定されている場合、有効な値は 1、2、3、4、5、6、7、8、9、12、24、36、48、60 です。