すべてのプロダクト
Search
ドキュメントセンター

Resource Orchestration Service:出力

最終更新日:Jan 24, 2025

Outputs セクションでは、GetStack 操作が呼び出されたときに Resource Orchestration Service (ROS) が返す値を定義できます。たとえば、Elastic Compute Service (ECS) インスタンス ID を出力として定義すると、GetStack 操作が呼び出されたときに ECS インスタンス ID が返されます。

構文

出力の宣言には、出力名と出力の説明が含まれます。各出力には、配列で返される複数の値を含めることができます。Outputs セクションの構文の例を、次のサンプルコードに示します。

Outputs:
  Name of Output 1:
    Description: the description of the output.
    Condition: the condition that determines whether to return a specific resource property.
    Value: the expression of the output value.
    Label: the alias of the output.
  Name of Output 2:
    Description: the description of the output.
    Condition: the condition that determines whether to return a specific resource property.
    Value:
      - Expression 1 of the output value.
      - Expression 2 of the output value.
      - ...
    Label: the alias of the output.
  • Name: 出力の名前。出力名は出力を識別し、テンプレート内で一意である必要があります。

  • Description: 出力の説明。このフィールドは省略可能です。

  • Value: GetStack 操作が呼び出されたときにリソースプロパティに対して返される値。このフィールドは必須です。

  • Condition: リソースを作成してその情報を返すかどうかを指定する条件。指定された条件が true の場合にのみ、リソースが作成され、その情報が返されます。このフィールドは省略可能です。

  • Label: 出力のエイリアス。このフィールドは省略可能です。

  • NoEcho: 返されるパラメーター値をマスクするかどうかを指定します。true に設定すると、ROS はパラメーター値をアスタリスク (*) でマスクして返します。このフィールドは省略可能です。

  • Console.Url: スタックの詳細ページの [スタック情報] タブに表示されるコンソール URL。このフィールドは省略可能です。

説明

出力の値には、関数や、数値、文字列、辞書、リストなどのリテラルを定義できます。また、値を参照するために Ref を定義したり、リソースプロパティ値をクエリするために Fn::GetAtt を定義したりすることもできます。

次の例では、2 つの出力が使用されています。最初の出力の ID は WebServer の InstanceId プロパティです。2 番目の出力の ID は WebServer の PublicIp プロパティと PrivateIp プロパティです。

Outputs:
  InstanceId:
    Value:
      Fn::GetAtt:
        - WebServer
        - InstanceId
  PublicIp & PrivateIp:
    Value:
      - Fn::GetAtt:
          - WebServer
          - PublicIp
      - Fn::GetAtt:
          - WebServer
          - PrivateIp

次の例では、MaxAmount で指定された条件が true の場合にのみ WebServer が作成されます。

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  MaxAmount:
    Type: Number
    Default: 1
Conditions:
  CreateWebServer:
    Fn::Not:
      Fn::Equals:
        - 0
        - Ref: MaxAmount
Resources:
  WebServer:
    Type: ALIYUN::ECS::InstanceGroup
    Condition: CreateWebServer
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small
      MaxAmount:
        Ref: MaxAmount
Outputs:
  WebServerIP:
    Condition: CreateWebServer
    Value:
      Fn::GetAtt:
        - WebServer
        - PublicIps

次の例では、リスト、辞書、関数、定数などの複数のタイプの出力値が返されます。サービスコンソールの URL を指定する Console.Url が出力として使用されます。

ROSTemplateFormatVersion: '2015-09-01'
Metadata: {}
Parameters:
  DictObjectParameter:
    Default:
      k2: v2
      k1: v1
    Type: Json
  NumberParameter:
    Default: 3.14
    Type: Number
  StringParameter:
    Default: ecs.c1.large
    Type: String
  ArrayListParameter:
    Default:
      - xiaomi
      - xiaofeng
      - xiaoliang
    Type: Json
  EcsInstancePublicIp:
    Default: 1.1.X.X
    Type: String
Resources: {}
Outputs:
  Console.Url:
    Description: Console Url Demo Value
    Value:
      Fn::Sub:
        - http://${EcsPublicIp}/elasticsearch-demo
        - EcsPublicIp:
            Ref: EcsInstancePublicIp
  ArrayList:
    Description: ArrayList Output Value
    Value:
      Ref: ArrayListParameter
  DictObject:
    Description: DictObject Output Value
    Value:
      Ref: DictObjectParameter
  Number:
    Description: Number Output Value
    Value:
      Ref: NumberParameter
  String:
    Description: String Output Value
    Value:
      Ref: StringParameter

次の例では、カンマ (,) で区切られた複数の Web サーバー URL を返すように出力値が定義されています。

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  WebServerAddress:
    Type: String
    Default: 192.168.1.1
    Label:
       
      en: WebServerAddress
Outputs:
  WebServerAddress:
    Description:
       
      en: Web Server url.
    Value:
      Fn::Sub:
        - http://${WebServerAddress}:80,http://${WebServerAddress}:8080,http://${WebServerAddress}:8881
        - WebServerAddress:
            Ref: WebServerAddress