From a15c328188250e8121796ed055aa0eedecb25f85 Mon Sep 17 00:00:00 2001 From: Rohith Jayawardene Date: Fri, 26 Apr 2024 18:04:38 +0100 Subject: [PATCH] feat: adding the ability source the username from the configuration (#5) --- README.md | 12 ++++++++++++ locals.tf | 2 ++ main.tf | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba712b0..0513f1d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,18 @@ The `terraform-docs` utility is used to generate this README. Follow the below s 2. Fetch the `terraform-docs` binary (https://terraform-docs.io/user-guide/installation/) 3. Run `terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject .` +## Using Secrets Manager + +The `slack` configuration can be sourced from AWS Secrets Manager, using the `var.slack.secret_name`. The secret should be a JSON object reassembling the `slack` configuration. + +```json +{ + "channel": "#channel", + "username": "username", + "webhook_url": "https://hooks.slack.com/services/..." +} +``` + ## Requirements diff --git a/locals.tf b/locals.tf index e8e2a0a..0680163 100644 --- a/locals.tf +++ b/locals.tf @@ -22,4 +22,6 @@ locals { slack_webhook_url = local.enable_slack_secret ? jsondecode(data.aws_secretsmanager_secret_version.slack[0].secret_string)["webhook_url"] : try(var.slack.webhook_url, null) ## The slack channel to post to slack_channel = local.enable_slack_secret ? jsondecode(data.aws_secretsmanager_secret_version.slack[0].secret_string)["channel"] : try(var.slack.channel, null) + ## slack_username to use + slack_username = local.enable_slack_secret ? jsondecode(data.aws_secretsmanager_secret_version.slack[0].secret_string)["username"] : try(var.slack.username, null) } diff --git a/main.tf b/main.tf index 885d919..37984bc 100644 --- a/main.tf +++ b/main.tf @@ -47,7 +47,7 @@ module "slack" { lambda_function_tags = var.tags recreate_missing_package = false slack_channel = local.slack_channel - slack_username = var.slack.username + slack_username = local.slack_username slack_webhook_url = local.slack_webhook_url sns_topic_name = var.sns_topic_name tags = var.tags