diff --git a/Makefile b/Makefile index 7fc6f36..2126b84 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,46 @@ test: _pull-tf fi; \ echo; \ echo "------------------------------------------------------------"; \ - echo "# Terraform plan"; \ + echo "# Terraform plan (1/2)"; \ + echo "------------------------------------------------------------"; \ + if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \ + plan -target 'module.tgw-satellite.data.aws_route_tables.all' \ + $(ARGS) \ + -out=tfplan \ + ; then \ + echo "OK"; \ + else \ + echo "Failed"; \ + docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:$(TF_VERSION) -rf .terraform/ || true; \ + exit 1; \ + fi; \ + echo; \ + echo "------------------------------------------------------------"; \ + echo "# Terraform apply (1/2)"; \ + echo "------------------------------------------------------------"; \ + if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \ + apply -target 'module.tgw-satellite.data.aws_route_tables.all' \ + -auto-approve \ + tfplan \ + ; then \ + echo "Apply OK"; \ + else \ + echo "Apply failed"; \ + if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \ + destroy \ + -auto-approve \ + $(ARGS) \ + ; then \ + echo "Destroy OK"; \ + docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:$(TF_VERSION) -rf .terraform/ terraform.tfstate terraform.tfstate.backup || true; \ + else \ + echo "Destroy failed. You should check for dangling resources."; \ + exit 1; \ + fi; \ + fi; \ + echo; \ + echo "------------------------------------------------------------"; \ + echo "# Terraform plan (2/2)"; \ echo "------------------------------------------------------------"; \ if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \ plan \ @@ -119,7 +158,7 @@ test: _pull-tf fi; \ echo; \ echo "------------------------------------------------------------"; \ - echo "# Terraform apply & destroy"; \ + echo "# Terraform apply (2/2) & destroy"; \ echo "------------------------------------------------------------"; \ if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \ apply \ @@ -154,7 +193,6 @@ test: _pull-tf fi; \ ) - # ------------------------------------------------------------------------------------------------- # Helper Targets # ------------------------------------------------------------------------------------------------- diff --git a/examples/satellite-all/main.tf b/examples/satellite-all/main.tf index a998688..67ab03e 100644 --- a/examples/satellite-all/main.tf +++ b/examples/satellite-all/main.tf @@ -11,7 +11,7 @@ module "tgw" { aws_account_id_satellite = [var.aws_account_id_satellite] } -module "tgw-satellite-all" { +module "tgw-satellite" { source = "../../" providers = { diff --git a/examples/satellite-default-route-all/main.tf b/examples/satellite-default-route-all/main.tf index 6c13181..67ab03e 100644 --- a/examples/satellite-default-route-all/main.tf +++ b/examples/satellite-default-route-all/main.tf @@ -11,7 +11,7 @@ module "tgw" { aws_account_id_satellite = [var.aws_account_id_satellite] } -module "tgw-satellite-default-route-all" { +module "tgw-satellite" { source = "../../" providers = { diff --git a/examples/satellite-default-route/main.tf b/examples/satellite-default-route/main.tf index dc6d50d..67ab03e 100644 --- a/examples/satellite-default-route/main.tf +++ b/examples/satellite-default-route/main.tf @@ -11,7 +11,7 @@ module "tgw" { aws_account_id_satellite = [var.aws_account_id_satellite] } -module "tgw-satellite-default-route" { +module "tgw-satellite" { source = "../../" providers = {