テラフォームコード:
resource "aws_cloudwatch_metric_alarm" "disk_percentage_low" {
for_each = toset(var.instance)
alarm_name = "disk_percentage_low"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name"LogicalDisk = % Free Space"
namespace = "CWAgent"
period = "60"
statistic = "Average"
threshold = "20"
alarm_description = "This metric monitors ec2 disk utilization"
actions_enabled = "true"
alarm_actions = [aws_sns_topic.disk_alarm.arn]
insufficient_data_actions = []
dimensions = {
InstanceId = var.InstanceId
InstanceType = var.InstanceType
ImageId = var.ImageId
instance = each.value
objectname = var.objectname
}
}
variable "instance" {
type = list
default = ["E:" , "D:"]
}
これがTerraformプランからの出力です。あなたはそれが例えば2つのCloudWatchのアラームを作成する必要が見ることができるようにE:
とD:
、私はコンソールに行くときに適用が正常に実行された後、しかし、それは唯一のインスタンスのアラームを作成しますE:
# aws_cloudwatch_metric_alarm.disk_percentage_low["D:"] will be created
+ resource "aws_cloudwatch_metric_alarm"
"disk_percentage_low" {
+ actions_enabled = true
+ alarm_actions = (known after apply)
+ alarm_description = "This metric monitors ec2 disk utilization"
+ alarm_name = "disk_percentage_low"
+ arn = (known after apply)
+ comparison_operator = "LessThanOrEqualToThreshold"
+ dimensions = {
+ "ImageId" = "ami-0aac9d7fa83beb6d2"
+ "InstanceId" = "i-021e580bccd130ac6"
+ "InstanceType" = "t2.micro"
+ "instance" = "D:"
+ "objectname" = "LogicalDisk"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 1
+ id = (known after apply)
+ metric_name = "LogicalDisk % Free Space"
+ namespace = "CWAgent"
+ period = 60
+ statistic = "Average"
+ threshold = 20
+ treat_missing_data = "missing"
}
# aws_cloudwatch_metric_alarm.disk_percentage_low["E:"] will be created
+ resource "aws_cloudwatch_metric_alarm"
"disk_percentage_low" {
+ actions_enabled = true
+ alarm_actions = (known after apply)
+ alarm_description = "This metric monitors ec2 disk utilization"
+ alarm_name = "disk_percentage_low"
+ arn = (known after apply)
+ comparison_operator = "LessThanOrEqualToThreshold"
+ dimensions = {
+ "ImageId" = "ami-0aac9d7fa83beb6d2"
+ "InstanceId" = "i-021e580bccd130ac6"
+ "InstanceType" = "t2.micro"
+ "instance" = "E:"
+ "objectname" = "LogicalDisk"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 1
+ id = (known after apply)
+ metric_name = "LogicalDisk % Free Space"
+ namespace = "CWAgent"
+ period = 60
+ statistic = "Average"
+ threshold = 20
+ treat_missing_data = "missing"
}
これは、alarm_name
:を修正したためだと思います。
alarm_name = "disk_percentage_low"
したがって、両方が同じ名前であるため、2番目のアラームが最初のアラームを上書きします。簡単な修正は次のとおりです。
alarm_name = "disk_percentage_low_${each.value}"
ただし:
、「E:」と「D:」があるため、名前で許可されるかどうかは上記ではわかりません。これはあなたがチェックできるものです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加