Skip to content

Commit bd0fc90

Browse files
[NDR-222] Script to delete CloudWatch dashboards (#403)
* Creating tickets * Allow delete or list * [NDR-222] delete script * removing rebase annotations * [NDR-222] delete dry run * [NDR-222] white space * [NDR-222] deleting conditional * [NDR-222] removing conditional --------- Co-authored-by: jameslinnell <[email protected]>
1 parent 550546e commit bd0fc90

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/list_workspace_resource.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,25 @@ function _list_cloudwatch_dashboards() {
759759
done
760760
}
761761

762+
function _delete_cloudwatch_dashboards() {
763+
local workspace=$1
764+
if [ -z "$workspace" ]; then
765+
echo "Error: Workspace substring must be provided. Refusing to delete all dashboards."
766+
return 1
767+
fi
768+
769+
local dashboards=$(aws cloudwatch list-dashboards --output json)
770+
dashboards=$(echo "$dashboards" | jq -r --arg SUBSTRING "$workspace" '.DashboardEntries[] | select(.DashboardName | contains($SUBSTRING)) | .DashboardName')
771+
772+
[ -z "$dashboards" ] && echo "No CloudWatch Dashboards found for deletion." && return 0
773+
774+
echo "Deleting the following CloudWatch Dashboards:"
775+
for dashboard in $dashboards; do
776+
echo "$dashboard"
777+
done
778+
aws cloudwatch delete-dashboards --dashboard-names $dashboards
779+
}
780+
762781
function _list_iam_instance_profiles() {
763782
local workspace=$1
764783
local profiles=$(aws iam list-instance-profiles --output json)
@@ -1008,6 +1027,7 @@ function _delete_workspace_resources() {
10081027
_delete_lambda_layers "$TERRAFORM_WORKSPACE"
10091028
_delete_cloudwatch_alarms "$TERRAFORM_WORKSPACE"
10101029
_delete_sns_subscriptions "$TERRAFORM_WORKSPACE"
1030+
_delete_cloudwatch_dashboards "$TERRAFORM_WORKSPACE"
10111031
}
10121032

10131033
# Parse args

0 commit comments

Comments
 (0)