Skip to content

Commit 7f25ddf

Browse files
committed
Merge branch 'feature/PI-670-billing_alarms' into release/2025-01-02
2 parents e7d929a + 4591c96 commit 7f25ddf

File tree

17 files changed

+303
-137
lines changed

17 files changed

+303
-137
lines changed

infrastructure/terraform/per_account/dev/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ JSON
2727
}
2828
}
2929

30+
module "billing_alarms" {
31+
source = "../modules/billing_alarms"
32+
project = local.project
33+
limit = var.budget_limit
34+
environment = terraform.workspace
35+
}
36+
3037
module "iam__api-gateway-to-cloudwatch" {
3138
source = "../modules/iam__api-gateway-to-cloudwatch"
3239
project = local.project

infrastructure/terraform/per_account/dev/terraform.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,17 @@ terraform {
1313
source = "hashicorp/aws"
1414
version = "~> 5.20.0"
1515
}
16+
null = {
17+
source = "hashicorp/null"
18+
version = "~> 3.0"
19+
}
20+
external = {
21+
source = "hashicorp/external"
22+
version = "~> 2.0"
23+
}
24+
local = {
25+
source = "hashicorp/local"
26+
version = "~> 2.0"
27+
}
1628
}
1729
}

infrastructure/terraform/per_account/dev/vars.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ variable "updated_date" {
2121
variable "workspace_type" {
2222
default = "PERSISTENT"
2323
}
24+
25+
variable "budget_limit" {
26+
default = "1050"
27+
type = string
28+
}

infrastructure/terraform/per_account/int/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ JSON
2727
}
2828
}
2929

30+
module "billing_alarms" {
31+
source = "../modules/billing_alarms"
32+
project = local.project
33+
limit = var.budget_limit
34+
environment = terraform.workspace
35+
}
36+
3037
module "iam__api-gateway-to-cloudwatch" {
3138
source = "../modules/iam__api-gateway-to-cloudwatch"
3239
project = local.project

infrastructure/terraform/per_account/int/vars.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ variable "updated_date" {
2121
variable "workspace_type" {
2222
default = "PERSISTENT"
2323
}
24+
25+
variable "budget_limit" {
26+
default = "385"
27+
type = string
28+
}

infrastructure/terraform/per_account/mgmt/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ JSON
2727
}
2828
}
2929

30+
module "billing_alarms" {
31+
source = "../modules/billing_alarms"
32+
project = local.project
33+
limit = var.budget_limit
34+
environment = terraform.workspace
35+
}
36+
3037
module "route53" {
3138
source = "./modules/route53"
3239
workspace = terraform.workspace

infrastructure/terraform/per_account/mgmt/vars.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ variable "updated_date" {
2121
variable "workspace_type" {
2222
default = "PERSISTENT"
2323
}
24+
25+
variable "budget_limit" {
26+
default = "450"
27+
type = string
28+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
resource "aws_ssm_parameter" "billing_alert_subscribers" {
2+
name = "${var.project}-billing-subscribers"
3+
type = "StringList"
4+
5+
}
6+
7+
data "aws_ssm_parameter" "billing_alert_subscribers" {
8+
name = aws_ssm_parameter.billing_alert_subscribers.name
9+
}
10+
11+
resource "aws_budgets_budget" "cpm_budget" {
12+
name = "${var.project}-monthly-budget-${var.environment}"
13+
budget_type = "COST"
14+
limit_amount = var.limit
15+
limit_unit = "USD"
16+
time_unit = "MONTHLY"
17+
18+
notification {
19+
comparison_operator = "GREATER_THAN"
20+
threshold = 50
21+
threshold_type = "PERCENTAGE"
22+
notification_type = "ACTUAL"
23+
subscriber_email_addresses = split(",", data.aws_ssm_parameter.billing_alert_subscribers.value)
24+
}
25+
26+
notification {
27+
comparison_operator = "GREATER_THAN"
28+
threshold = 75
29+
threshold_type = "PERCENTAGE"
30+
notification_type = "ACTUAL"
31+
subscriber_email_addresses = split(",", data.aws_ssm_parameter.billing_alert_subscribers.value)
32+
}
33+
34+
notification {
35+
comparison_operator = "GREATER_THAN"
36+
threshold = 90
37+
threshold_type = "PERCENTAGE"
38+
notification_type = "ACTUAL"
39+
subscriber_email_addresses = split(",", data.aws_ssm_parameter.billing_alert_subscribers.value)
40+
}
41+
42+
notification {
43+
comparison_operator = "GREATER_THAN"
44+
threshold = 100
45+
threshold_type = "PERCENTAGE"
46+
notification_type = "ACTUAL"
47+
subscriber_email_addresses = split(",", data.aws_ssm_parameter.billing_alert_subscribers.value)
48+
}
49+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
variable "limit" {
2+
type = string
3+
default = "1000"
4+
}
5+
6+
variable "project" {
7+
type = string
8+
}
9+
10+
variable "environment" {
11+
type = string
12+
default = "prod"
13+
}

infrastructure/terraform/per_account/prod/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ JSON
2727
}
2828
}
2929

30+
module "billing_alarms" {
31+
source = "../modules/billing_alarms"
32+
project = local.project
33+
limit = var.budget_limit
34+
environment = terraform.workspace
35+
}
36+
3037
module "iam__api-gateway-to-cloudwatch" {
3138
source = "../modules/iam__api-gateway-to-cloudwatch"
3239
project = local.project

0 commit comments

Comments
 (0)