-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bootstrap): add kms option to cdk bootstrap (#3634)
* feat(bootstrap): add kms option to cdk bootstrap * feat(bootstrap): PR review * feat(bootstrap): more aliases * fix(bootstrap): swap aliases
- Loading branch information
1 parent
0ca5d4a
commit d915aac
Showing
4 changed files
with
197 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { CreateChangeSetInput } from 'aws-sdk/clients/cloudformation'; | ||
import { Test } from 'nodeunit'; | ||
import { bootstrapEnvironment } from '../../lib'; | ||
import { fromYAML } from '../../lib/serialize'; | ||
import { MockSDK } from '../util/mock-sdk'; | ||
|
||
export = { | ||
async 'do bootstrap'(test: Test) { | ||
// GIVEN | ||
const sdk = new MockSDK(); | ||
|
||
let executed = false; | ||
|
||
sdk.stubCloudFormation({ | ||
describeStacks() { | ||
return { | ||
Stacks: [] | ||
}; | ||
}, | ||
|
||
createChangeSet(info: CreateChangeSetInput) { | ||
const template = fromYAML(info.TemplateBody as string); | ||
const bucketProperties = template.Resources.StagingBucket.Properties; | ||
test.equals(bucketProperties.BucketName, undefined, 'Expected BucketName to be undefined'); | ||
test.equals(bucketProperties.BucketEncryption.ServerSideEncryptionConfiguration[0].ServerSideEncryptionByDefault.KMSMasterKeyID, | ||
undefined, 'Expected KMSMasterKeyID to be undefined'); | ||
return {}; | ||
}, | ||
|
||
describeChangeSet() { | ||
return { | ||
Status: 'CREATE_COMPLETE', | ||
Changes: [], | ||
}; | ||
}, | ||
|
||
executeChangeSet() { | ||
executed = true; | ||
return {}; | ||
} | ||
}); | ||
|
||
// WHEN | ||
const ret = await bootstrapEnvironment({ | ||
account: '123456789012', | ||
region: 'us-east-1', | ||
name: 'mock', | ||
}, sdk, 'mockStack', undefined); | ||
|
||
// THEN | ||
test.equals(ret.noOp, false); | ||
test.equals(executed, true); | ||
|
||
test.done(); | ||
}, | ||
async 'do bootstrap using custom bucket name'(test: Test) { | ||
// GIVEN | ||
const sdk = new MockSDK(); | ||
|
||
let executed = false; | ||
|
||
sdk.stubCloudFormation({ | ||
describeStacks() { | ||
return { | ||
Stacks: [] | ||
}; | ||
}, | ||
|
||
createChangeSet(info: CreateChangeSetInput) { | ||
const template = fromYAML(info.TemplateBody as string); | ||
const bucketProperties = template.Resources.StagingBucket.Properties; | ||
test.equals(bucketProperties.BucketName, 'foobar', 'Expected BucketName to be foobar'); | ||
test.equals(bucketProperties.BucketEncryption.ServerSideEncryptionConfiguration[0].ServerSideEncryptionByDefault.KMSMasterKeyID, | ||
undefined, 'Expected KMSMasterKeyID to be undefined'); | ||
return {}; | ||
}, | ||
|
||
describeChangeSet() { | ||
return { | ||
Status: 'CREATE_COMPLETE', | ||
Changes: [], | ||
}; | ||
}, | ||
|
||
executeChangeSet() { | ||
executed = true; | ||
return {}; | ||
} | ||
}); | ||
|
||
// WHEN | ||
const ret = await bootstrapEnvironment({ | ||
account: '123456789012', | ||
region: 'us-east-1', | ||
name: 'mock', | ||
}, sdk, 'mockStack', undefined, { | ||
bucketName: 'foobar', | ||
}); | ||
|
||
// THEN | ||
test.equals(ret.noOp, false); | ||
test.equals(executed, true); | ||
|
||
test.done(); | ||
}, | ||
async 'do bootstrap using KMS CMK'(test: Test) { | ||
// GIVEN | ||
const sdk = new MockSDK(); | ||
|
||
let executed = false; | ||
|
||
sdk.stubCloudFormation({ | ||
describeStacks() { | ||
return { | ||
Stacks: [] | ||
}; | ||
}, | ||
|
||
createChangeSet(info: CreateChangeSetInput) { | ||
const template = fromYAML(info.TemplateBody as string); | ||
const bucketProperties = template.Resources.StagingBucket.Properties; | ||
test.equals(bucketProperties.BucketName, undefined, 'Expected BucketName to be undefined'); | ||
test.equals(bucketProperties.BucketEncryption.ServerSideEncryptionConfiguration[0].ServerSideEncryptionByDefault.KMSMasterKeyID, | ||
'myKmsKey', 'Expected KMSMasterKeyID to be myKmsKey'); | ||
return {}; | ||
}, | ||
|
||
describeChangeSet() { | ||
return { | ||
Status: 'CREATE_COMPLETE', | ||
Changes: [], | ||
}; | ||
}, | ||
|
||
executeChangeSet() { | ||
executed = true; | ||
return {}; | ||
} | ||
}); | ||
|
||
// WHEN | ||
const ret = await bootstrapEnvironment({ | ||
account: '123456789012', | ||
region: 'us-east-1', | ||
name: 'mock', | ||
}, sdk, 'mockStack', undefined, { | ||
kmsKeyId: 'myKmsKey', | ||
}); | ||
|
||
// THEN | ||
test.equals(ret.noOp, false); | ||
test.equals(executed, true); | ||
|
||
test.done(); | ||
}, | ||
}; |