Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix: sc portfolio deletion correction (#779)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Nguyen <nguyen102@users.noreply.github.com>
Co-authored-by: Jeet <68876606+jn1119@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 12, 2021
1 parent 9840e2c commit 6e4d67b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scripts/environment-delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,30 +253,30 @@ function removeServiceCatalogPortfolio() {
local aws_region="$(cat $CONFIG_DIR/settings/$STAGE.yml | grep 'awsRegion:' -m 1 --ignore-case | sed 's/ //g' | cut -d':' -f2 | tr -d '\012\015')"
local aws_region_shortname=$(cat $CONFIG_DIR/settings/.defaults.yml | grep \'$aws_region\' -m 1 --ignore-case | sed 's/ //g' | cut -d':' -f2 | tr -d '\012\015' | tr -d "'")
local solutionName=$(cat "$CONFIG_DIR/settings/$STAGE.yml" "$CONFIG_DIR/settings/.defaults.yml" | grep '^solutionName:' -m 1 --ignore-case | sed 's/ //g' | cut -d':' -f2 | tr -d '\012\015')
local portfolioId=$(aws dynamodb get-item --table-name "$STAGE-$aws_region_shortname-$solutionName-DeploymentStore" --key '{"type": {"S": "default-sc-portfolio"}, "id": {"S": "default-SC-portfolio-1"}}' --output text | grep -o 'port-[^"]*\b')

local portfolioId=$(aws dynamodb get-item --region $aws_region --table-name "$STAGE-$aws_region_shortname-$solutionName-DeploymentStore" --key '{"type": {"S": "default-sc-portfolio"}, "id": {"S": "default-SC-portfolio-1"}}' --output text | grep -o 'port-[^"]*\b')
if [[ "$portfolioId" != "" ]]; then
local constraintIds=$(aws servicecatalog list-constraints-for-portfolio --portfolio-id "$portfolioId" --query "ConstraintDetails[].ConstraintId" --output text)
local constraintIds=$(aws servicecatalog list-constraints-for-portfolio --region $aws_region --portfolio-id "$portfolioId" --query "ConstraintDetails[].ConstraintId" --output text)
constraintIds=(`echo ${constraintIds}`)
local productIds=$(aws servicecatalog list-constraints-for-portfolio --portfolio-id "$portfolioId" --query "ConstraintDetails[].ProductId" --output text)
local productIds=$(aws servicecatalog list-constraints-for-portfolio --region $aws_region --portfolio-id "$portfolioId" --query "ConstraintDetails[].ProductId" --output text)
productIds=(`echo ${productIds}`)
local principals=$(aws servicecatalog list-principals-for-portfolio --portfolio-id "$portfolioId" --query "Principals[].PrincipalARN" --output text)
local principals=$(aws servicecatalog list-principals-for-portfolio --region $aws_region --portfolio-id "$portfolioId" --query "Principals[].PrincipalARN" --output text)
principals=(`echo ${principals}`)

for constraint in "${constraintIds[@]}"; do
aws servicecatalog delete-constraint --id $constraint > /dev/null
aws servicecatalog --region $aws_region delete-constraint --id $constraint > /dev/null
done

for product in ${productIds[@]}; do
aws servicecatalog disassociate-product-from-portfolio --product-id $product --portfolio-id $portfolioId > /dev/null
aws servicecatalog delete-product --id $product > /dev/null
aws servicecatalog --region $aws_region disassociate-product-from-portfolio --product-id $product --portfolio-id $portfolioId > /dev/null
aws servicecatalog --region $aws_region delete-product --id $product > /dev/null
done

for principal in ${principals[@]}; do
aws servicecatalog disassociate-principal-from-portfolio --portfolio-id $portfolioId --principal-arn $principal > /dev/null
aws servicecatalog --region $aws_region disassociate-principal-from-portfolio --portfolio-id $portfolioId --principal-arn $principal > /dev/null
done

aws servicecatalog delete-portfolio --id $portfolioId > /dev/null
aws servicecatalog --region $aws_region delete-portfolio --id $portfolioId > /dev/null
fi

set -e
Expand Down

0 comments on commit 6e4d67b

Please sign in to comment.