全部产品
Search
文档中心

资源编排:AssociationProperty和AssociationPropertyMetadata

更新时间:Mar 16, 2026

当您使用ROS创建资源栈管理多种资源时,通常需要打开多个控制台查找资源参数信息。此时您可以在模板的参数配置中指定AssociationProperty以获取所选地域下对应的资源,指定AssociationPropertyMetadata对不同参数添加筛选条件,以便在控制台动态选择参数配置。

参数说明

AssociationPropertyMetadata参数的取值:

  • 为参数指定特定值。例如:"RegionId": "cn-hangzhou",ROS将填入特定的地域cn-hangzhou。

  • 为参数指定变量,格式为${ParameterKey}。例如:"VpcId": "${VpcId}",ROS将动态获取当前模板中参数VpcId对应的值。

    说明
    • 如果需要将${ParameterKey}指定为固定值,可以增加感叹号(!)。例如:${!Literal}表示取值为${Literal}

    • 如果要在Terraform模板中使用参数变量,需要在$前增加一个$。例如:"VpcId": "$${VpcId}",ROS将动态获取Terraform模板中VpcId对应的值。

ROS支持的AssociationProperty为不同资源时,对应的AssociationPropertyMetadata如下所示。

使用示例

示例1:AssociationProperty示例

在参数中指定AssociationProperty取值为ALIYUN::ECS::Image::ImageId,以获取所选地域下所有的镜像ID。

JSON示例:

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "UserName": {
      "Label": "用户名",
      "Description": "请输入用户名",
      "Default": "anonymous",
      "Type": "String",
      "MinLength": "6",
      "MaxLength": "12",
      "AllowedValues": [
        "anonymous",
        "user-one",
        "user-two"
      ]
    },
    "PassWord": {
      "Label": "密码",
      "NoEcho": "True",
      "Description": "请输入用户密码",
      "Type": "String",
      "MinLength": "1",
      "MaxLength": "41",
      "AllowedPattern": "[a-zA-Z0-9]*"
    },
    "ImageId": {
      "Label": "镜像",
      "Type": "String",
      "Description": "请选择镜像",
      "AssociationProperty": "ALIYUN::ECS::Image::ImageId",
      "Default": "centos_7_7_x64_20G_alibase_2020****.vhd"
    }
  }
}

YAML示例:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  UserName:
    Label: 用户名
    Description: 请输入用户名
    Default: anonymous
    Type: String
    MinLength: '6'
    MaxLength: '12'
    AllowedValues:
      - anonymous
      - user-one
      - user-two
  PassWord:
    Label: 密码
    NoEcho: 'True'
    Description: 请输入用户密码
    Type: String
    MinLength: '1'
    MaxLength: '41'
    AllowedPattern: '[a-zA-Z0-9]*'
  ImageId:
    Label: 镜像
    Type: String
    Description: 请选择镜像
    AssociationProperty: ALIYUN::ECS::Image::ImageId
    Default: centos_7_7_x64_20G_alibase_2020****.vhd

参数说明:

  • UserName:用户名。String类型,长度为6~12个字符,取值:

    • anonymous(默认值)

    • user-one

    • user-two

  • PassWord:密码。String类型,无默认值。长度为1~41个字符,支持大写英文字母、小写英文字母和数字。

    NoEcho取值为true,表示查询资源栈时将不会返回参数值。

  • ImageId:镜像ID。String类型。

    AssociationProperty取值为ALIYUN::ECS::Image::ImageId,创建资源栈时ROS控制台将会验证参数指定的镜像ID是否可用,并以下拉框的方式列出所选地域的其他镜像ID取值。

示例2:AssociationPropertyMetadata示例

在参数中指定AssociationProperty和对应的AssociationPropertyMetadata(RegionId、VpcId和ZoneId),以便获取指定专有网络和可用区的交换机。其中,RegionId取值为固定值cn-hangzhou;VpcId和ZoneId取值为变量${VpcId}和${EcsZone},将根据ALIYUN::ECS::VPC::VPCId和ZoneId选定的取值进行动态刷新,从而建立交换机与专有网络和可用区的关联关系。

说明

针对EcsZone这类配置了AllowedValues的参数,通过在AssociationPropertyMetadata中加入AutoChangeType并配置取值为false从而实现在资源编排控制台页面对AllowedValues参数的配置信息展示为下拉列表样式。

JSON示例:

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "VpcId": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId"
    },
    "EcsZone": {
      "Type": "String",
      "AllowedValues": [
        "cn-hangzhou-i",
        "cn-hangzhou-j",
        "cn-hangzhou-k",
        "cn-hangzhou-h"
      ],
      "AssociationPropertyMetadata": {
        "AutoChangeType": false
      }
    },
    "VSwitchId": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::VPC::VSwitch::VSwitchId",
      "AssociationPropertyMetadata": {
        "RegionId": "cn-hangzhou",
        "VpcId": "${VpcId}",
        "ZoneId": "${EcsZone}"
      }
    }
  }
}

YAML示例:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcId:
    Type: String
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
  EcsZone:
    Type: String
    AllowedValues:
      - cn-hangzhou-i
      - cn-hangzhou-j
      - cn-hangzhou-k
      - cn-hangzhou-h
    AssociationPropertyMetadata:
      AutoChangeType: false
  VSwitchId:
    Type: String
    AssociationProperty: ALIYUN::VPC::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      RegionId: cn-hangzhou
      VpcId: ${VpcId}
      ZoneId: ${EcsZone}

示例3:Terraform自动转换示例

当AssociationProperty取值为Auto时,ROS会基于Terraform原始数据结构,自动生成AssociationProperty和AssociationPropertyMetadata等字段。

  • 完整模板示例代码

    variable "user_information" {
      type = object({
        name    = string
        address = string
      })
      description = <<EOT
      {
        "AssociationProperty": "Auto",
        "AssociationPropertyMetadata": {
          "Overwrite": {
            "name": {
              "Label": {
                "zh-cn": "姓名",
                "en": "Name"
              }
            }
          }
        }
      }
      EOT
    }
    
    variable "region_ids" {
      type    = list(string)
      description = <<EOT
      {
        "AssociationProperty": "Auto",
        "AssociationPropertyMetadata": {
          "Overwrite": {
            "*": {
              "AssociationProperty": "ALIYUN::ECS::RegionId"
            }
          }
        }
      }
      EOT
    }
    
    variable "docker_ports" {
      type = list(object({
        internal = number
        external = number
        protocol = string
      }))
      description = <<EOT
      {
        "AssociationProperty": "Auto",
        "AssociationPropertyMetadata": {
          "Overwrite": {
            "protocol": {
              "AllowedValues": ["TCP", "UDP", "ICMP"]
            },
            "internal": {
              "Label": {
                "zh-cn": "内部端口",
                "en": "Internal Port"
              }
            }
          }
        }
      }
      EOT
    }
    
    variable "complex_type_demo" {
      type = list(object({
        b = list(string)
        c = list(object({
          d = list(string)
        }))
        e = list(list(string))
        f = list(list(object({
          g = list(string)
        })))
      }))
      description = <<EOT
      {
        "AssociationProperty": "Auto",
        "AssociationPropertyMetadata": {
            "Overwrite": {
                "b": {
                    "MaxLength": 3,
                    "AssociationPropertyMetadata": {
                        "Something": "123"
                    },
                    "Label": {
                        "zh-cn": "B",
                        "en": "B"
                    }
                },
                "b.*": {
                    "AssociationProperty": "ALIYUN::ECS::RegionId"
                },
                "c": {
                    "Label": {
                        "zh-cn": "C",
                        "en": "C"
                    }
                },
                "c.d": {
                    "Label": {
                        "zh-cn": "C/D",
                        "en": "C/D"
                    }
                },
                "c.d.*": {
                    "AssociationProperty": "ALIYUN::ECS::RegionId"
                },
                "e": {
                    "Label": {
                        "zh-cn": "E",
                        "en": "E"
                    }
                },
                "e.*": {
                    "MaxLength": 3
                },
                "e.*.*": {
                    "AssociationProperty": "ALIYUN::ECS::RegionId"
                },
                "f.g": {
                    "Label": {
                        "zh-cn": "F/G",
                        "en": "F/G"
                    }
                },
                "f.g.*": {
                    "AssociationProperty": "ALIYUN::ECS::RegionId"
                }
            }
        }
      }
      EOT
    }
  • 参数user_information转换后模板示例代码

    {
      "AssociationPropertyMetadata":{
        "Parameters":{
          "address":{
            "Type":"String"
          },
          "name":{
            "Type":"String",
            "Label":{
              "en":"Name",
              "zh-cn":"姓名"
            }
          }
        }
      }
    }
  • 参数region_ids转换后模板示例代码

    {
      "AssociationPropertyMetadata":{
        "Parameter":{
          "AssociationProperty":"ALIYUN::ECS::RegionId",
          "Type":"String"
        }
      },
      "AssociationProperty":"List[Parameter]"
    }
  • 参数docker_ports转换后模板示例代码

    {
      "AssociationPropertyMetadata":{
        "Parameters":{
          "internal":{
            "Type":"Number",
            "Label":{
              "en":"Internal Port",
              "zh-cn":"内部端口"
            }
          },
          "protocol":{
            "Type":"String",
            "AllowedValues":[
              "TCP",
              "UDP",
              "ICMP"
            ]
          },
          "external":{
            "Type":"Number"
          }
        }
      },
      "AssociationProperty":"List[Parameters]"
    }
  • 参数complex_type_demo转换后模板示例代码

    {
      "AssociationPropertyMetadata":{
        "Parameter":{
          "AssociationPropertyMetadata":{
            "Parameters":{
              "b":{
                "AssociationPropertyMetadata":{
                  "Parameter":{
                    "AssociationProperty":"ALIYUN::ECS::RegionId",
                    "Type":"String"
                  },
                  "Something":"123"
                },
                "AssociationProperty":"List[Parameter]",
                "Type":"Json",
                "Label":{
                  "en":"B",
                  "zh-cn":"B"
                },
                "MaxLength":3
              },
              "c":{
                "AssociationPropertyMetadata":{
                  "Parameter":{
                    "AssociationPropertyMetadata":{
                      "Parameters":{
                        "d":{
                          "AssociationPropertyMetadata":{
                            "Parameter":{
                              "AssociationProperty":"ALIYUN::ECS::RegionId",
                              "Type":"String"
                            }
                          },
                          "AssociationProperty":"List[Parameter]",
                          "Type":"Json",
                          "Label":{
                            "en":"C/D",
                            "zh-cn":"C/D"
                          }
                        }
                      }
                    },
                    "Type":"Json"
                  }
                },
                "AssociationProperty":"List[Parameter]",
                "Type":"Json",
                "Label":{
                  "en":"C",
                  "zh-cn":"C"
                }
              },
              "e":{
                "AssociationPropertyMetadata":{
                  "Parameter":{
                    "AssociationPropertyMetadata":{
                      "Parameter":{
                        "AssociationProperty":"ALIYUN::ECS::RegionId",
                        "Type":"String"
                      }
                    },
                    "AssociationProperty":"List[Parameter]",
                    "Type":"Json",
                    "MaxLength":3
                  }
                },
                "AssociationProperty":"List[Parameter]",
                "Type":"Json",
                "Label":{
                  "en":"E",
                  "zh-cn":"E"
                }
              },
              "f":{
                "AssociationPropertyMetadata":{
                  "Parameter":{
                    "AssociationPropertyMetadata":{
                      "Parameter":{
                        "AssociationPropertyMetadata":{
                          "Parameters":{
                            "g":{
                              "AssociationPropertyMetadata":{
                                "Parameter":{
                                  "AssociationProperty":"ALIYUN::ECS::RegionId",
                                  "Type":"String"
                                }
                              },
                              "AssociationProperty":"List[Parameter]",
                              "Type":"Json",
                              "Label":{
                                "en":"F/G",
                                "zh-cn":"F/G"
                              }
                            }
                          }
                        },
                        "Type":"Json"
                      }
                    },
                    "AssociationProperty":"List[Parameter]",
                    "Type":"Json"
                  }
                },
                "AssociationProperty":"List[Parameter]",
                "Type":"Json"
              }
            }
          },
          "Type":"Json"
        }
      },
      "AssociationProperty":"List[Parameter]"
    }

更多示例

您也可以使用AssociationProperty和AssociationPropertyMetadata,实现以下诉求: