尝试多次循环小部件字段时 Terraform 代码出现 400 错误
400 Error in Terraform code when trying to loop a widget field multiple times
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": "Should be object"
},
{
"dataPath": "/widgets/1",
"message": "Should be object"
},
{
"dataPath": "/widgets/2",
"message": "Should be object"
},
{
"dataPath": "/widgets/3",
"message": "Should be object"
}
]
状态码:400,请求id:706ac87c-a796-11e9-8983-65d87c7656b4
代码生成如下,
{
"widgets": [
[ // <--- It seems to be wrong.
{
"height": 6,
...
widgets 有列表中的列表。所以像下面这样修改,
jsonencode(
{
"widgets" : [ //removed [
for inst in range(length(local.instances)) :
{
...
"annotations" : {
"horizontal" : [
{
"label" : "Untitled annotation",
"value" : 1.01
}]
}
}
}
] // and removed ]
})
删除嵌套列表。
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": "Should be object" }, { "dataPath": "/widgets/1", "message": "Should be object" }, { "dataPath": "/widgets/2", "message": "Should be object" }, { "dataPath": "/widgets/3", "message": "Should be object" } ] 状态码:400,请求id:706ac87c-a796-11e9-8983-65d87c7656b4
代码生成如下,
{
"widgets": [
[ // <--- It seems to be wrong.
{
"height": 6,
...
widgets 有列表中的列表。所以像下面这样修改,
jsonencode(
{
"widgets" : [ //removed [
for inst in range(length(local.instances)) :
{
...
"annotations" : {
"horizontal" : [
{
"label" : "Untitled annotation",
"value" : 1.01
}]
}
}
}
] // and removed ]
})
删除嵌套列表。