Skip to content

Commit

Permalink
feat: Add tags to all resources
Browse files Browse the repository at this point in the history
  • Loading branch information
baolsen committed Dec 14, 2022
1 parent 0ef757b commit d86018e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ See `examples` dropdown on Terraform Cloud, or [browse here](/examples/).
| <a name="input_red_threshold"></a> [red\_threshold](#input\_red\_threshold) | Percentage exceeded threshold to send a red alert and notify the slack channel | `string` | `"50"` | no |
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | List of VPC security group IDs associated with the Lambda function. | `list(string)` | `[]` | no |
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | List of VPC subnet IDs associated with the Lambda function. | `list(string)` | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to the resources. | `map(string)` | `{}` | no |
| <a name="input_webhook_type"></a> [webhook\_type](#input\_webhook\_type) | Either "slack" or "teams". | `string` | `"slack"` | no |
| <a name="input_webhook_urls"></a> [webhook\_urls](#input\_webhook\_urls) | Webhook URLs to receive daily cost notifications on either Slack or Teams | `list(string)` | n/a | yes |

Expand Down
2 changes: 2 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ resource "aws_iam_policy" "cost_explorer_access_policy" {
}]
)
})

tags = var.tags
}
14 changes: 9 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ resource "aws_cloudwatch_event_target" "billing_notifier_lambda_event_target" {
data "aws_caller_identity" "current" {}

resource "aws_lambda_permission" "billing_notifier_lambda_permission" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = module.billing_notifier_lambda.lambda_function.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.billing_notifier_lambda_event_rule.arn

statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
principal = "events.amazonaws.com"

source_arn = aws_cloudwatch_event_rule.billing_notifier_lambda_event_rule.arn
source_account = data.aws_caller_identity.current.account_id

depends_on = [
module.billing_notifier_lambda
]
source_account = data.aws_caller_identity.current.account_id
}

locals {
Expand Down Expand Up @@ -52,6 +55,7 @@ module "billing_notifier_lambda" {
runtime = "python3.7"

timeout = 300
tags = var.tags

####################################
# Build
Expand Down
2 changes: 2 additions & 0 deletions sns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ resource "aws_sns_topic" "cost_notifier" {
name = "${var.naming_prefix}-costnotifier"

kms_master_key_id = coalesce(var.kms_key_arn, "alias/aws/sns")

tags = var.tags
}

resource "aws_sns_topic_subscription" "cost_notifier" {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ variable "lambda_description" {
default = "This function sends AWS cost notifications. Source: github.com/cloudandthings/terraform-aws-costnotifier"
}

variable "tags" {
description = "A mapping of tags to assign to the resources."
type = map(string)
default = {}
}

#---------------------------------------------------------------------------------------------------
# Notifications
#---------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit d86018e

Please sign in to comment.