【发布时间】:2019-09-02 23:19:37
【问题描述】:
我想添加一个警报,当 Elastic Beanstalk 环境创建的应用程序负载均衡器中有太多 5xx 错误时触发。
EB 环境由 terraform 脚本创建。 terraform创建资源aws_elastic_beanstalk_environment后才能知道负载均衡器的名称。
This page 表示elastic-beanstalk-environment 有一个名为elb_load_balancers 的输出。我想我可能可以使用这个输出来创建一个aws_cloudwatch_metric_alarm 资源。
以下 terraform 脚本是我现在所做的。它不工作
resource "aws_cloudwatch_metric_alarm" "alarm_5xx" {
alarm_name = "EB 5XX Alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = "60"
statistic = "Sum"
threshold = "10"
dimensions = {
# How can I put the name of the dynamically generated load balancer here?
LoadBalancer = "${aws_elastic_beanstalk_environment.my_eb_environment_name.elb_load_balancers}" # This line doesn't work
}
alarm_description = "This metric monitors number of 5xx erros in the application load balancer"
}
上面的脚本在我运行terraform apply -target=aws_cloudwatch_metric_alarm.alarm_5xx时产生如下错误:
* aws_cloudwatch_metric_alarm.alarm_5xx: Resource 'aws_elastic_beanstalk_environment.my_eb_environment_name' does not have attribute 'elb_load_balancers' for variable 'aws_elastic_beanstalk_environment.my_eb_environment_name.elb_load_balancers'
我也试过了
resource "aws_cloudwatch_metric_alarm" "alarm_5xx" {
alarm_name = "EB 5XX Alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = "60"
statistic = "Sum"
threshold = "10"
dimensions = {
LoadBalancer = "${aws_elastic_beanstalk_environment.RightestCARE-Api-Prod-Terraform.load_balancers}" # This line doesn't work
}
alarm_description = "This metric monitors number of 5xx erros in the application load balancer"
}
但这会产生以下错误:
* aws_cloudwatch_metric_alarm.alarm_5xx: dimensions (LoadBalancerName): '' expected type 'string', got unconvertible type '[]interface {}'
【问题讨论】:
-
aws_elastic_beanstalk_environment资源的输出只是load_balancers。
标签: amazon-web-services terraform amazon-elastic-beanstalk