hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.81k stars 9.16k forks source link

[Docs]: CloudWatch Alarm Check in aws_route53_health_check is not a relevant example #31582

Open MagnusSafty opened 1 year ago

MagnusSafty commented 1 year ago

Documentation Link

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_health_check#cloudwatch-alarm-check

Description

The example that is given for aws_cloudwatch_metric_alarm is monitoring CPU and not the health check.

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

MagnusSafty commented 1 year ago

Working example could look like this

resource "aws_route53_health_check" "example" {
  fqdn              = example.com
  port              = 443
  resource_path     = "/"
  failure_threshold = "3"
  request_interval  = "30"
  search_string     = "ok"
  type              = "HTTPS_STR_MATCH"
}

resource "aws_cloudwatch_metric_alarm" "example" {
  provider            = aws.useast1
  alarm_name          = "Down: ${aws_route53_health_check.example.fqdn}"
  comparison_operator = "LessThanThreshold"
  evaluation_periods  = "2"
  metric_name         = "HealthCheckStatus"
  namespace           = "AWS/Route53"
  period              = "60"
  statistic           = "Minimum"
  threshold           = "1"

  dimensions = {
    HealthCheckId = aws_route53_health_check.example.id
  }
}
justinretzolk commented 1 year ago

Hey @MagnusSafty 👋 Thank you for taking the time to raise this! The example you provided looks like a CloudWatch metric alarm that monitors a Route53 health check, whereas the example in the documentation as it stands is a Route53 health check that monitors a CloudWatch alarm (so, inverted). Unless I'm missing something (which I'm always open to!), it seems to me that both are valid configurations, however, the existing example seems like it's more relevant to the aws_route53_health_check resource's documentation. Does that line up with your read on the linked documents, or have I missed something here?

camdesgov commented 2 months ago

@MagnusSafty I just wanted to thank you for writing this! I was struggling with very same thing and I agree the "official" terraform example is backward. Most people want the cloudwatch metric to monitor their route53 alarm as you have suggested, I have never encountered a use case which is the other way round. The terraform example should be updated to match your suggestion

Dr-Emann commented 2 months ago

I agree with @justinretzolk: The existing documentation is valid, and is more directly related to "the ways you can configure a route53 health check" (the opposite way is much more related to "how to configure a cloudwatch alarm to point at a route53 health check")