Skip to content

Commit

Permalink
chore: fix CLI integ tests after switching bootstrapping to "new" sty…
Browse files Browse the repository at this point in the history
…le for V2 (#14177)


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 authored Apr 15, 2021
1 parent 4b6a6cc commit 3d7f1d2
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 81 deletions.
152 changes: 73 additions & 79 deletions packages/aws-cdk/test/integ/cli/bootstrapping.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ jest.setTimeout(600_000);
integTest('can bootstrap without execution', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--no-execute']);
await fixture.cdkBootstrapLegacy({
toolkitStackName: bootstrapStackName,
noExecute: true,
});

const resp = await fixture.aws.cloudFormation('describeStacks', {
StackName: bootstrapStackName,
Expand All @@ -28,12 +29,9 @@ integTest('upgrade legacy bootstrap stack to new bootstrap stack while in use',
fixture.rememberToDeleteBucket(newBootstrapBucketName); // This one shouldn't leak if the test succeeds, but let's be safe in case it doesn't

// Legacy bootstrap
await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--bootstrap-bucket-name', legacyBootstrapBucketName], {
modEnv: {
CDK_LEGACY_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapLegacy({
toolkitStackName: bootstrapStackName,
bootstrapBucketName: legacyBootstrapBucketName,
});

// Deploy stack that uses file assets
Expand All @@ -42,14 +40,10 @@ integTest('upgrade legacy bootstrap stack to new bootstrap stack while in use',
});

// Upgrade bootstrap stack to "new" style
await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--bootstrap-bucket-name', newBootstrapBucketName,
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: bootstrapStackName,
bootstrapBucketName: newBootstrapBucketName,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});

// (Force) deploy stack again
Expand All @@ -65,12 +59,8 @@ integTest('upgrade legacy bootstrap stack to new bootstrap stack while in use',
integTest('can and deploy if omitting execution policies', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--qualifier', fixture.qualifier], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: bootstrapStackName,
});

// Deploy stack that uses file assets
Expand All @@ -86,13 +76,9 @@ integTest('can and deploy if omitting execution policies', withDefaultFixture(as
integTest('deploy new style synthesis to new style bootstrap', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: bootstrapStackName,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});

// Deploy stack that uses file assets
Expand All @@ -108,13 +94,9 @@ integTest('deploy new style synthesis to new style bootstrap', withDefaultFixtur
integTest('deploy new style synthesis to new style bootstrap (with docker image)', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: bootstrapStackName,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});

// Deploy stack that uses file assets
Expand All @@ -130,13 +112,9 @@ integTest('deploy new style synthesis to new style bootstrap (with docker image)
integTest('deploy old style synthesis to new style bootstrap', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: bootstrapStackName,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});

// Deploy stack that uses file assets
Expand All @@ -150,7 +128,9 @@ integTest('deploy old style synthesis to new style bootstrap', withDefaultFixtur
integTest('deploying new style synthesis to old style bootstrap fails', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap', '--toolkit-stack-name', bootstrapStackName]);
await fixture.cdkBootstrapLegacy({
toolkitStackName: bootstrapStackName,
});

// Deploy stack that uses file assets, this fails because the bootstrap stack
// is version checked.
Expand All @@ -165,7 +145,12 @@ integTest('deploying new style synthesis to old style bootstrap fails', withDefa
integTest('can create a legacy bootstrap stack with --public-access-block-configuration=false', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack-1');

await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName, '--public-access-block-configuration', 'false', '--tags', 'Foo=Bar']);
await fixture.cdkBootstrapLegacy({
verbose: true,
toolkitStackName: bootstrapStackName,
publicAccessBlockConfiguration: false,
tags: 'Foo=Bar',
});

const response = await fixture.aws.cloudFormation('describeStacks', { StackName: bootstrapStackName });
expect(response.Stacks?.[0].Tags).toEqual([
Expand All @@ -179,8 +164,15 @@ integTest('can create multiple legacy bootstrap stacks', withDefaultFixture(asyn

// deploy two toolkit stacks into the same environment (see #1416)
// one with tags
await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName1, '--tags', 'Foo=Bar']);
await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName2]);
await fixture.cdkBootstrapLegacy({
verbose: true,
toolkitStackName: bootstrapStackName1,
tags: 'Foo=Bar',
});
await fixture.cdkBootstrapLegacy({
verbose: true,
toolkitStackName: bootstrapStackName2,
});

const response = await fixture.aws.cloudFormation('describeStacks', { StackName: bootstrapStackName1 });
expect(response.Stacks?.[0].Tags).toEqual([
Expand All @@ -189,10 +181,12 @@ integTest('can create multiple legacy bootstrap stacks', withDefaultFixture(asyn
}));

integTest('can dump the template, modify and use it to deploy a custom bootstrap stack', withDefaultFixture(async (fixture) => {
let template = await fixture.cdk(['bootstrap', '--show-template'], {
captureStderr: false,
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
let template = await fixture.cdkBootstrapModern({
// toolkitStackName doesn't matter for this particular invocation
toolkitStackName: fixture.fullStackName('bootstrap-stack'),
showTemplate: true,
cliOptions: {
captureStderr: false,
},
});

Expand All @@ -205,27 +199,27 @@ integTest('can dump the template, modify and use it to deploy a custom bootstrap

const filename = path.join(fixture.integTestDir, `${fixture.qualifier}-template.yaml`);
fs.writeFileSync(filename, template, { encoding: 'utf-8' });
await fixture.cdk(['bootstrap',
'--toolkit-stack-name', fixture.fullStackName('bootstrap-stack'),
'--qualifier', fixture.qualifier,
'--template', filename,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: fixture.fullStackName('bootstrap-stack'),
template: filename,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});
}));

integTest('switch on termination protection, switch is left alone on re-bootstrap', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName,
'--termination-protection', 'true',
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: { CDK_NEW_BOOTSTRAP: '1' },
await fixture.cdkBootstrapModern({
verbose: true,
toolkitStackName: bootstrapStackName,
terminationProtection: true,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});
await fixture.cdkBootstrapModern({
verbose: true,
toolkitStackName: bootstrapStackName,
force: true,
});
await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName, '--force'], { modEnv: { CDK_NEW_BOOTSTRAP: '1' } });

const response = await fixture.aws.cloudFormation('describeStacks', { StackName: bootstrapStackName });
expect(response.Stacks?.[0].EnableTerminationProtection).toEqual(true);
Expand All @@ -234,13 +228,17 @@ integTest('switch on termination protection, switch is left alone on re-bootstra
integTest('add tags, left alone on re-bootstrap', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName,
'--tags', 'Foo=Bar',
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: { CDK_NEW_BOOTSTRAP: '1' },
await fixture.cdkBootstrapModern({
verbose: true,
toolkitStackName: bootstrapStackName,
tags: 'Foo=Bar',
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});
await fixture.cdkBootstrapModern({
verbose: true,
toolkitStackName: bootstrapStackName,
force: true,
});
await fixture.cdk(['bootstrap', '-v', '--toolkit-stack-name', bootstrapStackName, '--force'], { modEnv: { CDK_NEW_BOOTSTRAP: '1' } });

const response = await fixture.aws.cloudFormation('describeStacks', { StackName: bootstrapStackName });
expect(response.Stacks?.[0].Tags).toEqual([
Expand All @@ -251,13 +249,9 @@ integTest('add tags, left alone on re-bootstrap', withDefaultFixture(async (fixt
integTest('can deploy modern-synthesized stack even if bootstrap stack name is unknown', withDefaultFixture(async (fixture) => {
const bootstrapStackName = fixture.fullStackName('bootstrap-stack');

await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--qualifier', fixture.qualifier,
'--cloudformation-execution-policies', 'arn:aws:iam::aws:policy/AdministratorAccess'], {
modEnv: {
CDK_NEW_BOOTSTRAP: '1',
},
await fixture.cdkBootstrapModern({
toolkitStackName: bootstrapStackName,
cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess',
});

// Deploy stack that uses file assets
Expand Down
Loading

0 comments on commit 3d7f1d2

Please sign in to comment.