定义映射信息表,映射信息是一种多层的Map结构。
- 映射是一个
Key-Value映射表。 - 在模板的
Resources和Outputs中,可使用内置函数Fn::FindInMap,通过指定Key而获取映射表的Value。
语法
映射由
Key-Value键值对组成。- 其中
Key和Value可以为字符串类型或者数字类型。 - 如果声明多个映射,用逗号
,分隔开。 - 每个映射的名称不能重复。
示例
代码段示例如下:
"Mappings" : {
"Mapping01" : {
"Key01" : {
"Name" : "Value01"
},
"Key02" : {
"Name" : "Value02"
},
"Key03" : {
"Name" : "Value03"
}
}使用内置函数
Fn::FindInMap返回对应的值示例:{
"ZStackTemplateFormatVersion": "2018-06-18",
"Parameters": {
"regionParam": {
"Description": "选择创建云主机的区域",
"Type": "String",
"AllowedValues": ["cn-hangzhou", "cn-shanghai"]
}
},
"Mappings" : {
"ImageInRegions" : {
"cn-hangzhou" : { "32" : "imageUuid-1", "64" : "imageUuid-2" },
"cn-shanghai" : { "32" : "imageUuid-3", "64" : "imageUuid-4" }
}
},
"Resources": {
"WebServer": {
"Type": "ZStack::Resource::VmInstance",
"Properties": {
"name" : "test-vm",
"imageUuid" : {"Fn::FindInMap": ["ImageInRegions", {"Ref":"regionParam"}, "64"]},
"instanceOfferingUuid": {"Ref":"instanceOfferingUuid"},
"l3NetworkUuids": [{"Ref":"l3NetworkUuid"}]
},
"DeletionPolicy": "Retain"
}
}
}