From 54435b5d0671e062772ae94d7bb5dab434f9333b Mon Sep 17 00:00:00 2001 From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:10:53 +0100 Subject: [PATCH] destroy-coco-aks: don't delete resource group Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- justfile | 2 +- packages/default.nix | 2 +- packages/destroy-coco-aks.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 packages/destroy-coco-aks.sh 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}"