Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make create idempotent #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions scripts/generate-tfvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ TFVARS_FILE="$ROOT/terraform/terraform.tfvars"

if [[ -f "${TFVARS_FILE}" ]]
then
echo "${TFVARS_FILE} already exists." 1>&2
echo "Please remove or rename before regenerating." 1>&2
exit 1;
echo "${TFVARS_FILE} already exists, skipping generation."
else
cat <<EOF > "${TFVARS_FILE}"
project="${PROJECT}"
Expand Down
18 changes: 18 additions & 0 deletions scripts/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,21 @@ bq rm -r -f "${PROJECT}":"${BQ_LOG_DS}"
# Tear down Terraform-managed resources and remove generated tfvars
cd "$ROOT/terraform" || exit; terraform destroy -input=false -auto-approve
rm -f "$ROOT/terraform/terraform.tfvars"

rm -f "$ROOT/terraform/terraform.tfstate"
rm -f "$ROOT/terraform/terraform.tfstate.backup"

# remove kubectl context & cluster from config
CONTEXT=$(kubectl config get-contexts -o=name | grep "$(gcloud config get-value project).*gke-bazel-tutorial")

if [[ ! -z $CONTEXT ]]; then
kubectl config delete-context "$CONTEXT"
kubectl config delete-cluster "$CONTEXT"
kubectl config unset "users.$CONTEXT"

# unset current context if it's us
CURRENT=$(kubectl config current-context)
if [ "$CURRENT" == "$CONTEXT" ]; then
kubectl config unset current-context
fi
fi