diff --git a/Makefile b/Makefile index db6c604..907871f 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ ifndef BUILD_TOOLS_DOCKER_IMAGE BUILD_TOOLS_DOCKER_IMAGE := ${BUILD_TOOLS_DOCKER_REPO}:${BUILD_TOOLS_VERSION} endif +USER_UID := $(shell id -u) +USER_GID := $(shell id -g) + GREEN := $(shell tput -Txterm setaf 2) YELLOW := $(shell tput -Txterm setaf 3) WHITE := $(shell tput -Txterm setaf 7) @@ -36,6 +39,8 @@ docker/pre-commit-hooks: @echo "${GREEN}Start running the pre-commit hooks with docker${RESET}" @docker run --rm \ -v ${PWD}:${MOUNT_TARGET_DIRECTORY} \ + -u ${USER_UID}:${USER_GID} \ + -e HOME=/tmp \ ${BUILD_TOOLS_DOCKER_IMAGE} \ sh -c "pre-commit run -a" @@ -45,6 +50,8 @@ docker/unit-tests: @docker run --rm \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ + -u ${USER_UID}:${USER_GID} \ + -e HOME=/tmp \ -v ${PWD}:${MOUNT_TARGET_DIRECTORY} \ ${BUILD_TOOLS_DOCKER_IMAGE} \ go test -v -timeout 45m -parallel 128 ./test diff --git a/README.md b/README.md index 4928be5..9db0605 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ a record for `www` pointing to localhost. ```hcl module "repository" { source = "mineiros-io/route53/aws" - version = "0.1.0" + version = "0.2.0" name = "mineiros.io" diff --git a/main.tf b/main.tf index e5e5488..c23cb10 100644 --- a/main.tf +++ b/main.tf @@ -12,7 +12,7 @@ locals { zones = var.name == null ? [] : try(tolist(var.name), [tostring(var.name)], []) skip_zone_creation = length(local.zones) == 0 run_in_vpc = length(var.vpc_ids) > 0 - skip_delegation_set_creation = ! var.enable_module || local.skip_zone_creation || local.run_in_vpc ? true : var.skip_delegation_set_creation + skip_delegation_set_creation = ! var.module_enabled || local.skip_zone_creation || local.run_in_vpc ? true : var.skip_delegation_set_creation delegation_set_id = var.delegation_set_id != null ? var.delegation_set_id : try( aws_route53_delegation_set.delegation_set[0].id, null @@ -27,6 +27,8 @@ resource "aws_route53_delegation_set" "delegation_set" { count = local.skip_delegation_set_creation ? 0 : 1 reference_name = var.reference_name + + depends_on = [var.module_depends_on] } # --------------------------------------------------------------------------------------------------------------------- @@ -34,7 +36,7 @@ resource "aws_route53_delegation_set" "delegation_set" { # --------------------------------------------------------------------------------------------------------------------- resource "aws_route53_zone" "zone" { - for_each = var.enable_module ? toset(local.zones) : [] + for_each = var.module_enabled ? toset(local.zones) : [] name = each.value comment = var.comment @@ -53,6 +55,8 @@ resource "aws_route53_zone" "zone" { { Name = each.value }, var.tags ) + + depends_on = [var.module_depends_on] } # --------------------------------------------------------------------------------------------------------------------- @@ -124,7 +128,7 @@ locals { # --------------------------------------------------------------------------------------------------------------------- resource "aws_route53_record" "record" { - for_each = var.enable_module ? local.records : {} + for_each = var.module_enabled ? local.records : {} zone_id = each.value.zone_id type = each.value.type @@ -167,4 +171,6 @@ resource "aws_route53_record" "record" { evaluate_target_health = alias.value.evaluate_target_health } } + + depends_on = [var.module_depends_on] } diff --git a/outputs.tf b/outputs.tf index a720559..5272408 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,3 +1,10 @@ +# ------------------------------------------------------------------------------ +# OUTPUT CALCULATED VARIABLES (prefer full objects) +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# OUTPUT ALL RESOURCES AS FULL OBJECTS +# ------------------------------------------------------------------------------ output "zone" { description = "The created Hosted Zone(s)." value = aws_route53_zone.zone @@ -12,3 +19,15 @@ output "delegation_set" { description = "The outputs of the created delegation set." value = try(aws_route53_delegation_set.delegation_set[0], null) } + +# ------------------------------------------------------------------------------ +# OUTPUT ALL INPUT VARIABLES +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# OUTPUT MODULE CONFIGURATION +# ------------------------------------------------------------------------------ +output "module_enabled" { + description = "Whether the module is enabled" + value = var.module_enabled +} diff --git a/variables.tf b/variables.tf index 4ac73db..ea9683a 100644 --- a/variables.tf +++ b/variables.tf @@ -51,12 +51,6 @@ variable "delegation_set_id" { default = null } -variable "enable_module" { - description = "Whether to enable the module and to create the Route53 Zone and it's associated resources." - type = bool - default = true -} - variable "force_destroy" { description = "Whether to force destroy all records (possibly managed outside of Terraform) in the zone when destroying the zone." type = bool @@ -158,3 +152,20 @@ variable "zone_id" { # # zone_id = "zoneid" } + +# ------------------------------------------------------------------------------ +# OPTIONAL MODULE CONFIGURATION PARAMETERS +# These variables are used to configure the module. +# See https://medium.com/mineiros/the-ultimate-guide-on-how-to-write-terraform-modules-part-1-81f86d31f024 +# ------------------------------------------------------------------------------ +variable "module_enabled" { + type = bool + description = "(optional) Whether to create resources within the module or not. Default is true." + default = true +} + +variable "module_depends_on" { + type = list(any) + description = "(optional) A list of external resources the module depends_on. Default is []." + default = [] +}