Skip to content

Commit

Permalink
Merge branch 'master' into nija-at/assertions-capture
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 9, 2021
2 parents ffa9eab + 430f50a commit 2c071ad
Show file tree
Hide file tree
Showing 177 changed files with 10,916 additions and 6,144 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@

All notable changes to this project will be documented in this file. See [standard-version](https:/conventional-changelog/standard-version) for commit guidelines.

## [1.122.0](https:/aws/aws-cdk/compare/v1.121.0...v1.122.0) (2021-09-08)

### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **assertions:** `hasOutput(props: any)` becomes `hasOutput(logicalId: string, props: any)`
* **assertions:** `findOutputs(props: any = {})` becomes `findOutputs(logicalId: string, props: any = {})`
* **assertions:** `hasMapping(props: any)` becomes `hasMapping(logicalId: string, props: any)`
* **assertions:** `findMappings(props: any = {})` becomes `findMappings(logicalId: string, props: any = {})`

### Features

* **ec2:** Allow ApplyCloudformationInitOptions to set additional params ([#16121](https:/aws/aws-cdk/issues/16121)) ([1d94646](https:/aws/aws-cdk/commit/1d94646bd50cbbbc1ace3732a7b8ebb313ed3ddf)), closes [#16004](https:/aws/aws-cdk/issues/16004)
* **backup:** option to prevent recovery point deletions ([#16282](https:/aws/aws-cdk/issues/16282)) ([6e71806](https:/aws/aws-cdk/commit/6e718067b6c4e1a2c905fedcc60a6863ba3add12))
* **cli:** hotswap deployments ([#15748](https:/aws/aws-cdk/issues/15748)) ([6e55c95](https:/aws/aws-cdk/commit/6e55c952d683f87bb815deb29124b9a37824749a))
* **config:** EC2_INSTANCE_PROFILE_ATTACHED managed rule ([#16011](https:/aws/aws-cdk/issues/16011)) ([816a319](https:/aws/aws-cdk/commit/816a31984b5c6e08c4c7dd740919e0c1f5d0e196))
* **ec2:** rename SubnetTypes to improve clarity with EC2 conventions ([#16348](https:/aws/aws-cdk/issues/16348)) ([2023004](https:/aws/aws-cdk/commit/2023004cc941a0e7a908bf3c90ad9887c6679564)), closes [#15929](https:/aws/aws-cdk/issues/15929)
* **ec2:** vpc endpoint for aws keyspaces ([#16306](https:/aws/aws-cdk/issues/16306)) ([ad425d0](https:/aws/aws-cdk/commit/ad425d004dd9154c367622733e2a2e36a38f1cef))
* **ecs-service-extensions:** Subscribe Extension ([#16049](https:/aws/aws-cdk/issues/16049)) ([66baca5](https:/aws/aws-cdk/commit/66baca58adc294d5c5924cf8f8c5fa122c6d6dfc))
* **elasticloadbalancingv2:** ALPN policy support for NLB listener ([#15956](https:/aws/aws-cdk/issues/15956)) ([5427578](https:/aws/aws-cdk/commit/5427578515c0b65d172f95c27f32f1933fcf8d60))
* **kms:** support fromLookup in KMS key to get key by alias name ([#15652](https:/aws/aws-cdk/issues/15652)) ([34a57ed](https:/aws/aws-cdk/commit/34a57eda01ab816cd77f260b10ca466a749586bf)), closes [#8822](https:/aws/aws-cdk/issues/8822)
* **lambda:** python 3.9 runtime ([#16366](https:/aws/aws-cdk/issues/16366)) ([a534829](https:/aws/aws-cdk/commit/a534829b2458c5ed54d05fd5cca025cba2ddaaa7))
* **pipelines:** stack-level steps ([#16215](https:/aws/aws-cdk/issues/16215)) ([d499c85](https:/aws/aws-cdk/commit/d499c85e4c09cc00b457ca7f2f4611a925ca8aeb)), closes [#16148](https:/aws/aws-cdk/issues/16148)
* **stepfunctions-tasks:** await the eval so async ops can be passed to tasks.EvaluateExpression ([#16290](https:/aws/aws-cdk/issues/16290)) ([174b066](https:/aws/aws-cdk/commit/174b066634755c76d1b78d05ca9b403145dedc47))


### Bug Fixes

* **apigatewayv2:** some methods of the `defaultStage` are not available without casting it to `IHttpStage` ([#15607](https:/aws/aws-cdk/issues/15607)) ([27a0113](https:/aws/aws-cdk/commit/27a0113ac68a05360faa22fa8897609f2f90b764))
* **assertions:** output and mapping assertions do not accept logical id ([#16329](https:/aws/aws-cdk/issues/16329)), closes [#16242](https:/aws/aws-cdk/issues/16242)
* **assets:** run executable command of container assets in cloud assembly root directory ([#16094](https:/aws/aws-cdk/issues/16094)) ([c2852c9](https:/aws/aws-cdk/commit/c2852c9c524a639a312bf296f7f23b0e3b112f6b)), closes [#15721](https:/aws/aws-cdk/issues/15721)
* **autoscaling:** EbsDeviceVolumeType.IO2 is not a valid CloudFormation value ([#16028](https:/aws/aws-cdk/issues/16028)) ([492d33b](https:/aws/aws-cdk/commit/492d33b27bc5b935e3da75f0bddd875bb6f9c15d)), closes [#16027](https:/aws/aws-cdk/issues/16027)
* **cli:** 'deploy' and 'diff' silently does nothing when given unknown stack name ([#16150](https:/aws/aws-cdk/issues/16150)) ([74776f3](https:/aws/aws-cdk/commit/74776f393462f7e7d23cb1953ef786a823adc896)), closes [#15866](https:/aws/aws-cdk/issues/15866)
* **cloudwatch:** cross account alarms does not support math expressions ([#16333](https:/aws/aws-cdk/issues/16333)) ([1ffd897](https:/aws/aws-cdk/commit/1ffd89714f8b1c1389d4e43383cc77d16d00ed9e)), closes [#16331](https:/aws/aws-cdk/issues/16331)
* **core:** allow asset bundling when selinux is enabled ([#15742](https:/aws/aws-cdk/issues/15742)) ([dbfebb4](https:/aws/aws-cdk/commit/dbfebb47a8ae61b2bb0557b6ba79a7b073f9d0df))
* **iam:** permissions boundary aspect doesn't always recognize roles ([#16154](https:/aws/aws-cdk/issues/16154)) ([c8bfcf6](https:/aws/aws-cdk/commit/c8bfcf650070a0138b148645f997f542431f70cf))
* **stepfunctions-tasks:** Athena StartQueryExecution includes QueryExecutionContext even when object is empty ([#16141](https:/aws/aws-cdk/issues/16141)) ([6e2a3e0](https:/aws/aws-cdk/commit/6e2a3e0f855221df98f78f6465586d5524f5c7d5)), closes [#16133](https:/aws/aws-cdk/issues/16133) [#16133](https:/aws/aws-cdk/issues/16133)

## [1.121.0](https:/aws/aws-cdk/compare/v1.120.0...v1.121.0) (2021-09-01)


Expand Down
4 changes: 4 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ removed:@aws-cdk/aws-stepfunctions-tasks.BatchSubmitJobProps.jobDefinition
strengthened:@aws-cdk/aws-stepfunctions-tasks.BatchSubmitJobProps
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.cluster
strengthened:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps

# Remove IO2 from autoscaling EbsDeviceVolumeType. This value is not supported
# at the moment and was not supported in the past.
removed:@aws-cdk/aws-autoscaling.EbsDeviceVolumeType.IO2
4 changes: 3 additions & 1 deletion buildspec-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ phases:
- yarn --version || npm -g install yarn
build:
commands:
- /bin/bash ./build.sh --extract && git diff-index --exit-code --ignore-space-at-eol --stat HEAD
- /bin/bash ./build.sh --extract
- /bin/bash ./scripts/transform.sh --extract
- git diff-index --exit-code --ignore-space-at-eol --stat HEAD
1 change: 1 addition & 0 deletions buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ phases:
- 'if ${BUMP_CANDIDATE:-false}; then /bin/bash ./scripts/bump-candidate.sh; fi'
- /bin/bash ./scripts/align-version.sh
- /bin/bash ./build.sh
- /bin/bash ./scripts/transform.sh
post_build:
commands:
- "[ -f .BUILD_COMPLETED ] && /bin/bash ./pack.sh"
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
"nohoist": [
"**/jszip",
"**/jszip/**",
"@aws-cdk/assertions-alpha/colors",
"@aws-cdk/assertions-alpha/colors/**",
"@aws-cdk/assertions-alpha/diff",
"@aws-cdk/assertions-alpha/diff/**",
"@aws-cdk/assertions-alpha/fast-deep-equal",
"@aws-cdk/assertions-alpha/fast-deep-equal/**",
"@aws-cdk/assertions-alpha/string-width",
"@aws-cdk/assertions-alpha/string-width/**",
"@aws-cdk/assertions-alpha/table",
"@aws-cdk/assertions-alpha/table/**",
"@aws-cdk/assertions/colors",
"@aws-cdk/assertions/colors/**",
"@aws-cdk/assertions/diff",
Expand Down
30 changes: 23 additions & 7 deletions packages/@aws-cdk/assertions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,32 @@ By default, the `hasResource()` and `hasResourceProperties()` APIs perform deep
partial object matching. This behavior can be configured using matchers.
See subsequent section on [special matchers](#special-matchers).

## Other Sections
## Output and Mapping sections

Similar to the `hasResource()` and `findResources()`, we have equivalent methods
to check and find other sections of the CloudFormation resources.
The module allows you to assert that the CloudFormation template contains an Output
that matches specific properties. The following code asserts that a template contains
an Output with a `logicalId` of `Foo` and the specified properties -

* Outputs - `hasOutput()` and `findOutputs()`
* Mapping - `hasMapping()` and `findMappings()`
```ts
assert.hasOutput('Foo', {
Value: 'Bar',
Export: { Name: 'ExportBaz' },
});
```

If you want to match against all Outputs in the template, use `*` as the `logicalId`.

```ts
assert.hasOutput('*', {
Value: 'Bar',
Export: { Name: 'ExportBaz' },
});
```

`findOutputs()` will return a list of outputs that match the `logicalId` and `props`,
and you can use the `'*'` special case as well.

All of the defaults and behaviour documented for `hasResource()` and
`findResources()` apply to these methods.
The APIs `hasMapping()` and `findMappings()` provide similar functionalities.

## Special Matchers

Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/assertions/lib/private/mappings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StackInspector } from '../vendored/assert';
import { formatFailure, matchSection } from './section';
import { filterLogicalId, formatFailure, matchSection } from './section';

export function findMappings(inspector: StackInspector, props: any = {}): { [key: string]: any }[] {
export function findMappings(inspector: StackInspector, logicalId: string, props: any = {}): { [key: string]: any }[] {
const section: { [key: string] : {} } = inspector.value.Mappings;
const result = matchSection(section, props);
const result = matchSection(filterLogicalId(section, logicalId), props);

if (!result.match) {
return [];
Expand All @@ -12,9 +12,9 @@ export function findMappings(inspector: StackInspector, props: any = {}): { [key
return result.matches;
}

export function hasMapping(inspector: StackInspector, props: any): string | void {
export function hasMapping(inspector: StackInspector, logicalId: string, props: any): string | void {
const section: { [key: string]: {} } = inspector.value.Mappings;
const result = matchSection(section, props);
const result = matchSection(filterLogicalId(section, logicalId), props);

if (result.match) {
return;
Expand Down
17 changes: 8 additions & 9 deletions packages/@aws-cdk/assertions/lib/private/outputs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StackInspector } from '../vendored/assert';
import { formatFailure, matchSection } from './section';
import { filterLogicalId, formatFailure, matchSection } from './section';

export function findOutputs(inspector: StackInspector, props: any = {}): { [key: string]: any }[] {
export function findOutputs(inspector: StackInspector, logicalId: string, props: any = {}): { [key: string]: any }[] {
const section: { [key: string] : {} } = inspector.value.Outputs;
const result = matchSection(section, props);
const result = matchSection(filterLogicalId(section, logicalId), props);

if (!result.match) {
return [];
Expand All @@ -12,20 +12,19 @@ export function findOutputs(inspector: StackInspector, props: any = {}): { [key:
return result.matches;
}

export function hasOutput(inspector: StackInspector, props: any): string | void {
export function hasOutput(inspector: StackInspector, logicalId: string, props: any): string | void {
const section: { [key: string]: {} } = inspector.value.Outputs;
const result = matchSection(section, props);

const result = matchSection(filterLogicalId(section, logicalId), props);
if (result.match) {
return;
}

if (result.closestResult === undefined) {
return 'No outputs found in the template';
return `No outputs named ${logicalId} found in the template.`;
}

return [
`Template has ${result.analyzedCount} outputs, but none match as expected.`,
`Template has ${result.analyzedCount} outputs named ${logicalId}, but none match as expected.`,
formatFailure(result.closestResult),
].join('\n');
}
}
9 changes: 9 additions & 0 deletions packages/@aws-cdk/assertions/lib/private/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ export function formatFailure(closestResult: MatchResult): string {
function leftPad(x: string, indent: number = 2): string {
const pad = ' '.repeat(indent);
return pad + x.split('\n').join(`\n${pad}`);
}

export function filterLogicalId(section: { [key: string]: {} }, logicalId: string): { [key: string]: {} } {
// default signal for all logicalIds is '*'
if (logicalId === '*') return section;

return Object.entries(section ?? {})
.filter(([k, _]) => k === logicalId)
.reduce((agg, [k, v]) => { return { ...agg, [k]: v }; }, {});
}
20 changes: 12 additions & 8 deletions packages/@aws-cdk/assertions/lib/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,46 +109,50 @@ export class Template {
* Assert that an Output with the given properties exists in the CloudFormation template.
* By default, performs partial matching on the resource, via the `Match.objectLike()`.
* To configure different behavour, use other matchers in the `Match` class.
* @param logicalId the name of the output. Provide `'*'` to match all outputs in the template.
* @param props the output as should be expected in the template.
*/
public hasOutput(props: any): void {
const matchError = hasOutput(this.inspector, props);
public hasOutput(logicalId: string, props: any): void {
const matchError = hasOutput(this.inspector, logicalId, props);
if (matchError) {
throw new Error(matchError);
}
}

/**
* Get the set of matching Outputs that match the given properties in the CloudFormation template.
* @param logicalId the name of the output. Provide `'*'` to match all outputs in the template.
* @param props by default, matches all Outputs in the template.
* When a literal object is provided, performs a partial match via `Match.objectLike()`.
* Use the `Match` APIs to configure a different behaviour.
*/
public findOutputs(props: any = {}): { [key: string]: any }[] {
return findOutputs(this.inspector, props);
public findOutputs(logicalId: string, props: any = {}): { [key: string]: any }[] {
return findOutputs(this.inspector, logicalId, props);
}

/**
* Assert that a Mapping with the given properties exists in the CloudFormation template.
* By default, performs partial matching on the resource, via the `Match.objectLike()`.
* To configure different behavour, use other matchers in the `Match` class.
* @param logicalId the name of the mapping. Provide `'*'` to match all mappings in the template.
* @param props the output as should be expected in the template.
*/
public hasMapping(props: any): void {
const matchError = hasMapping(this.inspector, props);
public hasMapping(logicalId: string, props: any): void {
const matchError = hasMapping(this.inspector, logicalId, props);
if (matchError) {
throw new Error(matchError);
}
}

/**
* Get the set of matching Mappings that match the given properties in the CloudFormation template.
* @param logicalId the name of the mapping. Provide `'*'` to match all mappings in the template.
* @param props by default, matches all Mappings in the template.
* When a literal object is provided, performs a partial match via `Match.objectLike()`.
* Use the `Match` APIs to configure a different behaviour.
*/
public findMappings(props: any = {}): { [key: string]: any }[] {
return findMappings(this.inspector, props);
public findMappings(logicalId: string, props: any = {}): { [key: string]: any }[] {
return findMappings(this.inspector, logicalId, props);
}

/**
Expand Down
Loading

0 comments on commit 2c071ad

Please sign in to comment.