【发布时间】:2020-09-12 09:37:29
【问题描述】:
我想通过基于列表变量(email_addresses)的 loping 使用 terraform template_file 创建 CFT。 以下是我要生成的变量和模板。
variables:-
emails_addresses = ["sample-1@gmail.com", "sample-2@gmail.com"]
sns_arn = "arn:aws:sns:us-east-1:xxxxxx:xxxx"
protocol = "email"
期望模板:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"sample-1": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Endpoint": "sample-1@gmail.com",
"Protocol": "email",
"TopicArn": "arn:aws:sns:us-east-1:xxxx:xxxxx"
}
},
"sample-2": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Endpoint": "sample-2@gmil.com",
"Protocol": "email",
"TopicArn": "arn:aws:sns:us-east-1:xxx:xxxx"
}
}
}
}
CFT 中的资源名称可以是一些随机字符串,但在多个计划/申请的情况下,每封邮件应相同。
【问题讨论】:
-
下面是我试图改变的一些例子。
data "template_file" "cloudformation_sns_stack" { template = file("${path.module}/templates/email-sns-stack.json.tpl") vars = { display_name = var.display_name subscriptions = join( ",", formatlist( "{ \"Endpoint\": \"%s\", \"Protocol\": \"%s\" }", var.email_addresses, var.protocol, ), ) } }
标签: amazon-web-services terraform amazon-sns terraform-provider-aws