Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aws/aws-cdk into diffNest…
Browse files Browse the repository at this point in the history
…edStacks
  • Loading branch information
comcalvi committed Jan 20, 2022
2 parents 28a3a0f + 565c26b commit ff137fd
Show file tree
Hide file tree
Showing 683 changed files with 12,997 additions and 12,439 deletions.
30 changes: 6 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let us know if it's not up-to-date (even better, submit a PR with your correcti

The following steps describe how to set up the AWS CDK repository on your local machine.
The alternative is to use [Gitpod](https://www.gitpod.io/), a Cloud IDE for your development.
See [Gitpod section](#gitpod) on how to set up the CDK repo on Gitpod.
See [Gitpod section](#gitpod-alternative) on how to set up the CDK repo on Gitpod.

### Setup

Expand All @@ -69,7 +69,7 @@ $ yarn install
```

We recommend that you use [Visual Studio Code](https://code.visualstudio.com/) to work on the CDK.
We use `eslint` to keep our code consistent in terms of style and reducing defects. We recommend installing the
We use `eslint` to keep our code consistent in terms of style and reducing defects. We recommend installing
the [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) as well.

### Repo Layout
Expand Down Expand Up @@ -726,7 +726,7 @@ these directories.
### Linking against this repository

If you are developing your own CDK application or library and want to use the locally checked out version of the
AWS CDK, instead of the the version of npm, the `./link-all.sh` script will help here.
AWS CDK, instead of the version of npm, the `./link-all.sh` script will help here.

This script symlinks the built modules from the local AWS CDK repo under the `node_modules/` folder of the CDK app or
library.
Expand Down Expand Up @@ -803,35 +803,17 @@ The pattern is simple:
with the name of the context key that **enables** this new feature (for
example, `ENABLE_STACK_NAME_DUPLICATES`). The context key should be in the
form `module.Type:feature` (e.g. `@aws-cdk/core:enableStackNameDuplicates`).
2. Use `node.tryGetContext(cxapi.ENABLE_XXX)` to check if this feature is enabled
2. Use `FeatureFlags.of(construct).isEnabled(cxapi.ENABLE_XXX)` to check if this feature is enabled
in your code. If it is not defined, revert to the legacy behavior.
3. Add your feature flag to the `FUTURE_FLAGS` map in
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cx-api/lib/features.ts).
This map is inserted to generated `cdk.json` files for new projects created
through `cdk init`.
4. In your PR title (which goes into CHANGELOG), add a `(under feature flag)` suffix. e.g:
4. In your tests, use the `testFutureBehavior` and `testLegacyBehavior` [jest helper methods] to test the enabled and disabled behavior.
5. In your PR title (which goes into CHANGELOG), add a `(under feature flag)` suffix. e.g:

`fix(core): impossible to use the same physical stack name for two stacks (under feature flag)`

In the [next major version of the
CDK](https://github.com/aws/aws-cdk/issues/3398) we will either remove the
legacy behavior or flip the logic for all these features and then
reset the `FEATURE_FLAGS` map for the next cycle.

### Feature Flags - CDKv2

We have started working on the next version of the CDK, specifically CDKv2. This is currently being maintained
on a separate branch `v2-main` whereas `master` continues to track versions `1.x`.

Feature flags introduced in the CDK 1.x and removed in 2.x, must be added to the `FUTURE_FLAGS_EXPIRED` list in
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cx-api/lib/features.ts)
on the `v2-main` branch.
This will make the default behaviour in CDKv2 as if the flag is enabled and also prevents users from disabling
the feature flag.

A couple of [jest helper methods] are available for use with unit tests. These help run unit tests that test
behaviour when flags are enabled or disabled in the two major versions.

[jest helper methods]: https://github.com/aws/aws-cdk/blob/master/tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts

## Versioning and Release
Expand Down
12 changes: 11 additions & 1 deletion allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@ removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.retry
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.tumblingWindow
base-types:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps
base-types:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps
base-types:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps
base-types:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps

# fixed vpc property of BaseLoadBalancer so it correctly implements I(Application|Network)LoadBalancer (i.e: must be optional)
changed-type:@aws-cdk/aws-elasticloadbalancingv2.ApplicationLoadBalancer.vpc
changed-type:@aws-cdk/aws-elasticloadbalancingv2.BaseLoadBalancer.vpc
changed-type:@aws-cdk/aws-elasticloadbalancingv2.NetworkLoadBalancer.vpc

# removed methods and properties related to event bridge notifications for S3 buckets as they are not yet supported (19 Jan 2022)
removed:@aws-cdk/aws-s3.Bucket.enableEventBridgeNotification
removed:@aws-cdk/aws-s3.BucketBase.enableEventBridgeNotification
removed:@aws-cdk/aws-s3.BucketProps.eventBridgeEnabled
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@yarnpkg/lockfile": "^1.1.0",
"cdk-generate-synthetic-examples": "^0.1.2",
"cdk-generate-synthetic-examples": "^0.1.3",
"conventional-changelog-cli": "^2.2.2",
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/app-delivery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"constructs": "^3.3.69"
},
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/aws-s3": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '@aws-cdk/assert-internal/jest';
import { isSuperObject } from '@aws-cdk/assert-internal';
import { Match, Matcher, Template } from '@aws-cdk/assertions';
import * as cfn from '@aws-cdk/aws-cloudformation';
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
Expand Down Expand Up @@ -135,56 +134,43 @@ describeDeprecated('pipeline deploy stack action', () => {
capabilities: [cfn.CloudFormationCapabilities.ANONYMOUS_IAM, cfn.CloudFormationCapabilities.AUTO_EXPAND],
adminPermissions: false,
}));
expect(pipelineStack).toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'TestStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_NAMED_IAM',
},

Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', hasPipelineActionConfiguration({
StackName: 'TestStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_NAMED_IAM',
}));
expect(pipelineStack).toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'AnonymousIAM',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_IAM',
},
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', hasPipelineActionConfiguration({
StackName: 'AnonymousIAM',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_IAM',
}));
expect(pipelineStack).not.toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'NoCapStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_NAMED_IAM',
},
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', Match.not(hasPipelineActionConfiguration({
StackName: 'NoCapStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_NAMED_IAM',
})));
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', Match.not(hasPipelineActionConfiguration({
StackName: 'NoCapStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_IAM',
})));
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', hasPipelineActionConfiguration({
StackName: 'NoCapStack',
ActionMode: 'CHANGE_SET_REPLACE',
}));
expect(pipelineStack).not.toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'NoCapStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_IAM',
},
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', hasPipelineActionConfiguration({
StackName: 'AutoExpand',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_AUTO_EXPAND',
}));
expect(pipelineStack).toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'NoCapStack',
ActionMode: 'CHANGE_SET_REPLACE',
},
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', hasPipelineActionConfiguration({
StackName: 'AnonymousIAMAndAutoExpand',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND',
}));
expect(pipelineStack).toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'AutoExpand',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_AUTO_EXPAND',
},
}));
expect(pipelineStack).toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'AnonymousIAMAndAutoExpand',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND',
},
}));

});

test('users can use admin permissions', () => {
const pipelineStack = getTestStack();
const selfUpdatingStack = createSelfUpdatingStack(pipelineStack);
Expand All @@ -196,7 +182,7 @@ describeDeprecated('pipeline deploy stack action', () => {
input: selfUpdatingStack.synthesizedApp,
adminPermissions: true,
}));
expect(pipelineStack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(pipelineStack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Version: '2012-10-17',
Statement: [
Expand Down Expand Up @@ -251,15 +237,13 @@ describeDeprecated('pipeline deploy stack action', () => {
],
},
});
expect(pipelineStack).toHaveResource('AWS::CodePipeline::Pipeline', hasPipelineAction({
Configuration: {
StackName: 'TestStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND',
},
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', hasPipelineActionConfiguration({
StackName: 'TestStack',
ActionMode: 'CHANGE_SET_REPLACE',
Capabilities: 'CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND',
}));

});

test('users can supply a role for deploy action', () => {
const pipelineStack = getTestStack();
const selfUpdatingStack = createSelfUpdatingStack(pipelineStack);
Expand Down Expand Up @@ -313,7 +297,7 @@ describeDeprecated('pipeline deploy stack action', () => {
}));

// THEN //
expect(pipelineStack).toHaveResource('AWS::IAM::Policy', {
Template.fromStack(pipelineStack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Version: '2012-10-17',
Statement: [
Expand Down Expand Up @@ -391,7 +375,7 @@ describeDeprecated('pipeline deploy stack action', () => {
const app = new cdk.App();

const deployedStack = new cdk.Stack(app, 'DeployedStack');
for (let i = 0 ; i < assetCount ; i++) {
for (let i = 0; i < assetCount; i++) {
deployedStack.node.addMetadata(cxschema.ArtifactMetadataEntryType.ASSET, {});
}

Expand All @@ -406,7 +390,6 @@ describeDeprecated('pipeline deploy stack action', () => {
},
),
);

});

test('allows overriding the ChangeSet and Execute action names', () => {
Expand All @@ -425,25 +408,21 @@ describeDeprecated('pipeline deploy stack action', () => {
],
});

expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
Stages: [
{},
{},
{
Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
Stages: Match.arrayWith([
Match.objectLike({
Name: 'Deploy',
Actions: [
{
Actions: Match.arrayWith([
Match.objectLike({
Name: 'Prepare',
},
{
}),
Match.objectLike({
Name: 'Deploy',
},
],
},
],
}),
]),
}),
]),
});


});
});

Expand Down Expand Up @@ -481,7 +460,7 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline
});

// simple source
const bucket = s3.Bucket.fromBucketArn( pipeline, 'PatternBucket', 'arn:aws:s3:::totally-fake-bucket');
const bucket = s3.Bucket.fromBucketArn(pipeline, 'PatternBucket', 'arn:aws:s3:::totally-fake-bucket');
const sourceOutput = new codepipeline.Artifact('SourceOutput');
const sourceAction = new cpactions.S3SourceAction({
actionName: 'S3Source',
Expand Down Expand Up @@ -509,15 +488,16 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline
return { synthesizedApp: buildOutput, pipeline };
}

function hasPipelineAction(expectedAction: any): (props: any) => boolean {
return (props: any) => {
for (const stage of props.Stages) {
for (const action of stage.Actions) {
if (isSuperObject(action, expectedAction, [], true)) {
return true;
}
}
}
return false;
};
}
function hasPipelineActionConfiguration(expectedActionConfiguration: any): Matcher {
return Match.objectLike({
Stages: Match.arrayWith([
Match.objectLike({
Actions: Match.arrayWith([
Match.objectLike({
Configuration: expectedActionConfiguration,
}),
]),
}),
]),
});
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.4.0",
"jest": "^27.4.7",
"ts-jest": "^27.1.2"
"ts-jest": "^27.1.3"
},
"dependencies": {
"@aws-cdk/cloud-assembly-schema": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"aws-cdk-migration": "0.0.0",
"constructs": "^3.3.69",
"jest": "^27.3.1",
"ts-jest": "^27.1.2"
"ts-jest": "^27.1.3"
},
"dependencies": {
"@aws-cdk/cloudformation-diff": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assertions/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------
----------------
29 changes: 29 additions & 0 deletions packages/@aws-cdk/assertions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,35 @@ target array. Out of order will be recorded as a match failure.
Alternatively, the `Match.arrayEquals()` API can be used to assert that the target is
exactly equal to the pattern array.

### String Matchers

The `Match.stringLikeRegexp()` API can be used to assert that the target matches the
provided regular expression.

```ts
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Template": "const includeHeaders = true;"
// }
// }
// }
// }

// The following will NOT throw an assertion error
template.hasResourceProperties('Foo::Bar', {
Template: Match.stringLikeRegexp('includeHeaders = (true|false)'),
});

// The following will throw an assertion error
template.hasResourceProperties('Foo::Bar', {
Template: Match.stringLikeRegexp('includeHeaders = null'),
});
```

### Not Matcher

The not matcher inverts the search pattern and matches all patterns in the path that does
Expand Down
Loading

0 comments on commit ff137fd

Please sign in to comment.