Skip to content

Commit

Permalink
Fix problem in CI with for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
snovikov committed Sep 13, 2024
1 parent 19abf76 commit 61a0ce5
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -154,7 +194,6 @@ test: _pull-tf
fi; \
)


# -------------------------------------------------------------------------------------------------
# Helper Targets
# -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 61a0ce5

Please sign in to comment.