阅读815 返回首页    go 微信


映射(Mappings)__模板语法_资源编排-阿里云

映像是一个 Key-Value 映射表。在模板的 Resources 和 Outputs 部分可以使用 Fn::FindInMap 内部函数,通过给出 Key 获取映射表的 Value。

语法

映像部分由 Key-Value 对组成。其中 Key 和 Value 可以为字符串类型或者数字类型。如果用户声明多个映射,则可用逗号将它们分隔开,每个映射的名称不能重复。

示例

以下示例正确的映像。

  1. "Mappings" : {
  2. "ValidMapping" : {
  3. "TestKey1" : { "TestValu1" : "value1" },
  4. "TestKey2" : { "TestValu2" : "value2" },
  5. 1234567890 : { "TestValu3" : "value3" },
  6. "TestKey4" : { "TestValu4" : 1234 }
  7. }
  8. }

以下示例错误的映像。

  1. "Mappings" : {
  2. "InvalidMapping1" : {
  3. "ValueList" : [ "foo", "bar" ],
  4. "ValueString" : "baz"
  5. },
  6. "InvalidMapping2": [ "foo", { "bar" : "baz" } ],
  7. "InvalidMapping3": "foobar"
  8. }

以下示例 Fn::FindInMap。

  1. {
  2. "ROSTemplateFormatVersion": "2015-09-01",
  3. "Parameters": {
  4. "regionParam": {
  5. "Description": "选择创建ECS的区域",
  6. "Type": "String",
  7. "AllowedValues": ["hangzhou", "beijing"]
  8. }
  9. },
  10. "Mappings" : {
  11. "RegionMap" : {
  12. "hangzhou" : { "32" : "m-25l0rcfjo", "64" : "m-25l0rcfj1" },
  13. "beijing" : { "32" : "m-25l0rcfj2", "64" : "m-25l0rcfj3" }
  14. }
  15. },
  16. "Resources": {
  17. "WebServer": {
  18. "Type": "ALIYUN::ECS::Instance",
  19. "Properties": {
  20. "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "regionParam" }, "32"]},
  21. "InstanceType": "ecs.t1.small",
  22. "SecurityGroupId": "sg-25zwc3se0",
  23. "ZoneId": "cn-beijing-b",
  24. "Tags": [{
  25. "Key": "tiantt",
  26. "Value": "ros"
  27. },{
  28. "Key": "tiantt1",
  29. "Value": "ros1"
  30. }
  31. ]
  32. }
  33. }
  34. }
  35. }

最后更新:2016-11-23 17:16:05

  上一篇:go 输出(Outputs)__模板语法_资源编排-阿里云
  下一篇:go ALIYUN::ECS::Disk__资源列表_资源编排-阿里云