-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
78 lines (65 loc) · 2.95 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## Provision the SNS topic for the budgets if required and notifications
module "notifications" {
source = "appvia/notifications/aws"
version = "2.0.0"
allowed_aws_services = [
"budgets.amazonaws.com",
"lambda.amazonaws.com",
]
create_sns_topic = var.create_sns_topic
sns_topic_name = var.sns_topic_name
enable_slack = local.enable_slack
slack = local.slack_configuration
tags = var.tags
}
## Iterate over the budgets and provision them
resource "aws_budgets_budget" "this" {
for_each = { for x in var.budgets : x.name => x }
name = each.value.name
budget_type = each.value.budget_type
limit_amount = each.value.limit_amount
tags = merge(var.tags, try(each.value.tags, {}))
limit_unit = lookup(each.value, "limit_unit", "USD")
time_period_start = lookup(each.value, "time_period_start", null)
time_period_end = lookup(each.value, "time_period_end", null)
time_unit = lookup(each.value, "time_unit", "MONTHLY")
dynamic "auto_adjust_data" {
for_each = lookup(each.value, "auto_adjust_data", null) != null ? try(tolist(each.value.auto_adjust_data), [
each.value.auto_adjust_data
]) : []
content {
auto_adjust_type = auto_adjust_data.value.auto_adjust_type
}
}
dynamic "cost_types" {
for_each = lookup(each.value, "cost_types", null) != null ? [each.value.cost_types] : []
content {
include_credit = lookup(cost_types.value, "include_credit", null)
include_discount = lookup(cost_types.value, "include_discount", null)
include_other_subscription = lookup(cost_types.value, "include_other_subscription", null)
include_recurring = lookup(cost_types.value, "include_recurring", null)
include_refund = lookup(cost_types.value, "include_refund", null)
include_subscription = lookup(cost_types.value, "include_subscription", null)
include_support = lookup(cost_types.value, "include_support", null)
include_tax = lookup(cost_types.value, "include_tax", null)
include_upfront = lookup(cost_types.value, "include_upfront", null)
use_blended = lookup(cost_types.value, "use_blended", null)
}
}
dynamic "cost_filter" {
for_each = each.value.cost_filter
content {
name = cost_filter.key
values = cost_filter.value.values
}
}
notification {
comparison_operator = each.value.notification.comparison_operator
notification_type = each.value.notification.notification_type
subscriber_email_addresses = var.notifications.email != null ? var.notifications.email.addresses : null
subscriber_sns_topic_arns = [module.notifications.sns_topic_arn]
threshold = each.value.notification.threshold
threshold_type = each.value.notification.threshold_type
}
depends_on = [module.notifications]
}