我正在使用Terraform创建CloudWatch警报,例如:
resource "aws_cloudwatch_metric_alarm" "terraform_cloudwatch_metric_alarm_CPUUtilization" {
alarm_name = "terraform_cloudwatch_metric_alarm_CPUUtilization"
alarm_description = "terraform_cloudwatch_metric_alarm_CPUUtilization"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "300"
statistic = "Average"
threshold = "90"
dimensions = {
"InstanceId" = "${aws_instance.terraform_instance.id}"
}
}
任何想法为何以及如何解决?
PS 临时解决方法是将local-exec
添加到aws_instance
:
provisioner "local-exec" {
command = <<-EOF
aws cloudwatch put-metric-alarm \
--alarm-name "cloudwatch_metric_alarm_CPUUtilization" \
--alarm-description "cloudwatch_metric_alarm_CPUUtilization" \
--no-actions-enabled \
--metric-name "CPUUtilization" \
--namespace "AWS/EC2" \
--statistic "Average" \
--dimensions "Name=InstanceId,Value=${aws_instance.terraform_instance.id}" \
--period "300" \
--unit "Percent" \
--evaluation-periods "1" \
--threshold "90" \
--comparison-operator "GreaterThanOrEqualToThreshold" \
--treat-missing-data "missing"
EOF
}