title: How to get a Route53 Health Check working with a CloudWatch alarm Terraform?
body: <p>I am trying to get a CloudWatch alarm working with a Route53 Health Check.</p>
  
  <p>I can manually set things up in the AWS GUI.</p>
  
  <p>When I try with Terraform the Health Check shows "No alarms configured".</p>
  
  <p>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.</p>
  
  <p>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").</p>
  
  <p><a href="https://i.stack.imgur.com/maqQT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/maqQT.png" alt="No alarms configured"></a></p>
  
  <p>Has anybody managed to get this to work?</p>
  
  <p>-=-=-=-=-</p>
  
  <p>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.</p>
  
  <p><a href="https://i.stack.imgur.com/c7y9D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c7y9D.png" alt="Manually added an alarm"></a></p>
  
  <p>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.</p>
  
  <p>-=-=-=-=-=-=-=-=-</p>
  
  <p>This is the Terraform code for one of the Route53 Health Checks &amp; CloudWatch alarm.</p>
  
  <p>The CW alarm:</p>
  
  <pre><code># 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}"
    }
  }
  </code></pre>
  
  <p>The Route53 HC:</p>
  
  <pre><code>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"
  }
  </code></pre>
  
  <p>(As you can see, I have been experimenting with options, including the region. </p>
  
  <p>-=-=-=-=-=-=-=-=-</p>