Reputation: 191
I am trying to get a CloudWatch alarm working with a Route53 Health Check.
I can manually set things up in the AWS GUI.
When I try with Terraform the Health Check shows "No alarms configured".
I've seen suggestions for methods using Health Checks to the http (or other) ports, but my service is internal and so not open to HTTP/TCP port checks, so instead I am looking at a CloudWatch StatusCheckFailed alarm.
Whatever I do I seem to end up with "No alarms configured" for my health checks (this screendump shows the two created manually with working alarms and two created via Terraform showing "No alarms configured").
Has anybody managed to get this to work?
-=-=-=-=-
I manually added an alarm to one of the "No alarms configured Health Checks above in the AWS Console GUI and it appeared and updated its status.
In doing so, I noticed that the Health Check description was the name of the CloudWatch alarm, so it would appear that at least some of the alarm info was processed by Terraform.
-=-=-=-=-=-=-=-=-
This is the Terraform code for one of the Route53 Health Checks & CloudWatch alarm.
The CW alarm:
# This is a dummy alarm, for testing.
# CloudWatch alarm for use with Route 53 DNS health Check; this does not have an action.
resource "aws_cloudwatch_metric_alarm" "dummy_alarm" {
provider = "aws.use1"
alarm_name = "smb-nfs-server-dummy-alarm"
alarm_description = "Check the SMB-NFS server is alarm"
comparison_operator = "GreaterThanOrEqualToThreshold"
metric_name = "StatusCheckFailed"
namespace = "AWS/EC2"
period = "60"
evaluation_periods = "2"
statistic = "Maximum"
threshold = "1"
treat_missing_data = "breaching"
#insufficient_data_actions = []
#alarm_actions = []
dimensions {
InstanceId = "${var.server_01_id}"
#HealthCheckId = "${var.dns_hc_01_id}"
}
}
The Route53 HC:
resource "aws_route53_health_check" "server_01_health" {
provider = "aws.use1"
child_health_threshold = "0",
#child_healthchecks.# = "0",
#cloudwatch_alarm_name = "awsec2-i-03dc5080f7bd3037d-paul-smb-gw-02-a-High-Status-Check-Failed-Any-",
#cloudwatch_alarm_region = "eu-west-1",
enable_sni = "false",
failure_threshold = "0",
fqdn = "",
#id = "6eb384bc-2129-47ff-9a7a-90adb9f9351f",
#insufficient_data_health_status = "LastKnownStatus",
invert_healthcheck = "false",
#ip_address = "",
measure_latency = "false",
port = "0",
#regions.# = "0",
request_interval = "0",
resource_path = "",
search_string = "",
#tags.% = "1",
#tags.Name = "smb-nfs-gw-02-a-OK",
#type = "CLOUDWATCH_METRIC"
#----------------------
cloudwatch_alarm_name = "${aws_cloudwatch_metric_alarm.dummy_alarm.alarm_name}"
#cloudwatch_alarm_name = "${aws_cloudwatch_metric_alarm.smb_nfs_server_01_alarm.alarm_name}"
cloudwatch_alarm_region = "us-east-1"
#cloudwatch_alarm_region = "${var.aws_region}"
insufficient_data_health_status = "LastKnownStatus"
tags = "${merge(var.tags, map("Name", "${var.tags["Name"]}_server_01_health"))}"
type = "CLOUDWATCH_METRIC"
}
(As you can see, I have been experimenting with options, including the region.
-=-=-=-=-=-=-=-=-
Upvotes: 1
Views: 2790
Reputation: 1
@Doug is correct. Just to emphasize the correction further, the solution requires that you adjust the dimensions dictionary to:
dimensions = {
'HealthCheckId' : "${aws_route53_health_check.server_01_health.id}"
},
The arguments in a health check resource that revolve around cloudwatch metrics alarm and region, are utilized when you are creating a health check that is monitoring the state of a cloudwatch alarm.
Upvotes: 0
Reputation: 21
I've got it to work by putting the HealthCheckId in the dimensions of the alarm, and not using the cloudwatch_alarm_name property in the aws_route53_health_check
resource "aws_cloudwatch_metric_alarm" "dummy_alarm" {
...
dimensions {
...
HealthCheckId = "${aws_route53_health_check.server_01_health.id}"
}
}
resource "aws_route53_health_check" "server_01_health" {
...
#cloudwatch_alarm_name =
#cloudwatch_alarm_region =
}
Upvotes: 2