Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class CdkCore extends ExternalModule {
public readonly TagManager = $T(Type.fromName(this, 'TagManager'));
public readonly TagType = $T(Type.fromName(this, 'TagType'));
public readonly Fn = $T(Type.fromName(this, 'Fn'));
public readonly Aws = $T(Type.fromName(this, 'Aws'));
public readonly ITaggable = Type.fromName(this, 'ITaggable');
public readonly ITaggableV2 = Type.fromName(this, 'ITaggableV2');
public readonly IResolvable = Type.fromName(this, 'IResolvable');
Expand Down
21 changes: 12 additions & 9 deletions tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,24 @@ export class ResourceClass extends ClassType implements Referenceable {
* Generates a static method that returns the ARN of the provided resource.
* If the resource's ref interface already has an ARN, that's what's returned:
*
* ```
* public static arnForTable(resource: ITableRef): string {
* return resource.tableRef.tableArn;
* }
* ```
*
* Otherwise, we fall back to using the ARN template:
*
* ```
* public static arnForRestApi(resource: IRestApiRef): string {
* return new cfn_parse.TemplateString("arn:${Partition}:apigateway:${Region}::/restapis/${RestApiId}").interpolate({
* "Partition": cdk.Stack.of(resource).partition,
* "Region": cdk.Stack.of(resource).region,
* "Account": cdk.Stack.of(resource).account,
* "Partition": cdk.Stack.of(resource).partition, // Always same partition as our current one, but might be beautified by Stack
* "Region": resource.env.region,
* "Account": resource.env.account,
* "RestApiId": resource.restApiRef.restApiId
* });
* }
* ```
*/
private addArnForResourceMethod(): void {
// The resource cannot provide us with its ARN
Expand Down Expand Up @@ -518,14 +522,13 @@ export class ResourceClass extends ClassType implements Referenceable {
// Case 2: Interpolate from template
} else {
const method = doAddMethod();
const resourceIdentifier = expr.ident('resource');
const stackOfResource = $T(CDK_CORE.Stack).of(resourceIdentifier);
const resourceIdentifier = $E(expr.ident('resource'));

const interpolationVars = {
Partition: stackOfResource.prop('partition'),
Region: stackOfResource.prop('region'),
Account: stackOfResource.prop('account'),
...mapValues(this.decider.resourceReference.arnVariables!, (propName) => $E(resourceIdentifier)[refAttributeName][propName]),
Partition: $T(CDK_CORE.Stack).of(resourceIdentifier).prop('partition'),
Region: resourceIdentifier.env.region,
Account: resourceIdentifier.env.account,
...mapValues(this.decider.resourceReference.arnVariables!, (propName) => resourceIdentifier[refAttributeName][propName]),
};

const interpolateArn = CDK_CORE.helpers.TemplateString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,8 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR
public static arnForResource(resource: IResourceRef): string {
return new cfn_parse.TemplateString("arn:\${Partition}:some:\${Region}:\${Account}:resource/\${ResourceId}").interpolate({
Partition: cdk.Stack.of(resource).partition,
Region: cdk.Stack.of(resource).region,
Account: cdk.Stack.of(resource).account,
Region: resource.env.region,
Account: resource.env.account,
ResourceId: resource.resourceRef.resourceId
});
}
Expand Down
12 changes: 6 additions & 6 deletions tools/@aws-cdk/spec2cdk/test/arnForResource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ describe('arnForResource is generated', () => {
"public static arnForResource(resource: IResourceRef): string {
return new cfn_parse.TemplateString("arn:\${Partition}:some:\${Region}:\${Account}:resource/\${ResourceId}").interpolate({
Partition: cdk.Stack.of(resource).partition,
Region: cdk.Stack.of(resource).region,
Account: cdk.Stack.of(resource).account,
Region: resource.env.region,
Account: resource.env.account,
ResourceId: resource.resourceRef.resourceId
});
}"
Expand All @@ -170,8 +170,8 @@ describe('arnForResource is generated', () => {
"public static arnForResource(resource: IResourceRef): string {
return new cfn_parse.TemplateString("arn:\${Partition}:some:\${Region}:\${Account}:resource/\${Team}").interpolate({
Partition: cdk.Stack.of(resource).partition,
Region: cdk.Stack.of(resource).region,
Account: cdk.Stack.of(resource).account,
Region: resource.env.region,
Account: resource.env.account,
Team: resource.resourceRef.team
});
}"
Expand Down Expand Up @@ -207,8 +207,8 @@ describe('arnForResource is generated', () => {
"public static arnForResource(resource: IResourceRef): string {
return new cfn_parse.TemplateString("arn:\${Partition}:sagemaker:\${Region}:\${Account}:workteam/\${WorkteamName}").interpolate({
Partition: cdk.Stack.of(resource).partition,
Region: cdk.Stack.of(resource).region,
Account: cdk.Stack.of(resource).account,
Region: resource.env.region,
Account: resource.env.account,
WorkteamName: resource.resourceRef.workteamName
});
}"
Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/spec2cdk/test/expect-to-contain-code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies

import { ChangeObject, diffLines } from 'diff';

expect.extend({
Expand Down
Loading