From 93f408483dc73250e9263603d30a860d679ff8ac Mon Sep 17 00:00:00 2001 From: lzrocha Date: Tue, 5 Oct 2021 19:54:10 +1100 Subject: [PATCH 1/4] Adding CloudFront CW alarms --- _variables.tf | 15 ++++++ cloudwatch-alarms-cloudfront.tf | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 cloudwatch-alarms-cloudfront.tf diff --git a/_variables.tf b/_variables.tf index 424a1a5..9ece00a 100644 --- a/_variables.tf +++ b/_variables.tf @@ -135,4 +135,19 @@ variable "response_page_path" { variable "lambda_edge" { default = [] description = "Lambda EDGE configuration" +} +variable "alarms" { + type = map(any) + default = {} + description = < Date: Thu, 7 Oct 2021 11:42:09 +1100 Subject: [PATCH 2/4] Keep variables in the _variables.tf file --- _variables.tf | 25 +++++++++++++++++++++++++ cloudwatch-alarms-cloudfront.tf | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/_variables.tf b/_variables.tf index 9ece00a..b7a5ed8 100644 --- a/_variables.tf +++ b/_variables.tf @@ -136,6 +136,31 @@ variable "lambda_edge" { default = [] description = "Lambda EDGE configuration" } + +variable "default_threshold" { + description = "The default threshold for the metric." + default = 5 +} + +variable "default_evaluation_periods" { + description = "The default amount of evaluation periods." + default = 2 +} + +variable "default_period" { + description = "The default evaluation period." + default = 60 +} + +variable "default_comparison_operator" { + description = "The default comparison operator." + default = "GreaterThanOrEqualToThreshold" +} + +variable "default_statistic" { + description = "The default statistic." + default = "Average" +} variable "alarms" { type = map(any) default = {} diff --git a/cloudwatch-alarms-cloudfront.tf b/cloudwatch-alarms-cloudfront.tf index ab47bf2..2cf51fd 100644 --- a/cloudwatch-alarms-cloudfront.tf +++ b/cloudwatch-alarms-cloudfront.tf @@ -1,28 +1,3 @@ -variable "default_threshold" { - description = "The default threshold for the metric." - default = 5 -} - -variable "default_evaluation_periods" { - description = "The default amount of evaluation periods." - default = 2 -} - -variable "default_period" { - description = "The default evaluation period." - default = 60 -} - -variable "default_comparison_operator" { - description = "The default comparison operator." - default = "GreaterThanOrEqualToThreshold" -} - -variable "default_statistic" { - description = "The default statistic." - default = "Average" -} - resource "aws_cloudwatch_metric_alarm" "alarm" { count = length(var.alarms) From 0a125c7beed615cf0fc14edd12844d04824acd28 Mon Sep 17 00:00:00 2001 From: lzrocha Date: Thu, 7 Oct 2021 11:42:51 +1100 Subject: [PATCH 3/4] Updating resource name --- cloudwatch-alarms-cloudfront.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudwatch-alarms-cloudfront.tf b/cloudwatch-alarms-cloudfront.tf index 2cf51fd..a8cfea0 100644 --- a/cloudwatch-alarms-cloudfront.tf +++ b/cloudwatch-alarms-cloudfront.tf @@ -1,4 +1,4 @@ -resource "aws_cloudwatch_metric_alarm" "alarm" { +resource "aws_cloudwatch_metric_alarm" "cloufront_alarm" { count = length(var.alarms) alarm_name = format("cloudfront-%s-%s", From 7c7d8c690b257c9fa85d14fce741244e4359f24d Mon Sep 17 00:00:00 2001 From: lzrocha Date: Thu, 7 Oct 2021 11:43:08 +1100 Subject: [PATCH 4/4] Adding alarm example --- examples/cloudfront-simple-alarm.tf | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/cloudfront-simple-alarm.tf diff --git a/examples/cloudfront-simple-alarm.tf b/examples/cloudfront-simple-alarm.tf new file mode 100644 index 0000000..2b06648 --- /dev/null +++ b/examples/cloudfront-simple-alarm.tf @@ -0,0 +1,24 @@ +resource "aws_s3_bucket" "app_frontend" { + bucket_prefix = "my-frontend-app-" + acl = "private" +} + +module "app_frontend" { + source = "git::https://github.com/DNXLabs/terraform-aws-static-app.git?ref=2.0.1" # Always check the latest version + + name = "my-frontend-app" + s3_bucket_id = aws_s3_bucket.app_frontend.id + hostnames = ["www.example.com"] + certificate_arn = "arn:aws:acm:us-east-1::certificate/" # Replace the and from a valid certificate + hosted_zone = "example.com" + hostname_create = true + + alarms = { + "TotalErrorRate" = { + threshold = 1 #(%) + } + "5xxErrorRate" = { + threshold = 5 #(%) + } + } +}