I'm trying to use terraform to create an AnomalySubscription with AWS Cloudformation. Based on: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ce-anomalysubscription.html
When I tested Terraform plan, I'm receiving:
│ Error: Invalid template interpolation value │ │ each.value.NotificationsEmail is tuple with 1 element │ │ Cannot include the given value in a string template: string required.
resource.tf
resource "aws_cloudformation_stack" "anomaly_detection" {
name = "${var.StackName}${each.value.Key}"
for_each = { for i in local.anomalies : "${i.Key}" => i }
template_body = <<EOF
AWSTemplateFormatVersion: "2010-09-09"
Description: Cost Anomaly Detection
Resources:
CostExplorer:
Type: AWS::CE::AnomalySubscription
Properties:
Frequency: DAILY
MonitorArnList: [!Ref CostExplorerServiceAnomalyMonitor]
Subscribers: ${each.value.NotificationsEmail}
SubscriptionName: DailyAnomalySubscription
Threshold: ${each.value.Threshold}
EOF
}
locals {
anomalies = flatten([
for k, v in var.Anomalies : [
{
Key = k
Type = v.Type
NotificationsEmail = v.NotificationsEmail
Threshold = v.Threshold
}
]
])
}
Anomalies = {
Subscription = {
Type = "Daily"
Threshold = 500
NotificationsEmail = [
{
Type = "EMAIL"
Address = "test@xyz.com"
},
{
Type = "EMAIL"
Address = "test2@xyz.com"
}]
}
}
NotificationsEmail = [
{
Type = "EMAIL"
Address = "test@xyz.com"
},
{
Type = "EMAIL"
Address = "test2@xyz.com"
}]