Skip to content

Commit 66474cc

Browse files
Merge pull request #1 from seanturner026/go-mod-fix
Go mod fix
2 parents dd26405 + 7540d87 commit 66474cc

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Full example(s) leveraging this module is contained in the [examples](https://gi
1616

1717
```hcl
1818
module "eventbridge_debug_logger" {
19-
source = "git@github.com:seanturner026/terraform-module-eventbridge-debug-logger.git"
19+
source = "github.com/seanturner026/terraform-module-eventbridge-debug-logger.git"
2020
2121
name = "eventbridge_debug_logger"
2222
service_name = "ec2"

locals.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
locals {
2-
service_name = replace(var.service_name, "-", "_")
2+
main_module_name = split(".terraform/modules/", path.module)[1]
3+
main_module_path = "./.terraform/modules/${local.main_module_name}"
4+
service_name = replace(var.service_name, "-", "_")
35

46
lambdas = {
57
events_logger = {

r_lambda.tf

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
resource "null_resource" "lambda_build" {
2-
for_each = local.lambdas
3-
4-
triggers = {
5-
binary_exists = local.null.lambda_binary_exists[each.key]
6-
7-
main = join("", [
8-
for file in fileset("${path.module}/lambdas/cmd/${each.key}", "*.go") : filebase64("${path.module}/lambdas/cmd/${each.key}/${file}")
9-
])
10-
}
11-
12-
provisioner "local-exec" {
13-
command = "export GO111MODULE=on"
14-
}
15-
16-
provisioner "local-exec" {
17-
command = "GOOS=linux go build -ldflags '-s -w' -o ${path.module}/lambdas/bin/${each.key} ${path.module}/lambdas/cmd/${each.key}/."
18-
}
19-
}
20-
211
resource "aws_lambda_function" "this" {
222
for_each = local.lambdas
233

r_null.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
resource "null_resource" "go_setup" {
2+
3+
triggers = {
4+
hash_go_mod = filemd5("${local.main_module_path}/go.mod")
5+
hash_go_sum = filemd5("${local.main_module_path}/go.sum")
6+
}
7+
8+
provisioner "local-exec" {
9+
interpreter = ["/bin/bash", "-c"]
10+
command = "cp -f ${local.main_module_path}/go.mod ."
11+
}
12+
13+
provisioner "local-exec" {
14+
interpreter = ["/bin/bash", "-c"]
15+
command = "cp -f ${local.main_module_path}/go.sum ."
16+
}
17+
}
18+
19+
resource "null_resource" "lambda_build" {
20+
for_each = local.lambdas
21+
depends_on = [null_resource.go_setup]
22+
23+
triggers = {
24+
binary_exists = local.null.lambda_binary_exists[each.key]
25+
26+
main = join("", [
27+
for file in fileset("${path.module}/lambdas/cmd/${each.key}", "*.go") : filemd5("${path.module}/lambdas/cmd/${each.key}/${file}")
28+
])
29+
}
30+
31+
provisioner "local-exec" {
32+
command = "export GO111MODULE=on"
33+
}
34+
35+
provisioner "local-exec" {
36+
command = "cd ${local.main_module_path} && GOOS=linux go build -ldflags '-s -w' -o ./lambdas/bin/${each.key} ./lambdas/cmd/${each.key}/main.go"
37+
}
38+
}

0 commit comments

Comments
 (0)