From 327055225826d734f939004d3d732b2f8eddc426 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Wed, 4 Nov 2020 18:33:33 +0100 Subject: [PATCH] feat: Updated version of Terraform AWS Lambda module to support multiple copies --- .pre-commit-config.yaml | 5 +++-- examples/cloudwatch-alerts-to-slack/main.tf | 12 ++++++++++-- examples/cloudwatch-alerts-to-slack/outputs.tf | 16 ++++++++-------- main.tf | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c40609f..8677870d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,9 @@ repos: - repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.43.0 + rev: v1.44.0 hooks: - id: terraform_fmt + - id: terraform_validate - id: terraform_docs - id: terraform_tflint args: @@ -20,6 +21,6 @@ repos: - '--args=--only=terraform_standard_module_structure' - '--args=--only=terraform_workspace_remote' - repo: git://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v3.3.0 hooks: - id: check-merge-conflict diff --git a/examples/cloudwatch-alerts-to-slack/main.tf b/examples/cloudwatch-alerts-to-slack/main.tf index 7dd563b9..a6114b8b 100644 --- a/examples/cloudwatch-alerts-to-slack/main.tf +++ b/examples/cloudwatch-alerts-to-slack/main.tf @@ -16,8 +16,16 @@ resource "aws_kms_ciphertext" "slack_url" { module "notify_slack" { source = "../../" + for_each = toset([ + "develop", + "release", + "test", + ]) + sns_topic_name = "slack-topic" + lambda_function_name = "notify_slack_${each.value}" + slack_webhook_url = aws_kms_ciphertext.slack_url.ciphertext_blob slack_channel = "aws-notification" slack_username = "reporter" @@ -43,9 +51,9 @@ resource "aws_cloudwatch_metric_alarm" "lambda_duration" { threshold = "5000" alarm_description = "Duration of notifying slack exceeds threshold" - alarm_actions = [module.notify_slack.this_slack_topic_arn] + alarm_actions = [module.notify_slack["develop"].this_slack_topic_arn] dimensions = { - FunctionName = module.notify_slack.notify_slack_lambda_function_name + FunctionName = module.notify_slack["develop"].notify_slack_lambda_function_name } } diff --git a/examples/cloudwatch-alerts-to-slack/outputs.tf b/examples/cloudwatch-alerts-to-slack/outputs.tf index 2137b5a6..0da0d553 100644 --- a/examples/cloudwatch-alerts-to-slack/outputs.tf +++ b/examples/cloudwatch-alerts-to-slack/outputs.tf @@ -1,39 +1,39 @@ output "this_sns_topic_arn" { description = "The ARN of the SNS topic from which messages will be sent to Slack" - value = module.notify_slack.this_slack_topic_arn + value = module.notify_slack["develop"].this_slack_topic_arn } output "lambda_iam_role_arn" { description = "The ARN of the IAM role used by Lambda function" - value = module.notify_slack.lambda_iam_role_arn + value = module.notify_slack["develop"].lambda_iam_role_arn } output "lambda_iam_role_name" { description = "The name of the IAM role used by Lambda function" - value = module.notify_slack.lambda_iam_role_name + value = module.notify_slack["develop"].lambda_iam_role_name } output "notify_slack_lambda_function_arn" { description = "The ARN of the Lambda function" - value = module.notify_slack.notify_slack_lambda_function_arn + value = module.notify_slack["develop"].notify_slack_lambda_function_arn } output "notify_slack_lambda_function_name" { description = "The name of the Lambda function" - value = module.notify_slack.notify_slack_lambda_function_name + value = module.notify_slack["develop"].notify_slack_lambda_function_name } output "notify_slack_lambda_function_invoke_arn" { description = "The ARN to be used for invoking Lambda function from API Gateway" - value = module.notify_slack.notify_slack_lambda_function_invoke_arn + value = module.notify_slack["develop"].notify_slack_lambda_function_invoke_arn } output "notify_slack_lambda_function_last_modified" { description = "The date Lambda function was last modified" - value = module.notify_slack.notify_slack_lambda_function_last_modified + value = module.notify_slack["develop"].notify_slack_lambda_function_last_modified } output "notify_slack_lambda_function_version" { description = "Latest published version of your Lambda function" - value = module.notify_slack.notify_slack_lambda_function_version + value = module.notify_slack["develop"].notify_slack_lambda_function_version } diff --git a/main.tf b/main.tf index 65a1e4b7..87a49413 100644 --- a/main.tf +++ b/main.tf @@ -67,7 +67,7 @@ resource "aws_sns_topic_subscription" "sns_notify_slack" { module "lambda" { source = "terraform-aws-modules/lambda/aws" - version = "1.18.0" + version = "1.27.0" create = var.create