Skip to content

Commit 8144204

Browse files
committed
fix: give up on using null_resource to save on shipping a binary
Just ship the binary and use LFS instead. ¯\_(ツ)_/¯
1 parent 436430f commit 8144204

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
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

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: 4 additions & 12 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
}
@@ -94,13 +94,6 @@ 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 {
10598
name = "/${var.ssm_path}/DATADOG_API_KEY"
10699
description = "Datadog API Key"
@@ -120,8 +113,8 @@ resource aws_ssm_parameter datadog_app_key {
120113

121114
resource "aws_lambda_function" "slowlog_check" {
122115
function_name = "slowlog_check"
123-
filename = "${path.module}/slowlog_check.1.0.1.zip"
124-
source_code_hash = "Xn5bMbrSmVqdHMjchEAk/r2TJT6cHdQfIXRIaZo7vdQ="
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"
@@ -141,8 +134,7 @@ resource "aws_lambda_function" "slowlog_check" {
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 {

0 commit comments

Comments
 (0)