From 1d83b2610c4327da3e93cbcd0d7cd896e1094e37 Mon Sep 17 00:00:00 2001 From: Zachary Winnerman <98712682+zwinnerman-fleetdm@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:27:05 -0400 Subject: [PATCH] Delete now defunct workspaces (#7322) --- .../sandbox/JITProvisioner/deprovisioner/main.go | 16 ++++++++++++++++ infrastructure/sandbox/readme.md | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/infrastructure/sandbox/JITProvisioner/deprovisioner/main.go b/infrastructure/sandbox/JITProvisioner/deprovisioner/main.go index 5aea4ede5e..9a1e9d4f3f 100644 --- a/infrastructure/sandbox/JITProvisioner/deprovisioner/main.go +++ b/infrastructure/sandbox/JITProvisioner/deprovisioner/main.go @@ -55,6 +55,22 @@ func runTerraform(workspace string) error { "-auto-approve", "-no-color", }) + if err != nil { + return err + } + err := runCmd([]string{ + "workspace", + "select", + "default", + }) + if err != nil { + return err + } + err := runCmd([]string{ + "workspace", + "delete", + workspace, + }) return err } diff --git a/infrastructure/sandbox/readme.md b/infrastructure/sandbox/readme.md index f2ca2a9b8b..e911d22949 100644 --- a/infrastructure/sandbox/readme.md +++ b/infrastructure/sandbox/readme.md @@ -82,6 +82,12 @@ for i in $((aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Item for i in $(aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | select(.State.S == "provisioned") | .ID.S'); do helm uninstall $i; aws dynamodb delete-item --table-name sandbox-prod-lifecycle --key "{\"ID\": {\"S\": \"${i}\"}}"; done ``` +#### Cleanup untracked instances fully +This needs to be run in the deprovisioner terraform directory! +```bash +for i in $((aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | .ID.S'; aws dynamodb scan --table-name sandbox-prod-lifecycle | jq -r '.Items[] | .ID.S'; terraform workspace list | sed 's/ //g' | grep -v '.*default' | sed '/^$/d') | sort | uniq -u); do (terraform workspace select $i && terraform apply -destroy -auto-approve && terraform workspace select default && terraform workspace delete $i); [ $? = 0 ] || break; done +``` + ### Runbooks #### 5xx errors If you are seeing 5xx errors, find out what instance its from via the saved query here: https://us-east-2.console.aws.amazon.com/athena/home?region=us-east-2#/query-editor