From 3ff8e18c5449f610eb9ca99c8e89bd31717a8bd9 Mon Sep 17 00:00:00 2001 From: Sean Turner Date: Mon, 24 May 2021 19:36:54 +1200 Subject: [PATCH] Added null_resource to copy go mod files to top level directory, fixed paths --- Makefile | 8 ++++---- cmd/repositories/create.go | 2 +- locals.tf | 4 ++-- r_lambda.tf | 39 +++++++++++++++++++++++++++----------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 6176ddb..8056e2c 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,10 @@ build: export GO111MODULE=on - env GOOS=linux go build -ldflags="-s -w" -o bin/auth cmd/auth/. & - env GOOS=linux go build -ldflags="-s -w" -o bin/releases cmd/releases/. & - env GOOS=linux go build -ldflags="-s -w" -o bin/repositories cmd/repositories/. & - env GOOS=linux go build -ldflags="-s -w" -o bin/users cmd/users/. & + env GOOS=linux go build -ldflags="-s -w" -o ./bin/auth ./cmd/auth/. & + env GOOS=linux go build -ldflags="-s -w" -o ./bin/releases ./cmd/releases/. & + env GOOS=linux go build -ldflags="-s -w" -o ./bin/repositories ./cmd/repositories/. & + env GOOS=linux go build -ldflags="-s -w" -o ./bin/users ./cmd/users/. & test: diff --git a/cmd/repositories/create.go b/cmd/repositories/create.go index a011d11..9814902 100644 --- a/cmd/repositories/create.go +++ b/cmd/repositories/create.go @@ -87,7 +87,7 @@ func (app awsController) writeRepoToDB(e createRepoEvent, itemInput map[string]* } return err } - log.Info(fmt.Sprintf("wroterepository %s successfully", e.RepoName)) + log.Info(fmt.Sprintf("wrote repository %s successfully", e.RepoName)) return nil } diff --git a/locals.tf b/locals.tf index 0cebe6f..b0b16b7 100644 --- a/locals.tf +++ b/locals.tf @@ -1,6 +1,4 @@ locals { - path = "${path.module}/../.." - ssm_parameters = { client_pool_secret = { description = "Cognito User Pool client secret." @@ -26,6 +24,8 @@ locals { frontend_module_comprehension = [for module in jsondecode(file("${path.root}/.terraform/modules/modules.json"))["Modules"] : module if length(regexall("vuejs_frontend", module.Key)) > 0][0] frontend_module_path = "${path.root}/${local.frontend_module_comprehension.Dir}" + main_module_path = "./.terraform/modules/${local.main_module_name}" + main_module_name = split(".terraform/modules/", path.module)[1] lambdas = { auth = { diff --git a/r_lambda.tf b/r_lambda.tf index f2a2641..32db45d 100644 --- a/r_lambda.tf +++ b/r_lambda.tf @@ -1,15 +1,32 @@ +resource "null_resource" "go_setup" { + + triggers = { + hash_go_mod = filemd5("${local.main_module_path}/go.mod") + hash_go_sum = filemd5("${local.main_module_path}/go.sum") + } + + provisioner "local-exec" { + command = "cp -f ${local.main_module_path}/go.mod ." + } + + provisioner "local-exec" { + command = "cp -f ${local.main_module_path}/go.sum ." + } +} + resource "null_resource" "lambda_build" { - for_each = local.lambdas + for_each = local.lambdas + depends_on = [null_resource.go_setup] triggers = { binary_exists = local.null.lambda_binary_exists[each.key] - main = join("", [ - for file in fileset("${path.module}/cmd/${each.key}", "*.go") : filebase64("${path.module}/cmd/${each.key}/${file}") + hash_main = join("", [ + for file in fileset("${path.module}/cmd/${each.key}", "*.go") : filemd5("${path.module}/cmd/${each.key}/${file}") ]) - util = join("", [ - for file in fileset("${path.module}/internal/util", "*.go") : filebase64("${path.module}/internal/util/${file}") + hash_util = join("", [ + for file in fileset("${path.module}/internal/util", "*.go") : filemd5("${path.module}/internal/util/${file}") ]) } @@ -18,7 +35,7 @@ resource "null_resource" "lambda_build" { } provisioner "local-exec" { - command = "GOOS=linux go build -ldflags '-s -w' -o ${path.module}/bin/${each.key} ${path.module}/cmd/${each.key}/." + command = "cd ${local.main_module_path} && GOOS=linux go build -ldflags '-s -w' -o ./bin/${each.key} ./cmd/${each.key}/." } } @@ -26,17 +43,17 @@ resource "null_resource" "lambda_test" { for_each = local.lambdas triggers = { - main = join("", [ - for file in fileset("${path.module}/cmd/${each.key}", "*.go") : filebase64("${path.module}/cmd/${each.key}/${file}") + hash_main = join("", [ + for file in fileset("${path.module}/cmd/${each.key}", "*.go") : filemd5("${path.module}/cmd/${each.key}/${file}") ]) - util = join("", [ - for file in fileset("${path.module}/internal/util", "*.go") : filebase64("${path.module}/internal/util/${file}") + hash_util = join("", [ + for file in fileset("${path.module}/internal/util", "*.go") : filemd5("${path.module}/internal/util/${file}") ]) } provisioner "local-exec" { - command = "go test ${path.module}/cmd/${each.key}" + command = "cd ${local.main_module_path} && go test ./cmd/${each.key}" } }