diff --git a/Makefile b/Makefile index 7fc6f36..2a51b22 100644 --- a/Makefile +++ b/Makefile @@ -102,9 +102,49 @@ test: _pull-tf 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; \ + # TODO: fix two step apply because of how `for_each` operator works 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 +159,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 +194,6 @@ test: _pull-tf fi; \ ) - # ------------------------------------------------------------------------------------------------- # Helper Targets # -------------------------------------------------------------------------------------------------