diff --git a/Cloudwatch-metric-alarm.tf b/Cloudwatch-metric-alarm.tf index 7e7f006..94b5005 100644 --- a/Cloudwatch-metric-alarm.tf +++ b/Cloudwatch-metric-alarm.tf @@ -1,5 +1,6 @@ resource "aws_cloudwatch_metric_alarm" "health_check" { - alarm_name = "route53-healthcheck/${var.name}" + count = try(var.cloudwatch_alarms_enabled, false) ? 1 : 0 + alarm_name = "route53-healthcheck/${var.hostname}" metric_name = "HealthCheckStatus" comparison_operator = "LessThanThreshold" evaluation_periods = "2" diff --git a/README.md b/README.md index e673935..8d6f661 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,16 @@ In addition you have the option to: | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | aws\_sns\_topic\_arn | n/a | `string` | `""` | no | -| failure\_threshold | n/a | `number` | `2` | no | +| cloudwatch\_alarms\_enabled | n/a | `bool` | `false` | no | +| failure\_threshold | n/a | `number` | `3` | no | | healthcheck\_path | n/a | `string` | `"/"` | no | | hostname | app Hostname to check | `any` | n/a | yes | -| name | Name of app service needs to be checked | `any` | n/a | yes | +| measure\_latency | Latency between health checkers in multiple AWS regions and your endpoint and to display CloudWatch latency graphs in the Route 53 console | `bool` | `false` | no | | period | n/a | `number` | `60` | no | | port | Port for target check | `string` | `"80"` | no | | protocol | n/a | `string` | `"HTTP"` | no | -| threshold | n/a | `number` | `1` | no | -| time\_request | n/a | `number` | `30` | no | +| request\_interval | n/a | `number` | `30` | no | +| threshold | n/a | `number` | `2` | no | ## Outputs diff --git a/_variables.tf b/_variables.tf index 6b32214..9d03709 100644 --- a/_variables.tf +++ b/_variables.tf @@ -1,6 +1,6 @@ -variable "name" { - description = "Name of app service needs to be checked" -} +# variable "name" { +# description = "Name of app service needs to be checked" +# } variable "port" { default = "80" @@ -24,17 +24,28 @@ variable "protocol" { } variable "threshold" { - default = 1 + default = 2 } variable "period" { default = 60 } -variable "time_request" { +variable "request_interval" { default = 30 } variable "failure_threshold" { - default = 2 + default = 3 } + +variable "measure_latency" { + type = bool + default = false + description = "Latency between health checkers in multiple AWS regions and your endpoint and to display CloudWatch latency graphs in the Route 53 console" +} + +variable "cloudwatch_alarms_enabled" { + type = bool + default = false +} \ No newline at end of file diff --git a/examples/one.yaml b/examples/one.yaml new file mode 100644 index 0000000..535e91b --- /dev/null +++ b/examples/one.yaml @@ -0,0 +1,21 @@ +workspaces: + prod-ap-southeast-2: + route53_health_check: + health_check_enable: true + endpoints: + - hostname: www.example.com + port: 8443 + protocol: HTTPS + healthcheck_path: /healthcheck + measure_latency: true + - hostname: www.myportal.com + port: 443 + protocol: HTTPS + healthcheck_path: + measure_latency: true + + aws_cloudwatch_metric_alarm: [] + # cloudwatch_alarms_enabled: true + # - alarm_name: + # period: + # aws_sns_topic_arn: \ No newline at end of file diff --git a/examples/route53_health_check.tf b/examples/route53_health_check.tf new file mode 100644 index 0000000..4222938 --- /dev/null +++ b/examples/route53_health_check.tf @@ -0,0 +1,13 @@ +module "terraform-aws-route53healthcheck" { + source = "git::https://github.com/DNXLabs/terraform-aws-route53healthcheck.git?ref=0.1.1" + for_each = { for healthcheck in try(local.workspace.route53_health_check.endpoint, []) : healthcheck.hostname => healthcheck } + # providers = { + # aws = aws.us-east-1 + # } + + hostname = try(each.value.hostname, "[]") + port = try(each.value.port, 443) + protocol = try(each.value.protocol, "HTTPS") + healthcheck_path = try(each.value.healthcheck_path, "") + measure_latency = try(each.value.measure_latency, true) +} \ No newline at end of file diff --git a/route53-healthcheck.tf b/route53-healthcheck.tf index 9ab126b..749591f 100644 --- a/route53-healthcheck.tf +++ b/route53-healthcheck.tf @@ -1,14 +1,15 @@ resource "aws_route53_health_check" "default" { - reference_name = var.name fqdn = var.hostname port = var.port type = var.protocol resource_path = var.healthcheck_path failure_threshold = var.failure_threshold - request_interval = var.time_request + request_interval = var.request_interval + measure_latency = var.measure_latency #insufficient_data_health_status = "Healthy" + # reference_name = var.name tags = { - Name = var.name + Name = var.hostname } -} +} \ No newline at end of file