【发布时间】:2021-05-22 16:01:48
【问题描述】:
我的 AWS_CloudWatch_Resource 在 terraform 上有以下正文:
dashboard_body = jsonencode(
dashboard_body = jsonencode(
{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 9,
"height": 6,
"properties": {
"view": "bar",
"stacked": false,
"metrics": [
[ "AWS/AutoScaling", "GroupDesiredCapacity", "AutoScalingGroupName", "Momo-Test-ASG1" ],
[ ".", "GroupMaxSize", ".", "." ],
[ ".", "GroupTotalCapacity", ".", "." ],
[ ".", "GroupTotalInstances", ".", "." ],
[ ".", "GroupInServiceInstances", ".", "." ]
],
"region": "eu-central-1",
"title": "ASG1 statistics"
}
},
{
"type": "metric",
"x": 9,
"y": 0,
"width": 9,
"height": 6,
"properties": {
"view": "bar",
"stacked": false,
"metrics": [
[ "AWS/AutoScaling", "GroupDesiredCapacity", "AutoScalingGroupName", "Momo-Test-ASG2" ],
[ ".", "GroupMaxSize", ".", "." ],
[ ".", "GroupTotalCapacity", ".", "." ],
[ ".", "GroupTotalInstances", ".", "." ],
[ ".", "GroupInServiceInstances", ".", "." ]
],
"region": "eu-central-1",
"period": 300,
"title": "ASG2 statistics"
}
},
{
"type": "explorer",
"x": 0,
"y": 6,
"width": 24,
"height": 15,
"properties": {
"metrics": [
{
"metricName": "CPUUtilization",
"resourceType": "AWS::EC2::Instance",
"stat": "Average"
},
{
"metricName": "NetworkIn",
"resourceType": "AWS::EC2::Instance",
"stat": "Average"
},
{
"metricName": "DiskReadOps",
"resourceType": "AWS::EC2::Instance",
"stat": "Average"
},
{
"metricName": "DiskWriteOps",
"resourceType": "AWS::EC2::Instance",
"stat": "Average"
},
{
"metricName": "NetworkOut",
"resourceType": "AWS::EC2::Instance",
"stat": "Average"
}
],
"aggregateBy": {
"key": "*",
"func": "AVG"
},
"labels": [
{
"key": "aws:autoscaling:groupName",
"value": "Momo-Test-ASG1"
},
{
"key": "aws:autoscaling:groupName",
"value": "Momo-Test-ASG2"
}
],
"widgetOptions": {
"legend": {
"position": "bottom"
},
"view": "timeSeries",
"stacked": false,
"rowsPerPage": 40,
"widgetsPerRow": 3
},
"period": 300,
"splitBy": "",
"title": "Average ASG1 and ASG2"
}
},
{
"type": "metric",
"x": 0,
"y": 21,
"width": 6,
"height": 6,
"properties": {
"metrics": [
[ { "expression": "AVG(METRICS())", "label": "Average", "id": "e1" } ],
[ "CWAgent", "mem_used_percent", "InstanceId", "i-0f67225a5c04aebf9", "AutoScalingGroupName", "Momo-Test-ASG2", "ImageId", "ami-0502e817a62226e03", "InstanceType", "t2.micro", { "yAxis": "left", "id": "m1" } ],
[ "...", "i-00198c860886391f4", ".", "Momo-Test-ASG1", ".", ".", ".", ".", { "id": "m2" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "eu-central-1",
"period": 300,
"stat": "Average",
"title": "mem_used_percent"
}
}
]
}
)
}
如您所见,我的Momo-Test-ASG1(第一个自动缩放组)和Momo-Test-ASG2(此处为缩放组的第二个 Autenter 代码)拥有相同的小部件。
如果我要测试很多 ASG,那么为很多组硬编码相同的东西会很麻烦。 有什么解决方案可以让 terraform 从列表中读取 ASG?而不必复制相同的部分?
【问题讨论】:
标签: amazon-web-services amazon-cloudwatch terraform-provider-aws