我目前正在设置AWS CloudWatch Alarm,使用 Terraform 检测服务器的运行状况。使用AWS Route 53运行状况检查检查运行状况。我的.tf
文件是:
resource "aws_cloudwatch_metric_alarm" "val1-alarm" {
alarm_name = "val-alarm"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "HealthCheckStatus"
namespace = "AWS/Route53"
period = "60"
statistic = "Minimum"
threshold = "0"
dimensions {
HealthCheckId = "${aws_route53_health_check.val1-hc.id}"
}
alarm_description = "This metric monitor whether the server is down or not."
insufficient_data_actions = []
}
resource "aws_route53_health_check" "val1-hc" {
fqdn = "${aws_route53_record.val1-record.name}"
port = 27017
type = "TCP"
failure_threshold = "3"
request_interval = "30"
measure_latency = 1
cloudwatch_alarm_name = "${aws_cloudwatch_metric_alarm.val1-alarm.alarm_name}"
cloudwatch_alarm_region = "eu-central-1"
}
申请时我有这个错误:
Cycle: aws_route53_health_check.val1-hc, aws_cloudwatch_metric_alarm.val1-alarm
循环意味着每个资源调用另一个。当我尝试从运行状况检查中删除cloudwatch_alarm_name
和cloudwatch_alarm_region
时,terraform错误会提示我需要这两个参数(即使doc指定这两个参数是可选的)。
如何解决?
非常感谢任何帮助或建议!
答案 0 :(得分:2)
您不需要在美国东部(弗吉尼亚州北部)中拥有您的资源,因为:
如果您选择任何其他指标,则无法使用Amazon Route 53指标 区域作为当前区域。
来源:Monitoring Health Check Status and Getting Notifications。
我设法使用此模块使用eu-west-1
:
variable "environment" {}
variable "domain_name" {}
variable "resource_path" {}
provider "aws" {
alias = "use1"
region = "us-east-1"
}
resource "aws_route53_health_check" "health_check" {
fqdn = "${var.domain_name}"
port = 443
type = "HTTPS"
resource_path = "${var.resource_path}"
measure_latency = true
request_interval = 30
failure_threshold = 3
tags = {
Name = "${var.environment}"
Origin = "terraform"
Environment = "${var.environment}"
}
}
resource "aws_sns_topic" "topic" {
name = "${var.environment}-healthcheck"
provider = "aws.use1"
}
resource "aws_cloudwatch_metric_alarm" "metric_alarm" {
provider = "aws.use1"
alarm_name = "${var.environment}-alarm-health-check"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "HealthCheckStatus"
namespace = "AWS/Route53"
period = "60"
statistic = "Minimum"
threshold = "1"
insufficient_data_actions = []
alarm_actions = ["${aws_sns_topic.topic.arn}"]
alarm_description = "Send an alarm if ${var.environment} is down"
dimensions {
HealthCheckId = "${aws_route53_health_check.health_check.id}"
}
}
答案 1 :(得分:1)
您无法<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="sample">
<div class="simple"></div>
<div class="details"></div>
</li>
<li class="sample">
<div class="simple"></div>
<div class="details"></div>
</li>
</ul>
来自A
和B
B
。
从A
删除引用,例如:
aws_cloudwatch_metric_alarm.val1-alarm
答案 2 :(得分:1)
在Terraform 0.9.3上,我必须执行相反操作并从aws_route53_health_check资源中删除cloudwatch_alarm_name和cloudwatch_alarm_region,以获取连接到运行状况检查的警报。感觉倒退了。 HealthCheckId维度足以将它们连接在一起。
resource "aws_cloudwatch_metric_alarm" "val1-alarm" {
alarm_name = "val-alarm"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "HealthCheckStatus"
namespace = "AWS/Route53"
period = "60"
statistic = "Minimum"
threshold = "0"
dimensions {
HealthCheckId = "${aws_route53_health_check.val1-hc.id}"
}
alarm_description = "This metric monitor whether the server is down or not."
insufficient_data_actions = []
}
resource "aws_route53_health_check" "val1-hc" {
fqdn = "${aws_route53_record.val1-record.name}"
port = 27017
type = "TCP"
failure_threshold = "3"
request_interval = "30"
measure_latency = 1
}
答案 3 :(得分:0)
namespace =“ AWS / Route53”