Skip to content

Commit

Permalink
Added null_resource to copy go mod files to top level directory, fixe…
Browse files Browse the repository at this point in the history
…d paths
  • Loading branch information
seanturner026 committed May 24, 2021
1 parent e51aee5 commit 3ff8e18
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/repositories/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
locals {
path = "${path.module}/../.."

ssm_parameters = {
client_pool_secret = {
description = "Cognito User Pool client secret."
Expand All @@ -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 = {
Expand Down
39 changes: 28 additions & 11 deletions r_lambda.tf
Original file line number Diff line number Diff line change
@@ -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}")
])
}

Expand All @@ -18,25 +35,25 @@ 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}/."
}
}

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}"
}
}

Expand Down

0 comments on commit 3ff8e18

Please sign in to comment.