diff --git a/justfile b/justfile index b3ce7a8f2..5c2418cf4 100644 --- a/justfile +++ b/justfile @@ -84,7 +84,7 @@ get-credentials: # Destroy a running AKS cluster. destroy: - nix run .#destroy-coco-aks -- "$azure_resource_group" + nix run .#destroy-coco-aks -- --name="$azure_resource_group" # Run code generators. codegen: diff --git a/packages/default.nix b/packages/default.nix index 8b4d602aa..4d0866395 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -112,7 +112,7 @@ rec { destroy-coco-aks = writeShellApplication { name = "destroy-coco-aks"; runtimeInputs = [ azure-cli-with-extensions ]; - text = ''az group delete --name "$1"''; + text = builtins.readFile ./destroy-coco-aks.sh; }; generate = writeShellApplication { diff --git a/packages/destroy-coco-aks.sh b/packages/destroy-coco-aks.sh new file mode 100644 index 000000000..7c7786b66 --- /dev/null +++ b/packages/destroy-coco-aks.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -euo pipefail +set -x + +for i in "$@"; do + case $i in + --name=*) + name="${i#*=}" + shift + ;; + *) + echo "Unknown option $i" + exit 1 + ;; + esac +done + +exitcode=0 + +az aks nodepool delete \ + --resource-group "${name}" \ + --name nodepool2 \ + --cluster-name "${name}" || + exitcode=$? + +az aks delete \ + --resource-group "${name}" \ + --name "${name}" \ + --yes || + exitcode=$? + +exit "${exitcode}"