Skip to content

Commit

Permalink
BBL-84 module migrated to tf-0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
exequielrafaela committed Jul 10, 2020
1 parent 9d4c410 commit c2e3ead
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
48 changes: 24 additions & 24 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# if(var.aws_sns_topic_arn != "" && var.aws_account_id != "")
#
resource "aws_cloudwatch_metric_alarm" "account_billing_alarm_to_existing_sns" {
count = "${var.aws_sns_topic_arn != "" && var.aws_account_id != "" ? 1 : 0}"
count = var.aws_sns_topic_arn != "" && var.aws_account_id != "" ? 1 : 0
alarm_name = "account-billing-alarm-${lower(var.currency)}-${var.aws_env}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
Expand All @@ -12,23 +12,23 @@ resource "aws_cloudwatch_metric_alarm" "account_billing_alarm_to_existing_sns" {
period = "28800"
statistic = "Maximum"
alarm_description = "Billing alarm account ${var.aws_account_id} >= US$ ${var.monthly_billing_threshold}"
threshold = "${var.monthly_billing_threshold}"
alarm_actions = ["${var.aws_sns_topic_arn}"]
threshold = var.monthly_billing_threshold
alarm_actions = [var.aws_sns_topic_arn]

dimensions = {
Currency = "${var.currency}"
LinkedAccount = "${var.aws_account_id}"
Currency = var.currency
LinkedAccount = var.aws_account_id
}

tags = "${var.tags}"
tags = var.tags
}

#
# case 2
# if(var.aws_sns_topic_arn != "" && var.aws_account_id == "")
#
resource "aws_cloudwatch_metric_alarm" "consolidated_accounts_billing_alarm_to_existing_sns" {
count = "${var.aws_sns_topic_arn != "" && var.aws_account_id == "" ? 1 : 0}"
count = var.aws_sns_topic_arn != "" && var.aws_account_id == "" ? 1 : 0
alarm_name = "account-billing-alarm-${lower(var.currency)}-${var.aws_env}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
Expand All @@ -37,33 +37,33 @@ resource "aws_cloudwatch_metric_alarm" "consolidated_accounts_billing_alarm_to_e
period = "28800"
statistic = "Maximum"
alarm_description = "Billing consolidated alarm >= US$ ${var.monthly_billing_threshold}"
threshold = "${var.monthly_billing_threshold}"
alarm_actions = ["${var.aws_sns_topic_arn}"]
threshold = var.monthly_billing_threshold
alarm_actions = [var.aws_sns_topic_arn]

dimensions = {
Currency = "${var.currency}"
Currency = var.currency
}

tags = "${var.tags}"
tags = var.tags
}

#
# cases 3 & 4
# if(var.aws_sns_topic_arn == "")
#
resource "aws_sns_topic" "sns_alert_topic" {
count = "${var.aws_sns_topic_arn == "" ? 1 : 0}"
count = var.aws_sns_topic_arn == "" ? 1 : 0
name = "billing-alarm-notification-${lower(var.currency)}-${var.aws_env}"

tags = "${var.tags}"
tags = var.tags
}

#
# case 3
# if(var.aws_sns_topic_arn == "" && var.aws_account_id != "")
#
resource "aws_cloudwatch_metric_alarm" "account_billing_alarm_to_new_sns" {
count = "${var.aws_sns_topic_arn == "" && var.aws_account_id != "" ? 1 : 0}"
count = var.aws_sns_topic_arn == "" && var.aws_account_id != "" ? 1 : 0
alarm_name = "account-billing-alarm-${lower(var.currency)}-${var.aws_env}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
Expand All @@ -72,23 +72,23 @@ resource "aws_cloudwatch_metric_alarm" "account_billing_alarm_to_new_sns" {
period = "28800"
statistic = "Maximum"
alarm_description = "Billing alarm account ${var.aws_account_id} >= US$ ${var.monthly_billing_threshold}"
threshold = "${var.monthly_billing_threshold}"
alarm_actions = ["${aws_sns_topic.sns_alert_topic.arn}"]
threshold = var.monthly_billing_threshold
alarm_actions = [aws_sns_topic.sns_alert_topic[0].arn]

dimensions = {
Currency = "${var.currency}"
LinkedAccount = "${var.aws_account_id}"
Currency = var.currency
LinkedAccount = var.aws_account_id
}

tags = "${var.tags}"
tags = var.tags
}

#
# case 4
# if(var.aws_sns_topic_arn == "" && var.aws_account_id == "")
#
resource "aws_cloudwatch_metric_alarm" "consolidated_accounts_billing_alarm_to_new_sns" {
count = "${var.aws_sns_topic_arn == "" && var.aws_account_id == "" ? 1 : 0}"
count = var.aws_sns_topic_arn == "" && var.aws_account_id == "" ? 1 : 0
alarm_name = "account-billing-alarm-${lower(var.currency)}-${var.aws_env}"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
Expand All @@ -97,12 +97,12 @@ resource "aws_cloudwatch_metric_alarm" "consolidated_accounts_billing_alarm_to_n
period = "28800"
statistic = "Maximum"
alarm_description = "Billing consolidated alarm >= US$ ${var.monthly_billing_threshold}"
threshold = "${var.monthly_billing_threshold}"
alarm_actions = ["${aws_sns_topic.sns_alert_topic.arn}"]
threshold = var.monthly_billing_threshold
alarm_actions = [aws_sns_topic.sns_alert_topic[0].arn]

dimensions = {
Currency = "${var.currency}"
Currency = var.currency
}

tags = "${var.tags}"
tags = var.tags
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "sns_topic_arn" {
description = "SNS Topic ARN to be subscribed to in order to delivery the clodwatch billing alarms"
value = "${var.aws_sns_topic_arn != "" ? var.aws_sns_topic_arn : join("", aws_sns_topic.sns_alert_topic.*.arn)}"
value = var.aws_sns_topic_arn != "" ? var.aws_sns_topic_arn : join("", aws_sns_topic.sns_alert_topic.*.arn)
}
7 changes: 6 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
#=============================#
variable "aws_env" {
description = "AWS environment you are deploying to. Will be appended to SNS topic and alarm name. (e.g. dev, stage, prod)"
type = string
}

variable "monthly_billing_threshold" {
description = "The threshold for which estimated monthly charges will trigger the metric alarm."
type = string
}

variable "currency" {
description = "Short notation for currency type (e.g. USD, CAD, EUR)"
type = string
default = "USD"
}

variable "aws_account_id" {
description = "AWS account id"
type = string
default = ""
}

Expand All @@ -24,14 +28,15 @@ variable "aws_account_id" {
#=============================#
variable "aws_sns_topic_arn" {
description = "If aws_sns_topic_enabled = false, then an existing AWS SNS topic ARN for the billing alert integration will be used"
type = string
default = ""
}

#=============================#
# TAGS #
#=============================#
variable "tags" {
type = "map"
type = map(string)
description = "A mapping of tags to assign to all resources"
default = {}
}

0 comments on commit c2e3ead

Please sign in to comment.