diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d2cdff6..a4a8ddc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -51,7 +51,7 @@ jobs: name: Minimum version check runs-on: ubuntu-latest container: - image: hashicorp/terraform:0.12.0 + image: hashicorp/terraform:0.12.20 steps: - uses: actions/checkout@master - name: Validate Code diff --git a/README.md b/README.md index 6ae826d..ef62723 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ If you have specified cloudfront_default_certificate, TLSv1 must be specified. | Name | Version | |------|---------| -| terraform | >= 0.12.0 | +| terraform | >= 0.12.20 | ## Providers @@ -52,6 +52,7 @@ If you have specified cloudfront_default_certificate, TLSv1 must be specified. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | alarm\_cloudfront\_500\_errors\_threshold | Cloudfront 500 Errors rate threshold (use 0 to disable this alarm) | `number` | `5` | no | +| alarm\_prefix | String prefix for cloudwatch alarms. (Optional) | `string` | `"alarm"` | no | | alarm\_sns\_topics\_us | Alarm topics to create and alert on metrics on US region | `list` | `[]` | no | | alb\_cloudfront\_key | Key generated by terraform-aws-ecs module to allow ALB connection from CloudFront | `any` | n/a | yes | | alb\_dns\_name | ALB DNS Name that CloudFront will point as origin | `any` | n/a | yes | diff --git a/_data.tf b/_data.tf index 239bc19..baf38e6 100644 --- a/_data.tf +++ b/_data.tf @@ -1 +1,3 @@ -data "aws_iam_account_alias" "current" {} +data "aws_iam_account_alias" "current" { + count = var.alarm_prefix == "" ? 1 : 0 +} diff --git a/_variables.tf b/_variables.tf index 02da8e7..82b32e2 100644 --- a/_variables.tf +++ b/_variables.tf @@ -116,3 +116,9 @@ variable "dynamic_ordered_cache_behavior" { type = any default = [] } + +variable "alarm_prefix" { + type = string + description = "String prefix for cloudwatch alarms. (Optional)" + default = "alarm" +} \ No newline at end of file diff --git a/cloudwatch-alarms.tf b/cloudwatch-alarms.tf index aae3c81..33fb3f4 100644 --- a/cloudwatch-alarms.tf +++ b/cloudwatch-alarms.tf @@ -2,7 +2,7 @@ resource "aws_cloudwatch_metric_alarm" "cloudfront_500_errors" { provider = aws.us-east-1 count = length(var.alarm_sns_topics_us) > 0 && var.alarm_cloudfront_500_errors_threshold != 0 ? 1 : 0 - alarm_name = "${data.aws_iam_account_alias.current.account_alias}-ecs-${var.cluster_name}-${var.name}-cloudfront-500-errors" + alarm_name = try(data.aws_iam_account_alias.current[0].account_alias, "${var.alarm_prefix}-ecs-${var.name}-cloudfront-500-errors") comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "3" metric_name = "5xxErrorRate" diff --git a/versions.tf b/versions.tf index cd0f691..8bf1778 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,3 @@ terraform { - required_version = ">= 0.12.0" + required_version = ">= 0.12.20" } \ No newline at end of file