![](/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.