全部产品
Search
文档中心

资源编排:伪参数(Pseudo parameters)

更新时间:May 29, 2024

伪参数是资源编排服务ROS的编排引擎提供的固定参数。它们可以和用户定义的参数一样被引用,其值在ROS运行时被确定。

伪参数

ROS为您提供了以下伪参数:

  • ALIYUN::StackName:资源栈名称。

  • ALIYUN::StackId:资源栈ID。

  • ALIYUN::Region:资源栈所在地域。

  • ALIYUN::AccountId:执行者账号ID。

  • ALIYUN::TenantId:当前账号的阿里云账号ID。

  • ALIYUN::ResourceGroupId:资源栈所属资源组。

  • ALIYUN::NoValue:创建或更新资源栈时,如果ALIYUN::NoValue用于可选属性,则将删除该属性;如果ALIYUN::NoValue用于必选属性,则将按类型获取默认值(例如,用于String类型的属性值为空字符串;用于Integer类型的属性值为0;用于数组类型属性值为空数组等)。

  • ALIYUN::Index:一个特殊的伪参数,仅在资源Count功能中使用,其他情况不能使用。Count详情,请参见Count

示例

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  EnvType:
    Default: pre
    Type: String
Conditions:
  CreateDisk:
    Fn::Equals:
    - prod
    - Ref: EnvType
Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      DiskMappings:
        Fn::If:
        - CreateDisk
        - - Category: cloud_efficiency
            DiskName: FirstDataDiskName
            Size: 40
          - Category: cloud_ssd
            DiskName: SecondDataDiskName
            Size: 40
        - Ref: ALIYUN::NoValue
      VpcId: vpc-m5eebunc50zfbmts7****
      SystemDiskCategory: cloud_efficiency
      SecurityGroupId: sg-m5eagh7rzys2z8sa****
      SystemDiskSize: 40
      ImageId: cent****
      IoOptimized: optimized
      VSwitchId: vsw-m5eem62p9729y6gps****
      InstanceType: ecs.c5.large
Outputs:
  StackName:
    Value:
      Ref: ALIYUN::StackName
  StackId:
    Value:
      Ref: ALIYUN::StackId
  Region:
    Value:
      Ref: ALIYUN::Region
  UserID:
    Value:
      Ref: ALIYUN::AccountId

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "EnvType": {
      "Default": "pre",
      "Type": "String"
    }
  },
  "Conditions": {
    "CreateDisk": {
      "Fn::Equals": [
        "prod",
        {
          "Ref": "EnvType"
        }
      ]
    }
  },
  "Resources": {
    "WebServer": {
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "DiskMappings": {
          "Fn::If": [
            "CreateDisk",
            [
              {
                "Category": "cloud_efficiency",
                "DiskName": "FirstDataDiskName",
                "Size": 40
              },
              {
                "Category": "cloud_ssd",
                "DiskName": "SecondDataDiskName",
                "Size": 40
              }
            ],
            {
              "Ref": "ALIYUN::NoValue"
            }
          ]
        },
        "VpcId": "vpc-m5eebunc50zfbmts7****",
        "SystemDiskCategory": "cloud_efficiency",
        "SecurityGroupId": "sg-m5eagh7rzys2z8sa****",
        "SystemDiskSize": 40,
        "ImageId": "cent****",
        "IoOptimized": "optimized",
        "VSwitchId": "vsw-m5eem62p9729y6gps****",
        "InstanceType": "ecs.c5.large"
      }
    }
  },
  "Outputs": {
    "StackName": {
      "Value": {
        "Ref": "ALIYUN::StackName"
      }
    },
    "StackId": {
      "Value": {
        "Ref": "ALIYUN::StackId"
      }
    },
    "Region": {
      "Value": {
        "Ref": "ALIYUN::Region"
      }
    },
    "UserID": {
      "Value": {
        "Ref": "ALIYUN::AccountId"
      }
    }
  }
}