You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(migrate): only allow migrate on healthy stacks (#28452)
If the stack is not in a healthy state, we should not allow cdk migrate to be run on it.
Closes #<issue number here>.
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
thrownewError(`Stack '${stackName}' in account ${environment.account} and region ${environment.region} has a status of '${stack.stackStatus.name}' due to '${stack.stackStatus.reason}'. The stack cannot be migrated until it is in a healthy state.`);
Copy file name to clipboardExpand all lines: packages/aws-cdk/test/cdk-toolkit.test.ts
+4-4
Original file line number
Diff line number
Diff line change
@@ -869,7 +869,7 @@ describe('synth', () => {
869
869
870
870
test('migrate fails when neither --from-path or --from-stack are provided',async()=>{
871
871
consttoolkit=defaultToolkitSetup();
872
-
awaitexpect(()=>toolkit.migrate({stackName: 'no-source'})).rejects.toThrowError('Either `--from-path` or `--from-stack` must be used to provide the source of the CloudFormation template.');
872
+
awaitexpect(()=>toolkit.migrate({stackName: 'no-source'})).rejects.toThrow('Either `--from-path` or `--from-stack` must be used to provide the source of the CloudFormation template.');
873
873
expect(stderrMock.mock.calls[1][0]).toContain(' ❌ Migrate failed for `no-source`: Either `--from-path` or `--from-stack` must be used to provide the source of the CloudFormation template.');
874
874
});
875
875
@@ -879,7 +879,7 @@ describe('synth', () => {
879
879
stackName: 'no-source',
880
880
fromPath: './here/template.yml',
881
881
fromStack: true,
882
-
})).rejects.toThrowError('Only one of `--from-path` or `--from-stack` may be provided.');
882
+
})).rejects.toThrow('Only one of `--from-path` or `--from-stack` may be provided.');
883
883
expect(stderrMock.mock.calls[1][0]).toContain(' ❌ Migrate failed for `no-source`: Only one of `--from-path` or `--from-stack` may be provided.');
884
884
});
885
885
@@ -888,14 +888,14 @@ describe('synth', () => {
888
888
awaitexpect(()=>toolkit.migrate({
889
889
stackName: 'bad-local-source',
890
890
fromPath: './here/template.yml',
891
-
})).rejects.toThrowError('\'./here/template.yml\' is not a valid path.');
891
+
})).rejects.toThrow('\'./here/template.yml\' is not a valid path.');
892
892
expect(stderrMock.mock.calls[1][0]).toContain(' ❌ Migrate failed for `bad-local-source`: \'./here/template.yml\' is not a valid path.');
893
893
});
894
894
895
895
test('migrate fails when --from-stack is used and stack does not exist in account',async()=>{
896
896
constmockSdkProvider=newMockSdkProvider();
897
897
mockSdkProvider.stubCloudFormation({
898
-
getTemplate(_request){
898
+
describeStacks(_request){
899
899
thrownewError('Stack does not exist in this environment');
test('readFromStack throws error when no stack exists with the stack name in the account and region',async()=>{
69
-
getTemplateMock.mockImplementationOnce(()=>{thrownewError('No stack. This did not go well.');});
70
-
awaitexpect(()=>readFromStack('that-one',sdkProvider,{account: 'num',region: 'here',name: 'hello-my-name-is-who...'})).rejects.toThrowError('No stack. This did not go well.');
80
+
describeStacksMock.mockImplementation(()=>{thrownewError('No stack. This did not go well.');});
81
+
awaitexpect(()=>readFromStack('that-one',sdkProvider,{account: 'num',region: 'here',name: 'hello-my-name-is-who...'})).rejects.toThrow('No stack. This did not go well.');
82
+
});
83
+
84
+
test('readFromStack throws error when stack exists but the status is not healthy',async()=>{
85
+
describeStacksMock.mockImplementation(()=>({
86
+
Stacks: [
87
+
{
88
+
StackName: 'this-one',
89
+
StackStatus: 'CREATE_FAILED',
90
+
StackStatusReason: 'Something went wrong',
91
+
},
92
+
],
93
+
}));
94
+
95
+
awaitexpect(()=>readFromStack('that-one',sdkProvider,{account: 'num',region: 'here',name: 'hello-my-name-is-chicka-chicka...'})).rejects.toThrow('Stack \'that-one\' in account num and region here has a status of \'CREATE_FAILED\' due to \'Something went wrong\'. The stack cannot be migrated until it is in a healthy state.');
71
96
});
72
97
73
98
test('setEnvironment sets account and region when provided',()=>{
0 commit comments