Skip to content

Commit 26ed834

Browse files
authored
Add notification service slack support (#179)
* Add notification service slack support * Fix slack api key secret creation
1 parent 667ac97 commit 26ed834

8 files changed

Lines changed: 56 additions & 8 deletions

File tree

templates/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ apply-secrets:
2828
aws secretsmanager describe-secret --secret-id "$(PROJECT)-$(ENVIRONMENT)-rds-<% index .Params `randomSeed` %>" > /dev/null 2>&1 || ( \
2929
cd terraform/bootstrap/secrets && \
3030
terraform init && \
31-
terraform apply $(AUTO_APPROVE) --var "sendgrid_api_key=${sendgridApiKey}" && \
31+
terraform apply $(AUTO_APPROVE) --var "sendgrid_api_key=${sendgridApiKey}" --var "slack_api_key=${notificationServiceSlackApiKey}"&& \
3232
rm ./terraform.tfstate )
3333

3434
apply-shared-env:

templates/kubernetes/terraform/environments/prod/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module "kubernetes" {
8282
# This domain or address must be verified by the mail provider (Sendgrid, SES, etc.)
8383
user_auth_mail_from_address = "noreply@${local.domain_name}"
8484

85-
notification_service_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
85+
notification_service_enabled = <%if eq (index .Params `notificationServiceEnabled`) "yes" %>true<% else %>false<% end %>
8686
notification_service_highly_available = true
8787

8888
cache_store = "<% index .Params `cacheStore` %>"

templates/kubernetes/terraform/environments/stage/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module "kubernetes" {
8181
# This domain or address must be verified by the mail provider (Sendgrid, SES, etc.)
8282
user_auth_mail_from_address = "noreply@${local.domain_name}"
8383

84-
notification_service_enabled = <%if eq (index .Params `sendgridApiKey`) "" %>false<% else %>true<% end %>
84+
notification_service_enabled = <%if eq (index .Params `notificationServiceEnabled`) "yes" %>true<% else %>false<% end %>
8585
notification_service_highly_available = false
8686

8787
cache_store = "<% index .Params `cacheStore` %>"

templates/kubernetes/terraform/modules/kubernetes/cert_manager.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
cert_manager_version = "1.0.4"
2+
cert_manager_version = "1.1.0"
33
cluster_issuer_name = var.cert_manager_use_production_acme_environment ? "clusterissuer-letsencrypt-production" : "clusterissuer-letsencrypt-staging"
44
cert_manager_acme_server = var.cert_manager_use_production_acme_environment ? "https://acme-v02.api.letsencrypt.org/directory" : "https://acme-staging-v02.api.letsencrypt.org/directory"
55
}

templates/kubernetes/terraform/modules/kubernetes/notification_service.tf

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
locals {
2-
sendgrid_api_key_secret_name = "${var.project}-sendgrid-${var.random_seed}" # Created in terraform/bootstrap/secrets
2+
# Created in terraform/bootstrap/secrets
3+
sendgrid_api_key_secret_name = "${var.project}-sendgrid-${var.random_seed}"
4+
slack_api_key_secret_name = "${var.project}-slack-${var.random_seed}"
35
}
46

57
data "aws_secretsmanager_secret" "sendgrid_api_key" {
@@ -11,6 +13,15 @@ data "aws_secretsmanager_secret_version" "sendgrid_api_key" {
1113
secret_id = data.aws_secretsmanager_secret.sendgrid_api_key[0].id
1214
}
1315

16+
data "aws_secretsmanager_secret" "slack_api_key" {
17+
count = var.notification_service_enabled ? 1 : 0
18+
name = local.slack_api_key_secret_name
19+
}
20+
data "aws_secretsmanager_secret_version" "slack_api_key" {
21+
count = var.notification_service_enabled ? 1 : 0
22+
secret_id = data.aws_secretsmanager_secret.slack_api_key[0].id
23+
}
24+
1425
resource "kubernetes_namespace" "notification_service" {
1526
count = var.notification_service_enabled ? 1 : 0
1627
metadata {
@@ -24,14 +35,20 @@ resource "helm_release" "notification_service" {
2435
name = "zero-notification-service"
2536
repository = "https://commitdev.github.io/zero-notification-service/"
2637
chart = "zero-notification-service"
27-
version = "0.0.4"
38+
version = "0.0.5"
2839
namespace = kubernetes_namespace.notification_service[0].metadata[0].name
2940

3041
set {
3142
name = "application.structuredLogging"
3243
value = "true"
3344
}
3445

46+
# Uncomment to set the image tag of the application to use separately from the chart version
47+
# set {
48+
# name = "image.tag"
49+
# value = "0.0.0"
50+
# }
51+
3552
set {
3653
name = "autoscaling.enabled"
3754
value = var.notification_service_highly_available ? "true" : "false" # If false, deployment replicas will be set to 1 and the replica options below will be ignored
@@ -45,9 +62,14 @@ resource "helm_release" "notification_service" {
4562
value = var.notification_service_highly_available ? "4" : "2"
4663
}
4764

48-
# This will become a secret provided as an env var
65+
# These will become secrets provided as env vars
4966
set_sensitive {
5067
name = "application.sendgridApiKey"
5168
value = data.aws_secretsmanager_secret_version.sendgrid_api_key[0].secret_string
5269
}
70+
71+
set_sensitive {
72+
name = "application.slackApiKey"
73+
value = data.aws_secretsmanager_secret_version.slack_api_key[0].secret_string
74+
}
5375
}

templates/terraform/bootstrap/secrets/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ module "sendgrid_api_key" {
4343
value = var.sendgrid_api_key
4444
tags = map("sendgrid", local.project)
4545
}
46+
47+
module "slack_api_key" {
48+
count = <%if eq (index .Params `notificationServiceSlackApiKey`) "" %>0<% else %>1<% end %>
49+
source = "commitdev/zero/aws//modules/secret"
50+
version = "0.0.2"
51+
52+
name = "${local.project}-slack-<% index .Params `randomSeed` %>"
53+
type = "string"
54+
value = var.slack_api_key
55+
tags = map("slack", local.project)
56+
}

templates/terraform/bootstrap/secrets/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ variable "sendgrid_api_key" {
22
description = "The Sendgrid API key to use for mailing, if necessary"
33
default = ""
44
}
5+
6+
variable "slack_api_key" {
7+
description = "The Slack API key to use with the notification service, if necessary"
8+
default = ""
9+
}

zero-module.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,19 @@ parameters:
8282
options:
8383
- "none"
8484
- "prometheus"
85+
- field: notificationServiceEnabled
86+
label: "Install the Zero Notification Service in your cluster?"
87+
info: Provides easy notification capability through email, slack, etc. - https://github.com/commitdev/zero-notification-service
88+
default: yes
89+
options:
90+
- "yes"
91+
- "no"
8592
- field: sendgridApiKey
8693
label: "API key to setup email integration (optional: leave blank to opt-out of Sendgrid setup)"
87-
info: Signup at https://signup.sendgrid.com or create an API key from https://app.sendgrid.com/settings/api_keys. Sendgrid is an email delivery service enabling transactional email sending and more.
94+
info: Signup at https://signup.sendgrid.com or create an API key at https://app.sendgrid.com/settings/api_keys - Sendgrid is an email delivery service enabling transactional email sending and more.
95+
- field: notificationServiceSlackApiKey
96+
label: "API key of your Slack bot if you want to use Slack with the Zero Notification Service. Leave blank if not applicable."
97+
info: See https://slack.com/intl/en-ca/help/articles/215770388-Create-and-regenerate-API-tokens
8898
- field: accountId
8999
label: AWS Account ID
90100
execute: aws sts get-caller-identity --query "Account" | tr -d '"'

0 commit comments

Comments
 (0)