File tree Expand file tree Collapse file tree 5 files changed +78
-1
lines changed
infrastructure/terraform/per_account
scripts/infrastructure/policies Expand file tree Collapse file tree 5 files changed +78
-1
lines changed Original file line number Diff line number Diff line change @@ -101,3 +101,16 @@ module "vpc" {
101
101
resource "aws_route53_zone" "dev-ns" {
102
102
name = " api.cpm.dev.national.nhs.uk"
103
103
}
104
+
105
+ module "billing-alert" {
106
+ source = " ../modules/billing-alert"
107
+ prefix = " ${ local . project } --${ terraform . workspace } "
108
+ metric_name = " EstimatedCharges"
109
+ metric_statistic = " Maximum"
110
+ metric_number_of_evaluation_periods = 1
111
+ threshold_dollars = 20
112
+ recipients = [] # get from secrets
113
+ tags = {
114
+ Name = " ${ local . project } --${ replace (terraform. workspace , " _" , " -" )} "
115
+ }
116
+ }
Original file line number Diff line number Diff line change
1
+ resource "aws_cloudwatch_metric_alarm" "account_billing_alarm" {
2
+ alarm_name = " ${ var . prefix } --billing-alarm--${ var . threshold_dollars } --${ var . metric_name } "
3
+ alarm_description = " Billing Alarm of ${ var . threshold_dollars } USD (${ var . metric_name } )"
4
+ namespace = " AWS/Billing"
5
+ tags = var. tags
6
+
7
+ # If statistic(metric) >= threshold in dollars then trigger topic
8
+ metric_name = var. metric_name
9
+ comparison_operator = " GreaterThanOrEqualToThreshold"
10
+ threshold = var. threshold_dollars
11
+ alarm_actions = [aws_sns_topic . sns_alert_topic . arn ]
12
+
13
+ # Evaluate a new statistic(metric) every 6 hours
14
+ period = 6 * 60 * 60 # seconds
15
+
16
+ # Calculate statistic(metric) over the specified number evaluation periods
17
+ statistic = var. metric_statistic
18
+ evaluation_periods = var. metric_number_of_evaluation_periods
19
+ datapoints_to_alarm = 1
20
+ }
21
+
22
+
23
+ resource "aws_sns_topic" "sns_alert_topic" {
24
+ name = " ${ var . prefix } --billing-alarm-${ var . threshold_dollars } --${ var . metric_name } "
25
+ tags = var. tags
26
+ }
27
+
28
+ resource "aws_sns_topic_subscription" "email_target" {
29
+ count = length (var. recipients )
30
+ topic_arn = aws_sns_topic. sns_alert_topic . arn
31
+ protocol = " email"
32
+ endpoint = var. recipients [count . index ]
33
+ }
Original file line number Diff line number Diff line change
1
+ variable "prefix" {
2
+ type = string
3
+ }
4
+
5
+ variable "threshold_dollars" {
6
+ type = number
7
+ }
8
+ variable "recipients" {
9
+ type = list (string )
10
+ }
11
+
12
+ variable "metric_name" {
13
+ type = string
14
+ }
15
+
16
+ variable "metric_number_of_evaluation_periods" {
17
+ type = number
18
+ }
19
+
20
+ variable "metric_statistic" {
21
+ type = string
22
+ }
23
+
24
+ variable "tags" {
25
+
26
+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ urllib3 = "<3"
27
27
orjson = " ^3.9.15"
28
28
attrs = " ^24.2.0"
29
29
locust = " ^2.29.1"
30
+ gevent = " <24.10.2"
30
31
31
32
[tool .poetry .group .dev .dependencies ]
32
33
pre-commit = " ^4.0.0"
Original file line number Diff line number Diff line change 256
256
" acm:ListCertificates" ,
257
257
" resource-groups:ListGroups" ,
258
258
" lambda:ListEventSourceMappings" ,
259
- " iam:ListRoles"
259
+ " iam:ListRoles" ,
260
+ " sns:CreateTopic" ,
261
+ " sns:TagResource" ,
262
+ " sns:SetTopicAttributes" ,
263
+ " sns:GetTopicAttributes"
260
264
],
261
265
"Resource" : [" *" ]
262
266
}
You can’t perform that action at this time.
0 commit comments