参数(parameters) V3
更新时间:2024-11-27
参数可用于在资源栈创建时覆盖模板中的某些值,用来提高模板的灵活性和可复用性。
JSON
1"parameters": {
2 "bccSpec": {
3 "label": "BCC实例规格",
4 "required": true,
5 "type": "String",
6 "description": "规格控制实例的CPU、内存大小等选型,请输入实例的规格,如bcc.g6.c2m8",
7 "defaultValue": "bcc.g6.c2m8"
8 }
9 }
上面定义的 bccSpec 参数,允许在用户使用模板创建资源栈时重新赋值。如果用户不设置参数值则使用默认的bcc.g6.c2m8
。在资源定义时,可以引用此参数:
JSON
1"resources": {
2 "bcc": {
3 "Type": "BCE::BCC::Instance",
4 "properties": {
5 "spec": {
6 "Ref": "bccSpec"
7 }
8 }
9 }
10 }
语法
每个参数由参数名称和参数属性组成。 参数名称必须为字母数字,并且在同一个模板中不能与其它参数名称重复。可以用 Label 字段来定义友好的参数名,一般在把模板动态生成为 Web 表单时很有用。 参数属性列表:
属性 | 是否必选 | 描述 |
---|---|---|
label | 否 | 参数别名,支持 UTF-8 字符,通过模板生成 Web 表单时可映射为 label。 |
require | 否 | 定义参数在创建stack时,是否为必选字段 |
type | 是 | 参数的数据类型。 String:字符串。如:”N3”。 Number:整数或浮点数。如:4。 Boolean:一个布尔值。如:true 或者 false Object:json 对象。如:{"key":"value"} List:json 数组。如:["key1","key2"] |
defaultValue | 否 | 在创建资源栈时,如果用户没有传入指定值,编排服务会检查模板中是否有定义默认值,如果有定义默认值,则使用默认值。 |
description | 否 | 用于描述参数的字符串。 |
示例
JSON
1"parameters": {
2 "rootDiskStorageType": {
3 "label": "系统盘类型",
4 "required": true,
5 "type": "String",
6 "defaultValue": "cloud_hp1",
7 "description": "系统盘的类型,默认为SSD(cloud_hp1),查看所有磁盘类型可参见:<a href='https://cloud.baidu.com/doc/BCC/s/6jwvyo0q2#storagetype' target='_blank'><b><font color='#2468f2'>磁盘类型</font></b></a>"
8 },
9 "rootDiskSizeInGb": {
10 "label": "系统盘大小(GB)",
11 "required": true,
12 "type": "Number",
13 "defaultValue": 50,
14 "description": "单位GB,最大不建议超过100G。"
15 },
16 "securityGroupIds": {
17 "label": "BCC实例绑定的安全组",
18 "description": "设置BCC实例的安全组,请注意可用区、子网、安全组相互关联。不填写将绑定默认安全组,可输入一个或多个安全组ID,例如:[\"xxx\",\"xxx\"]",
19 "required": false,
20 "type": "List",
21 "defaultValue": ["g-xxxx","g-xxxx"]
22 },
23 "bccBilling": {
24 "label": "BCC实例计费参数",
25 "required": true,
26 "type": "Object",
27 "description": "支持后付费Postpaid和预付费Prepaid两种付款方式,如果选择预付费,还需要指定购买时长(仅支持按月购买,可选月数为:[1,2,3,4,5,6,7,8,9,12,24,36]),如购买一个月时,应填入:{\"paymentTiming\":\"Prepaid\",\"reservation\":{\"reservationLength\":1,\"reservationTimeUnit\":\"month\"}}。",
28 "defaultValue": {
29 "paymentTiming": "Postpaid"
30 }
31 }
32}