Skip to content

Commit e890c3e

Browse files
authored
Merge pull request #8 from scribd/alpha
Release 1.3.0
2 parents 436430f + 2cfe00b commit e890c3e

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip filter=lfs diff=lfs merge=lfs -text

.github/workflows/validate_and_release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
jobs:
88
terraform:
99
name: 'Terraform'
10-
id: terraform
1110
runs-on: ubuntu-latest
1211
steps:
1312
- name: 'Checkout'

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# [1.3.0-alpha.1](https://github.com/scribd/terraform-elasticache-slowlog-to-datadog/compare/v1.2.1...v1.3.0-alpha.1) (2020-04-30)
2+
3+
4+
### Bug Fixes
5+
6+
* give up on using null_resource to save on shipping a binary ([8144204](https://github.com/scribd/terraform-elasticache-slowlog-to-datadog/commit/814420446e1bad24edc00867659550b0e3a98370))
7+
8+
9+
### Features
10+
11+
* enable multiple invocations of the module in a single account ([9a7a764](https://github.com/scribd/terraform-elasticache-slowlog-to-datadog/commit/9a7a7648c3929e3e3a9f0c06a6f0b03cd644eca8))
12+
113
## [1.2.1](https://github.com/scribd/terraform-elasticache-slowlog-to-datadog/compare/v1.2.0...v1.2.1) (2020-04-29)
214

315

files/slowlog_check.1.0.1.zip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5e7e5b31bad2995a9d1cc8dc844024febd93253e9c1dd41f217448699a3bbdd4
3+
size 345268

locals.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
locals {
2+
slowlog_check_archive_basename = "slowlog_check.1.0.1.zip"
3+
slowlog_check_archive_hash = "Xn5bMbrSmVqdHMjchEAk/r2TJT6cHdQfIXRIaZo7vdQ=" # generated with filebase64sha256()
4+
slowlog_check_archive_path = "${path.module}/files/${local.slowlog_check_archive_basename}"
5+
6+
search_replication_group = "(?P<first>[0-9A-Za-z_-]+)\\.(?P<second>[0-9A-Za-z_-]+)\\.{0,1}(?P<third>[0-9A-Za-z_]*)\\.(?P<region>[0-9A-Za-z_-]+)\\.cache\\.amazonaws\\.com:{0,1}(?P<port>[0-9]*)"
7+
parsed_elasticache_endpoint = regex(local.search_replication_group, var.elasticache_endpoint)
8+
# https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Endpoints.html
9+
replication_group = contains(["clustercfg", "master"], local.parsed_elasticache_endpoint["first"]) ? local.parsed_elasticache_endpoint["second"] : local.parsed_elasticache_endpoint["first"]
10+
}

main.tf

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource aws_cloudwatch_event_rule slowlog_check {
22
name_prefix = "slowlog_check_every_minute"
3-
description = "Check for slowlogs every five minutes"
3+
description = "Check for slowlogs every minute"
44
schedule_expression = "rate(1 minute)"
55
tags = var.tags
66
}
@@ -20,7 +20,7 @@ resource aws_lambda_permission slowlog_check {
2020

2121

2222
resource aws_iam_role slowlog_check {
23-
name = "slowlog_check"
23+
name_prefix = "slowlog_check"
2424

2525
assume_role_policy = <<EOF
2626
{
@@ -40,7 +40,7 @@ EOF
4040
}
4141

4242
resource aws_iam_policy slowlog_check {
43-
name = "slowlog_check"
43+
name_prefix = "slowlog_check"
4444
path = "/"
4545
description = "This IAM policy allows the slowlog_check to run"
4646

@@ -94,23 +94,16 @@ resource aws_security_group egress {
9494
tags = var.tags
9595
}
9696

97-
resource null_resource get_slowlog_check_archive {
98-
provisioner local-exec {
99-
command = "wget https://github.com/scribd/elasticache-slowlog-to-datadog/releases/download/v1.0.1/slowlog_check.1.0.1.zip"
100-
working_dir = path.module
101-
}
102-
}
103-
10497
resource aws_ssm_parameter datadog_api_key {
105-
name = "/${var.ssm_path}/DATADOG_API_KEY"
98+
name = "/${var.ssm_path}/${local.replication_group}/DATADOG_API_KEY"
10699
description = "Datadog API Key"
107100
tags = var.tags
108101
type = "SecureString"
109102
value = var.datadog_api_key
110103
}
111104

112105
resource aws_ssm_parameter datadog_app_key {
113-
name = "/${var.ssm_path}/DATADOG_APP_KEY"
106+
name = "/${var.ssm_path}/${local.replication_group}/DATADOG_APP_KEY"
114107
description = "Datadog App Key"
115108
tags = var.tags
116109
type = "SecureString"
@@ -119,9 +112,9 @@ resource aws_ssm_parameter datadog_app_key {
119112

120113

121114
resource "aws_lambda_function" "slowlog_check" {
122-
function_name = "slowlog_check"
123-
filename = "${path.module}/slowlog_check.1.0.1.zip"
124-
source_code_hash = "Xn5bMbrSmVqdHMjchEAk/r2TJT6cHdQfIXRIaZo7vdQ="
115+
function_name = "slowlog_check_for_${local.replication_group}"
116+
filename = local.slowlog_check_archive_path
117+
source_code_hash = local.slowlog_check_archive_hash
125118
role = aws_iam_role.slowlog_check.arn
126119
handler = "lambda_function.lambda_handler"
127120
runtime = "ruby2.5"
@@ -134,15 +127,14 @@ resource "aws_lambda_function" "slowlog_check" {
134127
environment {
135128
variables = {
136129
REDIS_HOST = var.elasticache_endpoint
137-
SSM_PATH = "${var.ssm_path}"
130+
SSM_PATH = "${var.ssm_path}/${local.replication_group}"
138131
NAMESPACE = var.namespace
139132
ENV = var.env
140133
METRICNAME = var.metric_name
141134
}
142135
}
143136

144-
tags = var.tags
145-
depends_on = [null_resource.get_slowlog_check_archive]
137+
tags = var.tags
146138
}
147139

148140
resource aws_lambda_function_event_invoke_config slowlog_check {

vars.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ variable metric_name {
3939
}
4040

4141
variable ssm_path {
42-
description = "Custom SSM path to provision Datadog access ID's in. Leading slash ommitted."
42+
description = "Custom SSM path to provision Datadog access ID's in. Leading slash ommitted. The final SSM paths will look like: `/$ssm_path/$replication_group/DATADOG_API_KEY`"
4343
default = "slowlog_check"
4444
}
4545

0 commit comments

Comments
 (0)