Skip to content
Closed
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
8 changes: 8 additions & 0 deletions tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export class ResourceClass extends ClassType {
});
}

// Add the arn too, unless it is duplicated in the resourceIdentifier already
if (this.decider.arn && this.resourceInterface.properties.every((p) => p.name !== this.decider.arn!.name)) {
this.resourceInterface.addProperty({
...this.decider.arn,
immutable: true,
});
}

// Build the members of this class
this.addProperty({
name: staticResourceTypeName(),
Expand Down
17 changes: 17 additions & 0 deletions tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class ResourceDecider {

private readonly taggability?: TaggabilityStyle;

/**
* The arn returned by the resource, if applicable.
*/
public readonly arn?: PropertySpec;
public readonly primaryIdentifier = new Array<PropertySpec>();
public readonly propsProperties = new Array<PropsProperty>();
public readonly classProperties = new Array<ClassProperty>();
Expand All @@ -40,6 +44,7 @@ export class ResourceDecider {
this.convertAttributes();

this.convertPrimaryIdentifier();
this.arn = this.findArn();

this.propsProperties.sort((p1, p2) => p1.propertySpec.name.localeCompare(p2.propertySpec.name));
this.classProperties.sort((p1, p2) => p1.propertySpec.name.localeCompare(p2.propertySpec.name));
Expand All @@ -65,6 +70,18 @@ export class ResourceDecider {
}
}

private findArn() {
// A list of possible names for the arn, in order of importance.
// This is relevant because some resources, like AWS::VpcLattice::AccessLogSubscription
// has both `Arn` and `ResourceArn`, and we want to select the `Arn` property.
const possibleArnNames = ['Arn', `${this.resource.name}Arn`];
for (const arn of possibleArnNames) {
const att = this.classAttributeProperties.find((a) => a.propertySpec.name === attributePropertyName(arn));
if (att) { return att.propertySpec; }
}
return;
}

private convertPrimaryIdentifier() {
if (this.resource.primaryIdentifier === undefined) { return; }
for (let i = 0; i < (this.resource.primaryIdentifier).length; i++) {
Expand Down
Loading
Loading