Skip to content

Commit

Permalink
Merge branch 'master' into benisrae/lambda-python-docs-lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 8, 2021
2 parents 42882a6 + 7c98fb2 commit 001f415
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"Type": "Api",
"PropertyNotInCfnSchema": "unmodeled property in map"
}
},
"ParentPropertyNotInCfnSchema": {
"ChildPropertyNotInCfnSchema": {
"Ref": "Bucket"
}
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion packages/@aws-cdk/core/lib/cfn-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { CfnCreationPolicy, CfnDeletionPolicy, CfnUpdatePolicy } from './cfn-res
import { Construct, IConstruct, Node } from 'constructs';
import { addDependency } from './deps';
import { CfnReference } from './private/cfn-reference';
import { CLOUDFORMATION_TOKEN_RESOLVER } from './private/cloudformation-lang';
import { Reference } from './reference';
import { RemovalPolicy, RemovalPolicyOptions } from './removal-policy';
import { TagManager } from './tag-manager';
import { Tokenization } from './token';
import { capitalizePropertyNames, ignoreEmpty, PostResolveToken } from './util';

export interface CfnResourceProps {
Expand Down Expand Up @@ -326,7 +328,14 @@ export class CfnResource extends CfnRefElement {
const hasDefined = Object.values(renderedProps).find(v => v !== undefined);
resourceDef.Properties = hasDefined !== undefined ? renderedProps : undefined;
}
return deepMerge(resourceDef, this.rawOverrides);
const resolvedRawOverrides = Tokenization.resolve(this.rawOverrides, {
scope: this,
resolver: CLOUDFORMATION_TOKEN_RESOLVER,
// we need to preserve the empty elements here,
// as that's how removing overrides are represented as
removeEmpty: false,
});
return deepMerge(resourceDef, resolvedRawOverrides);
}),
},
};
Expand Down
17 changes: 15 additions & 2 deletions packages/@aws-cdk/core/lib/private/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export interface IResolveOptions {
* @default false
*/
allowIntrinsicKeys?: boolean;

/**
* Whether to remove undefined elements from arrays and objects when resolving.
*
* @default true
*/
removeEmpty?: boolean;
}

/**
Expand Down Expand Up @@ -120,6 +127,9 @@ export function resolve(obj: any, options: IResolveOptions): any {
throw new Error('Unable to resolve object tree with circular reference. Path: ' + pathName);
}

// whether to leave the empty elements when resolving - false by default
const leaveEmpty = options.removeEmpty === false;

//
// undefined
//
Expand Down Expand Up @@ -188,7 +198,7 @@ export function resolve(obj: any, options: IResolveOptions): any {

const arr = obj
.map((x, i) => makeContext(`${i}`)[0].resolve(x))
.filter(x => typeof(x) !== 'undefined');
.filter(x => leaveEmpty || typeof(x) !== 'undefined');

return arr;
}
Expand Down Expand Up @@ -221,6 +231,9 @@ export function resolve(obj: any, options: IResolveOptions): any {

// skip undefined
if (typeof(value) === 'undefined') {
if (leaveEmpty) {
result[key] = undefined;
}
continue;
}

Expand Down Expand Up @@ -326,4 +339,4 @@ function tagResolvedValue(value: any, typeHint: ResolutionTypeHint): any {
export function resolvedTypeHint(value: any): ResolutionTypeHint | undefined {
if (typeof value !== 'object' || value == null) { return undefined; }
return value[RESOLUTION_TYPEHINT_SYM];
}
}
8 changes: 8 additions & 0 deletions packages/@aws-cdk/core/lib/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class Tokenization {
scope: options.scope,
resolver: options.resolver,
preparing: (options.preparing ?? false),
removeEmpty: options.removeEmpty,
});
}

Expand Down Expand Up @@ -265,6 +266,13 @@ export interface ResolveOptions {
* @default false
*/
readonly preparing?: boolean;

/**
* Whether to remove undefined elements from arrays and objects when resolving.
*
* @default true
*/
readonly removeEmpty?: boolean;
}

/**
Expand Down
35 changes: 33 additions & 2 deletions packages/@aws-cdk/core/test/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,37 @@ nodeunitShim({
test.done();
},

'addPropertyOverride() allows assigning an attribute of a different resource'(test: Test) {
// GIVEN
const stack = new Stack();
const r1 = new CfnResource(stack, 'MyResource1', { type: 'AWS::Resource::Type' });
const r2 = new CfnResource(stack, 'MyResource2', { type: 'AWS::Resource::Type' });

// WHEN
r2.addPropertyOverride('A', {
B: r1.getAtt('Arn'),
});

// THEN
test.deepEqual(toCloudFormation(stack), {
Resources: {
MyResource1: {
Type: 'AWS::Resource::Type',
},
MyResource2: {
Type: 'AWS::Resource::Type',
Properties: {
A: {
B: { 'Fn::GetAtt': ['MyResource1', 'Arn'] },
},
},
},
},
});

test.done();
},

'addOverride(p, null) will assign an "null" value'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -513,7 +544,7 @@ nodeunitShim({
test.done();
},

'addDeletionOverride(p) and addPropertyDeletionOverride(pp) are sugar `undefined`'(test: Test) {
'addDeletionOverride(p) and addPropertyDeletionOverride(pp) are sugar for `undefined`'(test: Test) {
// GIVEN
const stack = new Stack();

Expand Down Expand Up @@ -904,4 +935,4 @@ class CustomizableResource extends CfnResource {
/**
* Because Resource is abstract
*/
class TestResource extends Resource {}
class TestResource extends Resource {}
20 changes: 20 additions & 0 deletions packages/@aws-cdk/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,26 @@ After turning on `privilegedMode: true`, you will need to do a one-time manual c
pipeline to get it going again (as with a broken 'synth' the pipeline will not be able to self
update to the right state).

### S3 error: Access Denied

Some constructs, such as EKS clusters, generate nested stacks. When CloudFormation tries
to deploy those stacks, it may fail with this error:

```console
S3 error: Access Denied For more information check http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
```

This happens because the pipeline is not self-mutating and, as a consequence, the `FileAssetX`
build projects get out-of-sync with the generated templates. To fix this, make sure the
`selfMutating` property is set to `true`:

```typescript
const pipeline = new CdkPipeline(this, 'MyPipeline', {
selfMutating: true,
...
});
```

## Current Limitations

Limitations that we are aware of and will address:
Expand Down

0 comments on commit 001f415

Please sign in to comment.