I have the following code which I am trying to implement for multiple widgets in a single cloud watch dashboard
` locals {
instances = csvdecode(file("${path.module}/sample.csv"))
}
resource "aws_cloudwatch_dashboard" "main" {
dashboard_name = "my-dashboard"
dashboard_body = jsonencode(
{
"widgets": [
for inst in range(length(local.instances)):[
// i want to repeat the below section as the length of instances variable but getting an error
{
"type":"metric",
"x":0,
"y":0,
"width":12,
"height":6,
"properties":{
"metrics":[ // trying to implement multiple widget in a single dashboard
enter code here
[
"AWS/EC2",
"CPUUtilization",
"InstanceId",
"${local.instances[inst].instance_id}"
]
],
"period":300,
"stat":"Average",
"region":"ap-south-1",
"title":"EC2 Instance CPU",
"annotations": {
"horizontal": [
{
"label": "Untitled annotation",
"value": 1.01
}]
} }
}
]]
})
} `
我在错误下方收到此错误:
错误:放置仪表板失败:InvalidParameterInput:仪表板主体无效,存在4个验证错误: [ { “ dataPath”:“ / widgets / 0”, “ message”:“应该是对象” }, { “ dataPath”:“ / widgets / 1”, “ message”:“应该是对象” }, { “ dataPath”:“ / widgets / 2”, “ message”:“应该是对象” }, { “ dataPath”:“ / widgets / 3”, “ message”:“应该是对象” } ] 状态码:400,请求ID:706ac87c-a796-11e9-8983-65d87c7656b4
答案 0 :(得分:0)
代码生成如下,
{
"widgets": [
[ // <--- It seems to be wrong.
{
"height": 6,
...
小部件在列表中具有列表。因此,如下所示进行修改,
jsonencode(
{
"widgets" : [ //removed [
for inst in range(length(local.instances)) :
{
...
"annotations" : {
"horizontal" : [
{
"label" : "Untitled annotation",
"value" : 1.01
}]
}
}
}
] // and removed ]
})
删除嵌套列表。