You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78-9Lines changed: 78 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@
28
28
29
29
-->
30
30
31
-
Terraform module to manage[AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html).
31
+
Terraform module to create[AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html) and an associated SNS topic and Lambda function to send notifications to Slack.
32
32
33
33
---
34
34
@@ -109,11 +109,60 @@ module "label" {
109
109
name = "example"
110
110
}
111
111
112
-
module "example" {
112
+
locals {
113
+
budgets = [
114
+
{
115
+
name = "budget-ec2-monthly"
116
+
budget_type = "COST"
117
+
limit_amount = "1200"
118
+
limit_unit = "USD"
119
+
time_period_end = "2087-06-15_00:00"
120
+
time_unit = "MONTHLY"
121
+
122
+
cost_filter = {
123
+
Service = ["Amazon Elastic Compute Cloud - Compute"]
124
+
}
125
+
126
+
notification = {
127
+
comparison_operator = "GREATER_THAN"
128
+
threshold = "100"
129
+
threshold_type = "PERCENTAGE"
130
+
notification_type = "FORECASTED"
131
+
}
132
+
},
133
+
{
134
+
name = "100-total-monthly"
135
+
budget_type = "COST"
136
+
limit_amount = "100"
137
+
limit_unit = "USD"
138
+
time_unit = "MONTHLY"
139
+
},
140
+
{
141
+
name = "s3-3GB-limit-monthly"
142
+
budget_type = "USAGE"
143
+
limit_amount = "3"
144
+
limit_unit = "GB"
145
+
time_unit = "MONTHLY"
146
+
}
147
+
]
148
+
}
149
+
150
+
module "budgets" {
113
151
source = "cloudposse/budgets/aws"
114
152
# Cloud Posse recommends pinning every module to a specific version
115
153
# version = "x.x.x"
116
154
155
+
budgets = local.budgets
156
+
157
+
# create an SNS topic and lambda for Slack notifications
158
+
notifications_enabled = true
159
+
slack_webhook_url = "https://slack-webhook-url"
160
+
slack_username = "AWS Budgets"
161
+
slack_channel = "notifications"
162
+
163
+
# encrypt SNS topic, this also creates a KMS CMK that allows `budgets.amazonaws.com` to use it
|[aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity)| data source |
221
+
|[aws_iam_policy_document.kms_key_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document)| data source |
168
222
169
223
## Inputs
170
224
171
225
| Name | Description | Type | Default | Required |
| <aname="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map)| Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. |`map(string)`|`{}`| no |
174
228
| <aname="input_attributes"></a> [attributes](#input\_attributes)| ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. |`list(string)`|`[]`| no |
229
+
| <aname="input_budgets"></a> [budgets](#input\_budgets)| A list of Budgets to be managed by this module, see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/budgets_budget#argument-reference<br>for a list of possible attributes. For a more specific example, see `examples/complete/fixtures.us-east-2.tfvars` in this repository. |`any`|`[]`| no |
175
230
| <aname="input_context"></a> [context](#input\_context)| Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. |`any`| <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
176
231
| <aname="input_delimiter"></a> [delimiter](#input\_delimiter)| Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. |`string`|`null`| no |
177
232
| <aname="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats)| Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). |`any`|`{}`| no |
178
233
| <aname="input_enabled"></a> [enabled](#input\_enabled)| Set to false to prevent the module from creating any resources |`bool`|`null`| no |
234
+
| <aname="input_encryption_enabled"></a> [encryption\_enabled](#input\_encryption\_enabled)| Whether or not to use encryption. If set to `true` and no custom value for KMS key (kms\_master\_key\_id) is provided, a KMS key is created. |`bool`|`true`| no |
179
235
| <aname="input_environment"></a> [environment](#input\_environment)| ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' |`string`|`null`| no |
180
-
| <aname="input_example"></a> [example](#input\_example)| Example variable |`string`|`"hello world"`| no |
181
236
| <aname="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit)| Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. |`number`|`null`| no |
237
+
| <aname="input_kms_enable_key_rotation"></a> [kms\_enable\_key\_rotation](#input\_kms\_enable\_key\_rotation)| Specifies whether key rotation is enabled |`bool`|`true`| no |
238
+
| <aname="input_kms_key_deletion_window_in_days"></a> [kms\_key\_deletion\_window\_in\_days](#input\_kms\_key\_deletion\_window\_in\_days)| Duration in days after which the key is deleted after destruction of the resources |`number`|`7`| no |
239
+
| <aname="input_kms_master_key_id"></a> [kms\_master\_key\_id](#input\_kms\_master\_key\_id)| The ID of a KMS CMK to be used for encryption (see https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-sns-policy.html#protect-sns-sse for appropriate key policies). |`string`|`null`| no |
182
240
| <aname="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case)| Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. |`string`|`null`| no |
183
241
| <aname="input_label_order"></a> [label\_order](#input\_label\_order)| The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. |`list(string)`|`null`| no |
184
242
| <aname="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case)| Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. |`string`|`null`| no |
185
243
| <aname="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags)| Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. |`set(string)`| <pre>[<br> "default"<br>]</pre> | no |
186
244
| <aname="input_name"></a> [name](#input\_name)| ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. |`string`|`null`| no |
187
245
| <aname="input_namespace"></a> [namespace](#input\_namespace)| ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique |`string`|`null`| no |
246
+
| <aname="input_notifications_enabled"></a> [notifications\_enabled](#input\_notifications\_enabled)| Whether or not to setup Slack notifications. Set to `true` to create an SNS topic and Lambda function to send alerts to Slack. |`bool`|`false`| no |
188
247
| <aname="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars)| Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. |`string`|`null`| no |
248
+
| <aname="input_slack_channel"></a> [slack\_channel](#input\_slack\_channel)| The name of the channel in Slack for notifications. Only used when `notifications_enabled` is `true`|`string`|`""`| no |
249
+
| <aname="input_slack_username"></a> [slack\_username](#input\_slack\_username)| The username that will appear on Slack messages. Only used when `notifications_enabled` is `true`|`string`|`""`| no |
250
+
| <aname="input_slack_webhook_url"></a> [slack\_webhook\_url](#input\_slack\_webhook\_url)| The URL of Slack webhook. Only used when `notifications_enabled` is `true`|`string`|`""`| no |
189
251
| <aname="input_stage"></a> [stage](#input\_stage)| ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' |`string`|`null`| no |
190
252
| <aname="input_tags"></a> [tags](#input\_tags)| Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. |`map(string)`|`{}`| no |
191
253
| <aname="input_tenant"></a> [tenant](#input\_tenant)| ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for |`string`|`null`| no |
@@ -194,9 +256,16 @@ Available targets:
194
256
195
257
| Name | Description |
196
258
|------|-------------|
197
-
| <aname="output_example"></a> [example](#output\_example)| Example output |
198
-
| <aname="output_id"></a> [id](#output\_id)| ID of the created example |
199
-
| <aname="output_random"></a> [random](#output\_random)| Stable random number for this example |
259
+
| <aname="output_budgets"></a> [budgets](#output\_budgets)| List of Budgets that are being managed by this module |
260
+
| <aname="output_kms_key_arn"></a> [kms\_key\_arn](#output\_kms\_key\_arn)| ARN of the KMS CMK that was created specifically for budget notifications |
261
+
| <aname="output_kms_key_id"></a> [kms\_key\_id](#output\_kms\_key\_id)| ID of the KMS CMK that is used for SNS notifications |
262
+
| <aname="output_lambda_cloudwatch_log_group_arn"></a> [lambda\_cloudwatch\_log\_group\_arn](#output\_lambda\_cloudwatch\_log\_group\_arn)| The ARN of the Log Group used by the Slack Notify Lambda |
263
+
| <aname="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn)| The ARN of the Lambda function |
264
+
| <aname="output_lambda_function_invoke_arn"></a> [lambda\_function\_invoke\_arn](#output\_lambda\_function\_invoke\_arn)| The ARN to be used for invoking lambda function from API Gateway |
265
+
| <aname="output_lambda_function_name"></a> [lambda\_function\_name](#output\_lambda\_function\_name)| The name of the Lambda function |
266
+
| <aname="output_lambda_iam_role_arn"></a> [lambda\_iam\_role\_arn](#output\_lambda\_iam\_role\_arn)| The ARN of the IAM role used by Lambda function |
267
+
| <aname="output_sns_topic_arn"></a> [sns\_topic\_arn](#output\_sns\_topic\_arn)| ARN of the SNS topic created for notifications |
268
+
| <aname="output_sns_topic_name"></a> [sns\_topic\_name](#output\_sns\_topic\_name)| The name of the SNS topic created for notifications |
Copy file name to clipboardExpand all lines: README.yaml
+51-2Lines changed: 51 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ references:
48
48
49
49
# Short description of this project
50
50
description: |-
51
-
Terraform module to manage [AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html).
51
+
Terraform module to create [AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html) and an associated SNS topic and Lambda function to send notifications to Slack.
52
52
53
53
# Introduction to the project
54
54
# introduction: |-
@@ -72,11 +72,60 @@ usage: |-
72
72
name = "example"
73
73
}
74
74
75
-
module "example" {
75
+
locals {
76
+
budgets = [
77
+
{
78
+
name = "budget-ec2-monthly"
79
+
budget_type = "COST"
80
+
limit_amount = "1200"
81
+
limit_unit = "USD"
82
+
time_period_end = "2087-06-15_00:00"
83
+
time_unit = "MONTHLY"
84
+
85
+
cost_filter = {
86
+
Service = ["Amazon Elastic Compute Cloud - Compute"]
87
+
}
88
+
89
+
notification = {
90
+
comparison_operator = "GREATER_THAN"
91
+
threshold = "100"
92
+
threshold_type = "PERCENTAGE"
93
+
notification_type = "FORECASTED"
94
+
}
95
+
},
96
+
{
97
+
name = "100-total-monthly"
98
+
budget_type = "COST"
99
+
limit_amount = "100"
100
+
limit_unit = "USD"
101
+
time_unit = "MONTHLY"
102
+
},
103
+
{
104
+
name = "s3-3GB-limit-monthly"
105
+
budget_type = "USAGE"
106
+
limit_amount = "3"
107
+
limit_unit = "GB"
108
+
time_unit = "MONTHLY"
109
+
}
110
+
]
111
+
}
112
+
113
+
module "budgets" {
76
114
source = "cloudposse/budgets/aws"
77
115
# Cloud Posse recommends pinning every module to a specific version
78
116
# version = "x.x.x"
79
117
118
+
budgets = local.budgets
119
+
120
+
# create an SNS topic and lambda for Slack notifications
121
+
notifications_enabled = true
122
+
slack_webhook_url = "https://slack-webhook-url"
123
+
slack_username = "AWS Budgets"
124
+
slack_channel = "notifications"
125
+
126
+
# encrypt SNS topic, this also creates a KMS CMK that allows `budgets.amazonaws.com` to use it
0 commit comments