Skip to content

Commit

Permalink
Merge pull request #6 from seanturner026/go-mod-fix
Browse files Browse the repository at this point in the history
Added null_resource to copy go mod files to top level directory, fixe…
  • Loading branch information
seanturner026 authored May 24, 2021
2 parents e51aee5 + 9fd768e commit f7b5a24
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 24 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
2 changes: 1 addition & 1 deletion r_api_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aws_apigatewayv2_api" "this" {
allow_credentials = true
allow_headers = ["Content-Type", "Authorization", "X-Session-Id"]
allow_methods = ["GET", "OPTIONS", "POST"]
allow_origins = ["https://${var.fqdn_alias}"]
allow_origins = [var.hosted_zone_name != "" && var.fqdn_alias != "" ? "https://${var.fqdn_alias}" : "https://${module.cloudfront.cloudfront_distribution_domain_name}"]
max_age = 600
}

Expand Down
2 changes: 1 addition & 1 deletion r_cognito.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "aws_cognito_user_pool_client" "this" {
allowed_oauth_flows_user_pool_client = true
allowed_oauth_scopes = ["email", "openid"]
supported_identity_providers = ["COGNITO"]
callback_urls = ["https://${var.fqdn_alias}"]
callback_urls = [var.hosted_zone_name != "" && var.fqdn_alias != "" ? "https://${var.fqdn_alias}" : "https://${module.cloudfront.cloudfront_distribution_domain_name}"]

explicit_auth_flows = [
"ALLOW_ADMIN_USER_PASSWORD_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
6 changes: 3 additions & 3 deletions r_route53.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ resource "aws_route53_record" "alias" {
}

resource "aws_route53_record" "acm" {
for_each = {
for_each = var.hosted_zone_name != "" && var.fqdn_alias != "" ? {
for dvo in aws_acm_certificate.this[0].domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
} if var.hosted_zone_name != "" && var.fqdn_alias != ""
}
}
} : {}

allow_overwrite = true
name = each.value.name
Expand Down
7 changes: 7 additions & 0 deletions terraform_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Complete Example

This is a full invocation and provides everything the module has to offer.

### Cloudfront DNS Example

This example creates everything which is created by the complete example. However, it does not create ACM or Route53 resources, and uses the default cloudfront DNS and certficate. The Terraform module invocation is not extenable such that it is possible to provide an ACM certificate ARN and alias to utilise non-default cloudfront DNS and certificate.
75 changes: 75 additions & 0 deletions terraform_examples/cloudfront_dns/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions terraform_examples/cloudfront_dns/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module "moot" {
source = "github.com/seanturner026/moot.git"

name = "moot"
admin_user_email = var.admin_user_email
enable_delete_admin_user = false
github_token = var.github_token
gitlab_token = var.gitlab_token
slack_webhook_url = var.slack_webhook_url
enable_api_gateway_access_logs = true
tags = var.tags
}
3 changes: 3 additions & 0 deletions terraform_examples/cloudfront_dns/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "us-east-1"
}
4 changes: 4 additions & 0 deletions terraform_examples/cloudfront_dns/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tags = {
name = "moot"
managed_by = "terraform"
}
37 changes: 37 additions & 0 deletions terraform_examples/cloudfront_dns/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
variable "tags" {
type = map(string)
description = "Map of tags to be applied to resources."
}

variable "admin_user_email" {
type = string
description = <<-DESC
Controls the creation of an admin user that is required to initially gain access to the
dashboard.
If access to the dashboard is completely lost, do the following
• `var.enable_delete_admin_user = true`
• `terraform apply`
• `var.enable_delete_admin_user = false`
• `terraform apply`
If the initial admin user should no longer be able to access the dashboard, revoke access by
setting `var.enable_delete_admin_user = true` and running `terraform apply`
DESC
default = ""
}

variable "github_token" {
type = string
description = "Token for Github."
}

variable "gitlab_token" {
type = string
description = "Token for Gitlab."
}

variable "slack_webhook_url" {
type = string
description = "URL to send slack message payloads to."
}
2 changes: 1 addition & 1 deletion terraform_examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "moot" {
source = "github.com/seanturner026/moot.git?ref=terraform-module"
source = "github.com/seanturner026/moot.git"

name = "moot"
admin_user_email = var.admin_user_email
Expand Down

0 comments on commit f7b5a24

Please sign in to comment.