Skip to content

Commit 09fc592

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. Fix a bunch of build problems
1 parent 1ea1fee commit 09fc592

File tree

82 files changed

+3044
-165
lines changed

Some content is hidden

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

82 files changed

+3044
-165
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as elasticbeanstalk from 'aws-cdk-lib/aws-elasticbeanstalk';
44
import * as iam from 'aws-cdk-lib/aws-iam';
55
import * as s3 from 'aws-cdk-lib/aws-s3';
66
import * as deploy from 'aws-cdk-lib/aws-s3-deployment';
7-
import { App, Fn, RemovalPolicy, Stack } from 'aws-cdk-lib';
7+
import { App, AssumptionError, Fn, RemovalPolicy, Stack } from 'aws-cdk-lib';
88
import * as integ from '@aws-cdk/integ-tests-alpha';
99
import * as cpactions from 'aws-cdk-lib/aws-codepipeline-actions';
1010

@@ -49,9 +49,15 @@ const serviceRole = new iam.Role(stack, 'service-role', {
4949
managedPolicies: [
5050
{
5151
managedPolicyArn: 'arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth',
52+
get node(): any {
53+
throw new AssumptionError('Cannot reference node here');
54+
},
5255
},
5356
{
5457
managedPolicyArn: 'arn:aws:iam::aws:policy/AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy',
58+
get node(): any {
59+
throw new AssumptionError('Cannot reference node here');
60+
},
5561
},
5662
],
5763
});
@@ -62,12 +68,21 @@ const instanceProfileRole = new iam.Role(stack, 'instance-profile-role', {
6268
managedPolicies: [
6369
{
6470
managedPolicyArn: 'arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier',
71+
get node(): any {
72+
throw new AssumptionError('Cannot reference node here');
73+
},
6574
},
6675
{
6776
managedPolicyArn: 'arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker',
77+
get node(): any {
78+
throw new AssumptionError('Cannot reference node here');
79+
},
6880
},
6981
{
7082
managedPolicyArn: 'arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier',
83+
get node(): any {
84+
throw new AssumptionError('Cannot reference node here');
85+
},
7186
},
7287
],
7388
});

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/databrew/integ.start-job-run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class GlueDataBrewJobStack extends cdk.Stack {
2424
const role = new iam.Role(this, 'DataBrew Role', {
2525
managedPolicies: [{
2626
managedPolicyArn: 'arn:aws:iam::aws:policy/service-role/AWSGlueDataBrewServiceRole',
27+
get node(): any {
28+
throw new cdk.AssumptionError('Cannot reference node here');
29+
},
2730
}],
2831
path: '/',
2932
assumedBy: new iam.ServicePrincipal('databrew.amazonaws.com'),
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
"exclude": [
3-
"attribute-tag:@aws-cdk/aws-ec2-alpha.RouteTable.routeTableId",
4-
"from-method:@aws-cdk/aws-ec2-alpha.Route",
5-
"from-method:@aws-cdk/aws-ec2-alpha.TransitGateway",
6-
"from-method:@aws-cdk/aws-ec2-alpha.TransitGatewayRouteTableAssociation",
7-
"from-method:@aws-cdk/aws-ec2-alpha.TransitGatewayRouteTablePropagation",
8-
"from-method:@aws-cdk/aws-ec2-alpha.TransitGatewayVpcAttachment"
9-
]
10-
}
2+
"exclude": [
3+
"attribute-tag:@aws-cdk/aws-ec2-alpha.RouteTable.routeTableId",
4+
"from-method:@aws-cdk/aws-ec2-alpha.Route",
5+
"from-method:@aws-cdk/aws-ec2-alpha.TransitGateway",
6+
"from-method:@aws-cdk/aws-ec2-alpha.TransitGatewayRouteTableAssociation",
7+
"from-method:@aws-cdk/aws-ec2-alpha.TransitGatewayRouteTablePropagation",
8+
"from-method:@aws-cdk/aws-ec2-alpha.TransitGatewayVpcAttachment",
9+
"docs-public-apis:@aws-cdk/aws-ec2-alpha.SubnetV2.subnetRef",
10+
"docs-public-apis:@aws-cdk/aws-ec2-alpha.VpcV2Base.vpcRef"
11+
]
12+
}

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
/**

0 commit comments

Comments
 (0)