Skip to content

Commit

Permalink
fix(aws-cdk): destroy stacks in reverse order
Browse files Browse the repository at this point in the history
Fixes #1508.
  • Loading branch information
rix0rrr committed Jan 10, 2019
1 parent d7371f0 commit 2a3752c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ async function initCommandLine() {

async function cliDestroy(stackNames: string[], force: boolean, roleArn: string | undefined) {
const stacks = await appStacks.selectStacks(...stackNames);

// The stacks will have been ordered for deployment, so reverse them for deletion.
stacks.reverse();

renames.validateSelectedStacks(stacks);

if (!force) {
Expand Down
4 changes: 4 additions & 0 deletions packages/aws-cdk/integ-tests/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ class IamStack extends cdk.Stack {
class ProvidingStack extends cdk.Stack {
constructor(parent, id) {
super(parent, id);

new sns.Topic(this, 'BogusTopic'); // Some filler
}
}

class ConsumingStack extends cdk.Stack {
constructor(parent, id, providingStack) {
super(parent, id);


new sns.Topic(this, 'BogusTopic'); // Some filler
new cdk.Output(this, 'IConsumedSomething', { value: providingStack.stackName });
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/aws-cdk/integ-tests/test-cdk-order.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ source ${scriptdir}/common.bash

setup

# ls order == synthesis order == provider before consumer
assert "cdk list | grep -- -order-" <<HERE
cdk-toolkit-integration-order-providing
cdk-toolkit-integration-order-consuming
HERE
# Deploy all stacks with an ordering component between them
cdk deploy cdk-toolkit-integration-order-\*

# Destroy them again
cdk destroy -f cdk-toolkit-integration-order-\*

echo "✅ success"

0 comments on commit 2a3752c

Please sign in to comment.