![](/img/trans.png)
[英]How to pass public key from parameter file in cloudformation template?
[英]How to pass a list of AZs from Terraform to a CloudFormation template?
我有一个定义此参数的 CloudFormation 模板:
"AvailabilityZones" : {
"Description" : "List of Availability Zones used ... ",
"Type" : "List<AWS::EC2::AvailabilityZone::Name>"
},
我像这样调用 CF 模板:
resource "aws_cloudformation_stack" "xxx" {
name = "xxx-stack"
template_body = file("../cloudformation/xxx_CloudFormation_template_2.1.1.json")
parameters = {
VpcId = aws_vpc.xxxvpc.id
SubnetCidrBlock = var.aws_vpc_cidr
AvailabilityZones = var.aws_azs
InstanceType = "m5.4xlarge"
ExternalNet = "0.0.0.0/0"
....
}
on_failure = "DELETE"
}
在哪里:
variable "aws_azs" {
default = ["us-east-1a", "us-east-1b", "us-east-1c"]
}
我收到错误:
Inappropriate value for attribute "parameters": element "AvailabilityZones": string required.
我在这个主题上尝试了很多变体,但我看不到如何将 AZ 列表从 TF 传递给 CF 模板。
我也对错误消息中需要字符串的断言感到有点困惑,因为 CF 模板中的参数类型被定义为列表。
请问有什么想法吗?
我更喜欢使用templatefile
函数而不是您在template_body
字段中使用的file
。 您可以在那里传递变量,并使用漂亮的模板引擎用传递的变量填充模板。 您可以在那里使用变量、函数、语句和循环。
示例在这里https://www.terraform.io/docs/language/functions/templatefile.html
你的榜样
resource "aws_cloudformation_stack" "xxx" {
....
template_body = templatefile("../cloudformation/xxx_CloudFormation_template_2.1.1.json", {
aws_azs = var. aws_azs
})
....
}
和你的 cf 文件:
"AvailabilityZones" : {
"Description" : "List of Availability Zones used ${join(',', aws_azs)} ",
"Type" : "List<AWS::EC2::AvailabilityZone::Name>"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.