Skip to content

Commit bc96ee1

Browse files
feat: metadata collection for construct methods (#33292)
### Issue # (if applicable) N/A ### Reason for this change Support construct public method logging. Method name, keys, and property values of Boolean and ENUM types - When you use an L2 construct method, we will collect the method name, property keys, and property values of Boolean and enum types. ### Description of changes Based on the discussion #33198. This change adds `@MetadataMethod` decorator to public construct methods which will allow metadata logging during synthesis into `AWS::CDK::Metadata` resource. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes No integ test is possible as integ test requires analytics reporting to be false. Unit tests added. ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 3403da4 commit bc96ee1

File tree

164 files changed

+10830
-1839
lines changed

Some content is hidden

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

164 files changed

+10830
-1839
lines changed

packages/@aws-cdk/aws-amplify-alpha/lib/app.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BasicAuth } from './basic-auth';
77
import { Branch, BranchOptions } from './branch';
88
import { Domain, DomainOptions } from './domain';
99
import { renderEnvironmentVariables } from './utils';
10-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
10+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
1111

1212
/**
1313
* An Amplify Console application
@@ -280,6 +280,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
280280
/**
281281
* Adds a custom rewrite/redirect rule to this application
282282
*/
283+
@MethodMetadata()
283284
public addCustomRule(rule: CustomRule) {
284285
this.customRules.push(rule);
285286
return this;
@@ -291,6 +292,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
291292
* All environment variables that you add are encrypted to prevent rogue
292293
* access so you can use them to store secret information.
293294
*/
295+
@MethodMetadata()
294296
public addEnvironment(name: string, value: string) {
295297
this.environmentVariables[name] = value;
296298
return this;
@@ -302,6 +304,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
302304
* All environment variables that you add are encrypted to prevent rogue
303305
* access so you can use them to store secret information.
304306
*/
307+
@MethodMetadata()
305308
public addAutoBranchEnvironment(name: string, value: string) {
306309
this.autoBranchEnvironmentVariables[name] = value;
307310
return this;
@@ -310,6 +313,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
310313
/**
311314
* Adds a branch to this application
312315
*/
316+
@MethodMetadata()
313317
public addBranch(id: string, options: BranchOptions = {}): Branch {
314318
return new Branch(this, id, {
315319
...options,
@@ -320,6 +324,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
320324
/**
321325
* Adds a domain to this application
322326
*/
327+
@MethodMetadata()
323328
public addDomain(id: string, options: DomainOptions = {}): Domain {
324329
return new Domain(this, id, {
325330
...options,

packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { IApp } from './app';
1717
import { BasicAuth } from './basic-auth';
1818
import { renderEnvironmentVariables } from './utils';
1919
import { AssetDeploymentIsCompleteFunction, AssetDeploymentOnEventFunction } from '../custom-resource-handlers/dist/aws-amplify-alpha/asset-deployment-provider.generated';
20-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
20+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
2121

2222
/**
2323
* A branch
@@ -206,6 +206,7 @@ export class Branch extends Resource implements IBranch {
206206
* All environment variables that you add are encrypted to prevent rogue
207207
* access so you can use them to store secret information.
208208
*/
209+
@MethodMetadata()
209210
public addEnvironment(name: string, value: string) {
210211
this.environmentVariables[name] = value;
211212
return this;

packages/@aws-cdk/aws-amplify-alpha/lib/domain.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Construct } from 'constructs';
55
import { CfnDomain } from 'aws-cdk-lib/aws-amplify';
66
import { IApp } from './app';
77
import { IBranch } from './branch';
8-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
8+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
99

1010
/**
1111
* Options to add a domain to an application
@@ -171,6 +171,7 @@ export class Domain extends Resource {
171171
* @param branch The branch
172172
* @param prefix The prefix. Use '' to map to the root of the domain. Defaults to branch name.
173173
*/
174+
@MethodMetadata()
174175
public mapSubDomain(branch: IBranch, prefix?: string) {
175176
this.subDomains.push({ branch, prefix });
176177
return this;
@@ -179,6 +180,7 @@ export class Domain extends Resource {
179180
/**
180181
* Maps a branch to the domain root
181182
*/
183+
@MethodMetadata()
182184
public mapRoot(branch: IBranch) {
183185
return this.mapSubDomain(branch, '');
184186
}

packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CfnService } from 'aws-cdk-lib/aws-apprunner';
1111
import { IVpcConnector } from './vpc-connector';
1212
import { IAutoScalingConfiguration } from './auto-scaling-configuration';
1313
import { IObservabilityConfiguration } from './observability-configuration';
14-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
14+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
1515

1616
/**
1717
* The image repository types
@@ -1373,13 +1373,15 @@ export class Service extends cdk.Resource implements IService, iam.IGrantable {
13731373
/**
13741374
* Adds a statement to the instance role.
13751375
*/
1376+
@MethodMetadata()
13761377
public addToRolePolicy(statement: iam.PolicyStatement) {
13771378
this.instanceRole.addToPrincipalPolicy(statement);
13781379
}
13791380

13801381
/**
13811382
* This method adds an environment variable to the App Runner service.
13821383
*/
1384+
@MethodMetadata()
13831385
public addEnvironmentVariable(name: string, value: string) {
13841386
if (name.startsWith('AWSAPPRUNNER')) {
13851387
throw new Error(`Environment variable key ${name} with a prefix of AWSAPPRUNNER is not allowed`);
@@ -1390,6 +1392,7 @@ export class Service extends cdk.Resource implements IService, iam.IGrantable {
13901392
/**
13911393
* This method adds a secret as environment variable to the App Runner service.
13921394
*/
1395+
@MethodMetadata()
13931396
public addSecret(name: string, secret: Secret) {
13941397
if (name.startsWith('AWSAPPRUNNER')) {
13951398
throw new Error(`Environment secret key ${name} with a prefix of AWSAPPRUNNER is not allowed`);

packages/@aws-cdk/aws-cognito-identitypool-alpha/lib/identitypool.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Resource, IResource, Stack, ArnFormat, Lazy, Token } from 'aws-cdk-lib/
44
import { Construct } from 'constructs';
55
import { IdentityPoolRoleAttachment, IdentityPoolRoleMapping } from './identitypool-role-attachment';
66
import { IUserPoolAuthenticationProvider } from './identitypool-user-pool-authentication-provider';
7-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
7+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
88

99
/**
1010
* Represents a Cognito Identity Pool
@@ -418,6 +418,7 @@ export class IdentityPool extends Resource implements IIdentityPool {
418418
/**
419419
* Add a User Pool to the Identity Pool and configure the User Pool client to handle identities
420420
*/
421+
@MethodMetadata()
421422
public addUserPoolAuthentication(userPool: IUserPoolAuthenticationProvider): void {
422423
const providers = userPool.bind(this, this);
423424
this.cognitoIdentityProviders = this.cognitoIdentityProviders.concat(providers);
@@ -426,6 +427,7 @@ export class IdentityPool extends Resource implements IIdentityPool {
426427
/**
427428
* Add Role Mappings to the Identity Pool
428429
*/
430+
@MethodMetadata()
429431
public addRoleMappings(...roleMappings: IdentityPoolRoleMapping[]): void {
430432
if (!roleMappings || !roleMappings.length) return;
431433
this.roleAttachmentCount++;

packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CfnIPAM, CfnIPAMPool, CfnIPAMPoolCidr, CfnIPAMScope } from 'aws-cdk-lib/aws-ec2';
22
import { Construct } from 'constructs';
33
import { Lazy, Names, Resource, Stack, Tags } from 'aws-cdk-lib';
4-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
4+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
55

66
/**
77
* Represents the address family for IP addresses in an IPAM pool.
@@ -373,6 +373,7 @@ class IpamPool extends Resource implements IIpamPool {
373373
* @param options Either a CIDR or netmask length must be provided
374374
* @returns AWS::EC2::IPAMPoolCidr
375375
*/
376+
@MethodMetadata()
376377
public provisionCidr(id: string, options: IpamPoolCidrProvisioningOptions): CfnIPAMPoolCidr {
377378
const cidr = new CfnIPAMPoolCidr(this, id, {
378379
...options,
@@ -549,6 +550,7 @@ export class Ipam extends Resource {
549550
* Function to add custom scope to an existing IPAM
550551
* Custom scopes can only be private
551552
*/
553+
@MethodMetadata()
552554
public addScope(scope: Construct, id: string, options: IpamScopeOptions): IIpamScopeBase {
553555
const ipamScope = new IpamScope(scope, id, {
554556
...options,

packages/@aws-cdk/aws-ec2-alpha/lib/route.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Annotations, Duration, IResource, Resource, Tags } from 'aws-cdk-lib/co
44
import { IVpcV2, VPNGatewayV2Options } from './vpc-v2-base';
55
import { NetworkUtils, allRouteTableIds, CidrBlock } from './util';
66
import { ISubnetV2 } from './subnet-v2';
7-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
7+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
88

99
/**
1010
* Indicates whether the NAT gateway supports public or private connectivity.
@@ -819,6 +819,7 @@ export class RouteTable extends Resource implements IRouteTable {
819819
* @param target The gateway or endpoint targeted by the route.
820820
* @param routeName The resource name of the route.
821821
*/
822+
@MethodMetadata()
822823
public addRoute(id: string, destination: string, target: RouteTargetType, routeName?: string) {
823824
new Route(this, id, {
824825
routeTable: this,

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Construct, DependencyGroup, IDependable } from 'constructs';
44
import { IVpcV2 } from './vpc-v2-base';
55
import { CidrBlock, CidrBlockIpv6 } from './util';
66
import { RouteTable } from './route';
7-
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
7+
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
88

99
/**
1010
* Interface to define subnet CIDR
@@ -330,6 +330,7 @@ export class SubnetV2 extends Resource implements ISubnetV2 {
330330
* @param networkAcl The Network ACL to associate with this subnet.
331331
* This allows controlling inbound and outbound traffic for instances in this subnet.
332332
*/
333+
@MethodMetadata()
333334
public associateNetworkAcl(id: string, networkAcl: INetworkAcl) {
334335
this._networkAcl = networkAcl;
335336

packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-route-table-association.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ITransitGatewayRouteTable } from './transit-gateway-route-table';
33
import { CfnTransitGatewayRouteTableAssociation } from 'aws-cdk-lib/aws-ec2';
44
import { Construct } from 'constructs';
55
import { ITransitGatewayAssociation, TransitGatewayAssociationBase } from './transit-gateway-association';
6+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
67

78
/**
89
* Represents a Transit Gateway Route Table Association.
@@ -44,6 +45,8 @@ export class TransitGatewayRouteTableAssociation extends TransitGatewayAssociati
4445

4546
constructor(scope: Construct, id: string, props: TransitGatewayRouteTableAssociationProps) {
4647
super(scope, id);
48+
// Enhanced CDK Analytics Telemetry
49+
addConstructMetadata(this, props);
4750

4851
const resource = new CfnTransitGatewayRouteTableAssociation(this, id, {
4952
transitGatewayAttachmentId: props.transitGatewayVpcAttachment.transitGatewayAttachmentId,

packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-route-table-propagation.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CfnTransitGatewayRouteTablePropagation } from 'aws-cdk-lib/aws-ec2';
33
import { Construct } from 'constructs';
44
import { ITransitGatewayAttachment } from './transit-gateway-attachment';
55
import { ITransitGatewayRouteTable } from './transit-gateway-route-table';
6+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
67

78
/**
89
* Represents a Transit Gateway Route Table Propagation.
@@ -50,6 +51,8 @@ export class TransitGatewayRouteTablePropagation extends Resource implements ITr
5051

5152
constructor(scope: Construct, id: string, props: TransitGatewayRouteTablePropagationProps) {
5253
super(scope, id);
54+
// Enhanced CDK Analytics Telemetry
55+
addConstructMetadata(this, props);
5356

5457
const resource = new CfnTransitGatewayRouteTablePropagation(this, id, {
5558
transitGatewayAttachmentId: props.transitGatewayVpcAttachment.transitGatewayAttachmentId,

packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-route-table.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ITransitGatewayAttachment } from './transit-gateway-attachment';
66
import { TransitGatewayRoute, TransitGatewayBlackholeRoute, ITransitGatewayRoute } from './transit-gateway-route';
77
import { ITransitGatewayRouteTableAssociation, TransitGatewayRouteTableAssociation } from './transit-gateway-route-table-association';
88
import { ITransitGatewayRouteTablePropagation, TransitGatewayRouteTablePropagation } from './transit-gateway-route-table-propagation';
9+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
910

1011
/**
1112
* Represents a Transit Gateway Route Table.
@@ -109,6 +110,8 @@ export class TransitGatewayRouteTable extends TransitGatewayRouteTableBase {
109110

110111
constructor(scope: Construct, id: string, props: TransitGatewayRouteTableProps) {
111112
super(scope, id);
113+
// Enhanced CDK Analytics Telemetry
114+
addConstructMetadata(this, props);
112115

113116
const resource = new CfnTransitGatewayRouteTable(this, id, {
114117
transitGatewayId: props.transitGateway.transitGatewayId,

packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-route.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Construct } from 'constructs';
33
import { CfnTransitGatewayRoute } from 'aws-cdk-lib/aws-ec2';
44
import { ITransitGatewayRouteTable } from './transit-gateway-route-table';
55
import { ITransitGatewayAttachment } from './transit-gateway-attachment';
6+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
67

78
/**
89
* Represents a Transit Gateway Route.
@@ -87,6 +88,8 @@ export class TransitGatewayRoute extends TransitGatewayRouteBase {
8788

8889
constructor(scope: Construct, id: string, props: TransitGatewayRouteProps) {
8990
super(scope, id);
91+
// Enhanced CDK Analytics Telemetry
92+
addConstructMetadata(this, props);
9093

9194
this.resource = new CfnTransitGatewayRoute(this, 'TransitGatewayRoute', {
9295
blackhole: false,
@@ -112,6 +115,8 @@ export class TransitGatewayBlackholeRoute extends TransitGatewayRouteBase {
112115

113116
constructor(scope: Construct, id: string, props: TransitGatewayBlackholeRouteProps) {
114117
super(scope, id);
118+
// Enhanced CDK Analytics Telemetry
119+
addConstructMetadata(this, props);
115120

116121
const resource = new CfnTransitGatewayRoute(this, id, {
117122
blackhole: true,

packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway-vpc-attachment.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ITransitGatewayAttachment, TransitGatewayAttachmentBase } from './trans
77
import { getFeatureStatus } from './util';
88
import { ITransitGatewayRouteTable } from './transit-gateway-route-table';
99
import { Annotations } from 'aws-cdk-lib';
10+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
1011

1112
/**
1213
* Options for Transit Gateway VPC Attachment.
@@ -131,6 +132,8 @@ export class TransitGatewayVpcAttachment extends TransitGatewayAttachmentBase im
131132

132133
constructor(scope: Construct, id: string, props: TransitGatewayVpcAttachmentProps) {
133134
super(scope, id);
135+
// Enhanced CDK Analytics Telemetry
136+
addConstructMetadata(this, props);
134137

135138
this._resource = new CfnTransitGatewayAttachment(this, id, {
136139
subnetIds: props.subnets.map((subnet) => subnet.subnetId),

packages/@aws-cdk/aws-ec2-alpha/lib/transit-gateway.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IRouteTarget } from './route';
77
import { TransitGatewayRouteTableAssociation } from './transit-gateway-route-table-association';
88
import { TransitGatewayRouteTablePropagation } from './transit-gateway-route-table-propagation';
99
import { getFeatureStatus, TransitGatewayFeatureStatus } from './util';
10+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
1011

1112
/**
1213
* Represents a Transit Gateway.
@@ -222,6 +223,8 @@ export class TransitGateway extends TransitGatewayBase {
222223

223224
constructor(scope: Construct, id: string, props: TransitGatewayProps = {}) {
224225
super(scope, id);
226+
// Enhanced CDK Analytics Telemetry
227+
addConstructMetadata(this, props);
225228

226229
const resource = new CfnTransitGateway(this, id, {
227230
amazonSideAsn: props.amazonSideAsn ?? undefined,

packages/@aws-cdk/aws-eks-v2-alpha/lib/access-entry.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CfnAccessEntry } from 'aws-cdk-lib/aws-eks';
44
import {
55
Resource, IResource, Aws, Lazy,
66
} from 'aws-cdk-lib/core';
7+
import { MethodMetadata, addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
78

89
/**
910
* Represents an access entry in an Amazon EKS cluster.
@@ -325,6 +326,8 @@ export class AccessEntry extends Resource implements IAccessEntry {
325326

326327
constructor(scope: Construct, id: string, props: AccessEntryProps ) {
327328
super(scope, id);
329+
// Enhanced CDK Analytics Telemetry
330+
addConstructMetadata(this, props);
328331

329332
this.cluster = props.cluster;
330333
this.principal = props.principal;
@@ -356,6 +359,7 @@ export class AccessEntry extends Resource implements IAccessEntry {
356359
* Add the access policies for this entry.
357360
* @param newAccessPolicies - The new access policies to add.
358361
*/
362+
@MethodMetadata()
359363
public addAccessPolicies(newAccessPolicies: IAccessPolicy[]): void {
360364
// add newAccessPolicies to this.accessPolicies
361365
this.accessPolicies.push(...newAccessPolicies);

packages/@aws-cdk/aws-eks-v2-alpha/lib/addon.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Construct } from 'constructs';
22
import { ICluster } from './cluster';
33
import { CfnAddon } from 'aws-cdk-lib/aws-eks';
44
import { ArnFormat, IResource, Resource, Stack, Fn } from 'aws-cdk-lib/core';
5+
import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
56

67
/**
78
* Represents an Amazon EKS Add-On.
@@ -127,6 +128,8 @@ export class Addon extends Resource implements IAddon {
127128
super(scope, id, {
128129
physicalName: props.addonName,
129130
});
131+
// Enhanced CDK Analytics Telemetry
132+
addConstructMetadata(this, props);
130133

131134
this.clusterName = props.cluster.clusterName;
132135
this.addonName = props.addonName;

0 commit comments

Comments
 (0)