Skip to content

Commit 346988c

Browse files
committed
feat: introduce reference interfaces, but don't require them yet
This introduces the `IXxxRef` interfaces from #35032, without actually having the L2s extend them yet. This avoids introducing the implementation burden of them to the L2 interfaces, but does allow pre-implementation in advance of their requirement.
1 parent 1ea1fee commit 346988c

File tree

78 files changed

+2941
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2941
-147
lines changed

packages/@aws-cdk/aws-ec2-alpha/lib/subnet-v2.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CidrBlock, CidrBlockIpv6, defaultSubnetName } from './util';
66
import { RouteTable } from './route';
77
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
88
import { propertyInjectable } from 'aws-cdk-lib/core/lib/prop-injectable';
9+
import { SubnetReference } from 'aws-cdk-lib/aws-ec2/lib/ec2.generated';
910

1011
/**
1112
* Interface to define subnet CIDR
@@ -194,6 +195,12 @@ export class SubnetV2 extends Resource implements ISubnetV2 {
194195
*/
195196
public readonly routeTable: IRouteTable = { routeTableId: attrs.routeTableId! };
196197

198+
public get subnetRef(): SubnetReference {
199+
return {
200+
subnetId: this.subnetId,
201+
};
202+
}
203+
197204
/**
198205
* Associate a Network ACL with this subnet
199206
* Required here since it is implemented in the ISubnetV2
@@ -245,6 +252,12 @@ export class SubnetV2 extends Resource implements ISubnetV2 {
245252
*/
246253
public readonly ipv6CidrBlock?: string;
247254

255+
public get subnetRef(): SubnetReference {
256+
return {
257+
subnetId: this.subnetId,
258+
};
259+
}
260+
248261
/**
249262
* The type of subnet (public or private) that this subnet represents.
250263
* @attribute SubnetType

packages/@aws-cdk/aws-ec2-alpha/lib/vpc-v2-base.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EgressOnlyInternetGateway, InternetGateway, NatConnectivityType, NatGat
66
import { ISubnetV2 } from './subnet-v2';
77
import { AccountPrincipal, Effect, PolicyStatement, Role } from 'aws-cdk-lib/aws-iam';
88
import { IVPCCidrBlock } from './vpc-v2';
9+
import { VPCReference } from 'aws-cdk-lib/aws-ec2/lib/ec2.generated';
910

1011
/**
1112
* Options to define EgressOnlyInternetGateway for VPC
@@ -327,6 +328,12 @@ export abstract class VpcV2Base extends Resource implements IVpcV2 {
327328
};
328329
}
329330

331+
public get vpcRef(): VPCReference {
332+
return {
333+
vpcId: this.vpcId,
334+
};
335+
}
336+
330337
/**
331338
* Adds a VPN Gateway to this VPC
332339
* @deprecated use enableVpnGatewayV2 for compatibility with VPCV2.Route

packages/aws-cdk-lib/aws-apigateway/lib/api-key.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct } from 'constructs';
2-
import { CfnApiKey } from './apigateway.generated';
2+
import { ApiKeyReference, CfnApiKey, IApiKeyRef } from './apigateway.generated';
33
import { ResourceOptions } from './resource';
44
import { IRestApi } from './restapi';
55
import { IStage } from './stage';
@@ -14,7 +14,7 @@ import { propertyInjectable } from '../../core/lib/prop-injectable';
1414
* API keys are alphanumeric string values that you distribute to
1515
* app developer customers to grant access to your API
1616
*/
17-
export interface IApiKey extends IResourceBase {
17+
export interface IApiKey extends IResourceBase, IApiKeyRef {
1818
/**
1919
* The API key ID.
2020
* @attribute
@@ -138,6 +138,12 @@ abstract class ApiKeyBase extends Resource implements IApiKey {
138138
resourceArns: [this.keyArn],
139139
});
140140
}
141+
142+
public get apiKeyRef(): ApiKeyReference {
143+
return {
144+
apiKeyId: this.keyId,
145+
};
146+
}
141147
}
142148

143149
/**

packages/aws-cdk-lib/aws-apigateway/lib/domain-name.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Construct } from 'constructs';
2-
import { CfnDomainName } from './apigateway.generated';
2+
import { CfnDomainName, DomainNameReference, IDomainNameRef } from './apigateway.generated';
33
import { BasePathMapping, BasePathMappingOptions } from './base-path-mapping';
44
import { EndpointType, IRestApi } from './restapi';
55
import { IStage } from './stage';
66
import * as apigwv2 from '../../aws-apigatewayv2';
77
import * as acm from '../../aws-certificatemanager';
88
import { IBucket } from '../../aws-s3';
9-
import { IResource, Names, Resource, Token } from '../../core';
9+
import { Arn, IResource, Names, Resource, Stack, Token } from '../../core';
1010
import { ValidationError } from '../../core/lib/errors';
1111
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
1212
import { propertyInjectable } from '../../core/lib/prop-injectable';
@@ -94,7 +94,7 @@ export interface DomainNameProps extends DomainNameOptions {
9494
readonly mapping?: IRestApi;
9595
}
9696

97-
export interface IDomainName extends IResource {
97+
export interface IDomainName extends IResource, IDomainNameRef {
9898
/**
9999
* The domain name (e.g. `example.com`)
100100
*
@@ -132,12 +132,22 @@ export class DomainName extends Resource implements IDomainName {
132132
public readonly domainName = attrs.domainName;
133133
public readonly domainNameAliasDomainName = attrs.domainNameAliasTarget;
134134
public readonly domainNameAliasHostedZoneId = attrs.domainNameAliasHostedZoneId;
135+
136+
public readonly domainNameRef = {
137+
domainName: this.domainName,
138+
domainNameArn: Arn.format({
139+
service: 'apigateway',
140+
resource: 'domainnames',
141+
resourceName: attrs.domainName,
142+
}, Stack.of(scope)),
143+
};
135144
}
136145

137146
return new Import(scope, id);
138147
}
139148

140149
public readonly domainName: string;
150+
public readonly domainNameRef: DomainNameReference;
141151
public readonly domainNameAliasDomainName: string;
142152
public readonly domainNameAliasHostedZoneId: string;
143153
private readonly basePaths = new Set<string | undefined>();
@@ -168,6 +178,7 @@ export class DomainName extends Resource implements IDomainName {
168178
});
169179

170180
this.domainName = resource.ref;
181+
this.domainNameRef = resource.domainNameRef;
171182

172183
this.domainNameAliasDomainName = edge
173184
? resource.attrDistributionDomainName

packages/aws-cdk-lib/aws-apigateway/lib/gateway-response.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct } from 'constructs';
2-
import { CfnGatewayResponse, CfnGatewayResponseProps } from './apigateway.generated';
2+
import { CfnGatewayResponse, CfnGatewayResponseProps, GatewayResponseReference, IGatewayResponseRef } from './apigateway.generated';
33
import { IRestApi } from './restapi';
44
import { IResource, Resource } from '../../core';
55
import { addConstructMetadata } from '../../core/lib/metadata-resource';
@@ -8,7 +8,7 @@ import { propertyInjectable } from '../../core/lib/prop-injectable';
88
/**
99
* Represents gateway response resource.
1010
*/
11-
export interface IGatewayResponse extends IResource {
11+
export interface IGatewayResponse extends IResource, IGatewayResponseRef {
1212
}
1313

1414
/**
@@ -61,6 +61,20 @@ export class GatewayResponse extends Resource implements IGatewayResponse {
6161
/** Uniquely identifies this class. */
6262
public static readonly PROPERTY_INJECTION_ID: string = 'aws-cdk-lib.aws-apigateway.GatewayResponse';
6363

64+
/**
65+
* Reference an existing GatewayResponse given a gateway response ID.
66+
*/
67+
public static fromGatewayResponseId(scope: Construct, id: string, gatewayResponseId: string): IGatewayResponse {
68+
class Import extends Resource implements IGatewayResponse {
69+
public readonly gatewayResponseRef = {
70+
gatewayResponseId: gatewayResponseId,
71+
};
72+
}
73+
return new Import(scope, id);
74+
}
75+
76+
public readonly gatewayResponseRef: GatewayResponseReference;
77+
6478
constructor(scope: Construct, id: string, props: GatewayResponseProps) {
6579
super(scope, id);
6680
// Enhanced CDK Analytics Telemetry
@@ -86,6 +100,7 @@ export class GatewayResponse extends Resource implements IGatewayResponse {
86100
});
87101
}
88102

103+
this.gatewayResponseRef = resource.gatewayResponseRef;
89104
this.node.defaultChild = resource;
90105
}
91106

packages/aws-cdk-lib/aws-apigateway/lib/resource.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Construct } from 'constructs';
2-
import { CfnResource, CfnResourceProps } from './apigateway.generated';
2+
import { CfnResource, CfnResourceProps, IResourceRef, ResourceReference } from './apigateway.generated';
33
import { Cors, CorsOptions } from './cors';
44
import { Integration } from './integration';
55
import { MockIntegration } from './integrations';
6-
import { Method, MethodOptions, AuthorizationType } from './method';
6+
import { AuthorizationType, Method, MethodOptions } from './method';
77
import { IRestApi, RestApi } from './restapi';
88
import { IResource as IResourceBase, Resource as ResourceConstruct } from '../../core';
99
import { ValidationError } from '../../core/lib/errors';
1010
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
1111
import { propertyInjectable } from '../../core/lib/prop-injectable';
1212

13-
export interface IResource extends IResourceBase {
13+
export interface IResource extends IResourceBase, IResourceRef {
1414
/**
1515
* The parent of this resource or undefined for the root resource.
1616
*/
@@ -383,6 +383,13 @@ export abstract class ResourceBase extends ResourceConstruct implements IResourc
383383
public get url(): string {
384384
return this.restApi.urlForPath(this.path);
385385
}
386+
387+
public get resourceRef(): ResourceReference {
388+
return {
389+
resourceId: this.resourceId,
390+
restApiId: this.api.restApiId,
391+
};
392+
}
386393
}
387394

388395
/**

packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Construct } from 'constructs';
22
import { ApiDefinition } from './api-definition';
33
import { ApiKey, ApiKeyOptions, IApiKey } from './api-key';
44
import { ApiGatewayMetrics } from './apigateway-canned-metrics.generated';
5-
import { CfnAccount, CfnRestApi } from './apigateway.generated';
5+
import { CfnAccount, CfnRestApi, IRestApiRef, RestApiReference } from './apigateway.generated';
66
import { CorsOptions } from './cors';
77
import { Deployment } from './deployment';
88
import { DomainName, DomainNameOptions } from './domain-name';
@@ -27,7 +27,7 @@ import { APIGATEWAY_DISABLE_CLOUDWATCH_ROLE } from '../../cx-api';
2727
const RESTAPI_SYMBOL = Symbol.for('@aws-cdk/aws-apigateway.RestApiBase');
2828
const APIGATEWAY_RESTAPI_SYMBOL = Symbol.for('@aws-cdk/aws-apigateway.RestApi');
2929

30-
export interface IRestApi extends IResourceBase {
30+
export interface IRestApi extends IResourceBase, IRestApiRef {
3131
/**
3232
* The ID of this API Gateway RestApi.
3333
* @attribute
@@ -738,6 +738,12 @@ export abstract class RestApiBase extends Resource implements IRestApi, iam.IRes
738738
...props,
739739
}).attachTo(this);
740740
}
741+
742+
public get restApiRef(): RestApiReference {
743+
return {
744+
restApiId: this.restApiId,
745+
};
746+
}
741747
}
742748

743749
/**

packages/aws-cdk-lib/aws-apigateway/lib/stage.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Construct } from 'constructs';
22
import { AccessLogFormat, IAccessLogDestination } from './access-log';
33
import { IApiKey, ApiKeyOptions, ApiKey } from './api-key';
44
import { ApiGatewayMetrics } from './apigateway-canned-metrics.generated';
5-
import { CfnStage } from './apigateway.generated';
5+
import { CfnStage, IStageRef, StageReference } from './apigateway.generated';
66
import { Deployment } from './deployment';
77
import { IRestApi, RestApiBase } from './restapi';
88
import { parseMethodOptionsPath } from './util';
@@ -15,7 +15,7 @@ import { propertyInjectable } from '../../core/lib/prop-injectable';
1515
/**
1616
* Represents an APIGateway Stage.
1717
*/
18-
export interface IStage extends IResource {
18+
export interface IStage extends IResource, IStageRef {
1919
/**
2020
* Name of this stage.
2121
* @attribute
@@ -357,6 +357,13 @@ export abstract class StageBase extends Resource implements IStage {
357357
...props,
358358
}).attachTo(this);
359359
}
360+
361+
public get stageRef(): StageReference {
362+
return {
363+
stageName: this.stageName,
364+
restApiId: this.restApi.restApiId,
365+
};
366+
}
360367
}
361368

362369
@propertyInjectable

packages/aws-cdk-lib/aws-apigateway/lib/usage-plan.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Construct } from 'constructs';
22
import { IApiKey } from './api-key';
3-
import { CfnUsagePlan, CfnUsagePlanKey } from './apigateway.generated';
3+
import { CfnUsagePlan, CfnUsagePlanKey, IUsagePlanRef, UsagePlanReference } from './apigateway.generated';
44
import { Method } from './method';
55
import { IRestApi } from './restapi';
66
import { Stage } from './stage';
@@ -161,7 +161,7 @@ export interface AddApiKeyOptions {
161161
/**
162162
* A UsagePlan, either managed by this CDK app, or imported.
163163
*/
164-
export interface IUsagePlan extends IResource {
164+
export interface IUsagePlan extends IResource, IUsagePlanRef {
165165
/**
166166
* Id of the usage plan
167167
* @attribute
@@ -211,6 +211,12 @@ abstract class UsagePlanBase extends Resource implements IUsagePlan {
211211
resource.overrideLogicalId(options?.overrideLogicalId);
212212
}
213213
}
214+
215+
public get usagePlanRef(): UsagePlanReference {
216+
return {
217+
usagePlanId: this.usagePlanId,
218+
};
219+
}
214220
}
215221

216222
@propertyInjectable

packages/aws-cdk-lib/aws-apigateway/lib/vpc-link.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { propertyInjectable } from '../../core/lib/prop-injectable';
88
/**
99
* Represents an API Gateway VpcLink
1010
*/
11-
export interface IVpcLink extends IResource {
11+
export interface IVpcLink extends IResource, IVpcLinkRef {
1212
/**
1313
* Physical ID of the VpcLink resource
1414
* @attribute
@@ -56,6 +56,9 @@ export class VpcLink extends Resource implements IVpcLink {
5656
public static fromVpcLinkId(scope: Construct, id: string, vpcLinkId: string): IVpcLink {
5757
class Import extends Resource implements IVpcLink {
5858
public vpcLinkId = vpcLinkId;
59+
public vpcLinkRef = {
60+
vpcLinkId: vpcLinkId,
61+
};
5962
}
6063

6164
return new Import(scope, id);
@@ -67,6 +70,8 @@ export class VpcLink extends Resource implements IVpcLink {
6770
*/
6871
public readonly vpcLinkId: string;
6972

73+
public readonly vpcLinkRef: VpcLinkReference;
74+
7075
private readonly _targets = new Array<elbv2.INetworkLoadBalancer>();
7176

7277
constructor(scope: Construct, id: string, props: VpcLinkProps = {}) {
@@ -83,6 +88,7 @@ export class VpcLink extends Resource implements IVpcLink {
8388
targetArns: Lazy.list({ produce: () => this.renderTargets() }),
8489
});
8590

91+
this.vpcLinkRef = cfnResource.vpcLinkRef;
8692
this.vpcLinkId = cfnResource.ref;
8793

8894
if (props.targets) {

0 commit comments

Comments
 (0)