Skip to content

Commit aa61dfb

Browse files
moofish32Elad Ben-Israel
authored and
Elad Ben-Israel
committed
feat(cdk): Expose props in CFN resources and remove propertyOverrides (#2372) (#2372)
Modify the generation of CFN resources to create Class members for each CloudFormation Property. This removes the need for the property override solution implemented previously. CloudFormation Resource attributes are now prefixed with `attr` instead of resource name. The RefKind patches are removed. All L2 resources have been updated to consume the new attribute names. The Ref attributes are removed and the new `refAsString` is used. Added tagging support for AppSync, AppMesh, StepFunctions. Token now supports `number` types, so the generated code no longer treats number as non-tokenizable. Fixes #2100 BREAKING CHANGE: All L1 ("Cfn") Resources attributes are now prefixed with `attr` instead of the resource type. For example, in S3 `bucket.bucketArn` is now `bucket.attrArn`. * `propertyOverrides` has been removed from all "Cfn" resources, instead users can now read/write resource properties directly on the resource class. For example, instead of `lambda.propertyOverrides.runtime` just use `lambda.runtime`.
1 parent be574a1 commit aa61dfb

File tree

90 files changed

+417
-5352
lines changed

Some content is hidden

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

90 files changed

+417
-5352
lines changed

packages/@aws-cdk/aws-apigateway/lib/deployment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Deployment extends Resource {
7676
}
7777

7878
this.api = props.api;
79-
this.deploymentId = Lazy.stringValue({ produce: () => this.resource.deploymentId });
79+
this.deploymentId = Lazy.stringValue({ produce: () => this.resource.refAsString });
8080
}
8181

8282
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class Resource extends ResourceBase {
211211
};
212212
const resource = new CfnResource(this, 'Resource', resourceProps);
213213

214-
this.resourceId = resource.resourceId;
214+
this.resourceId = resource.refAsString;
215215
this.restApi = props.parent.restApi;
216216

217217
// render resource path (special case for root)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class RestApi extends Resource implements IRestApi {
228228
this.configureCloudWatchRole(resource);
229229
}
230230

231-
this.root = new RootResource(this, props, resource.restApiRootResourceId);
231+
this.root = new RootResource(this, props, resource.attrRootResourceId);
232232
}
233233

234234
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export class VpcLink extends Resource {
4545
targetArns: props.targets.map(nlb => nlb.loadBalancerArn)
4646
});
4747

48-
this.vpcLinkId = cfnResource.vpcLinkId;
48+
this.vpcLinkId = cfnResource.refAsString;
4949
}
50-
}
50+
}

packages/@aws-cdk/aws-apigateway/test/test.resource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ export = {
286286

287287
}
288288
}
289-
};
289+
};

packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class ScalableTarget extends Resource implements IScalableTarget {
119119
serviceNamespace: props.serviceNamespace
120120
});
121121

122-
this.scalableTargetId = resource.scalableTargetId;
122+
this.scalableTargetId = resource.refAsString;
123123
}
124124

125125
/**
@@ -269,4 +269,4 @@ export enum ServiceNamespace {
269269
* Custom Resource
270270
*/
271271
CustomResource = 'custom-resource',
272-
}
272+
}

packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class StepScalingAction extends cdk.Construct {
9393
} as CfnScalingPolicy.StepScalingPolicyConfigurationProperty
9494
});
9595

96-
this.scalingPolicyArn = resource.scalingPolicyArn;
96+
this.scalingPolicyArn = resource.refAsString;
9797
}
9898

9999
/**
@@ -190,4 +190,4 @@ export interface AdjustmentTier {
190190
* @default +Infinity
191191
*/
192192
readonly upperBound?: number;
193-
}
193+
}

packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct {
141141
}
142142
});
143143

144-
this.scalingPolicyArn = resource.scalingPolicyArn;
144+
this.scalingPolicyArn = resource.refAsString;
145145
}
146146
}
147147

@@ -171,4 +171,4 @@ export enum PredefinedMetric {
171171
SageMakerVariantInvocationsPerInstance = 'SageMakerVariantInvocationsPerInstance',
172172
ECSServiceAverageCPUUtilization = 'ECSServiceAverageCPUUtilization',
173173
ECSServiceAverageMemoryUtilization = 'ECSServiceAverageMemoryUtilization',
174-
}
174+
}

packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
442442

443443
this.autoScalingGroup = new CfnAutoScalingGroup(this, 'ASG', asgProps);
444444
this.osType = machineImage.os.type;
445-
this.autoScalingGroupName = this.autoScalingGroup.autoScalingGroupName;
445+
this.autoScalingGroupName = this.autoScalingGroup.refAsString;
446446
this.autoScalingGroupArn = Stack.of(this).formatArn({
447447
service: 'autoscaling',
448448
resource: 'autoScalingGroup:*:autoScalingGroupName',

packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class LifecycleHook extends Resource implements ILifecycleHook {
116116
// lifecycle hook.
117117
resource.node.addDependency(this.role);
118118

119-
this.lifecycleHookName = resource.lifecycleHookName;
119+
this.lifecycleHookName = resource.refAsString;
120120
}
121121
}
122122

packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class StepScalingAction extends cdk.Construct {
8181
stepAdjustments: cdk.Lazy.anyValue({ produce: () => this.adjustments }),
8282
});
8383

84-
this.scalingPolicyArn = resource.scalingPolicyArn;
84+
this.scalingPolicyArn = resource.refAsString;
8585
}
8686

8787
/**
@@ -178,4 +178,4 @@ export interface AdjustmentTier {
178178
* @default +Infinity
179179
*/
180180
readonly upperBound?: number;
181-
}
181+
}

packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct {
143143
}
144144
});
145145

146-
this.scalingPolicyArn = this.resource.scalingPolicyArn;
146+
this.scalingPolicyArn = this.resource.refAsString;
147147
}
148148
}
149149

packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class Certificate extends Resource implements ICertificate {
8787
domainValidationOptions: allDomainNames.map(domainValidationOption),
8888
});
8989

90-
this.certificateArn = cert.certificateArn;
90+
this.certificateArn = cert.refAsString;
9191

9292
/**
9393
* Return the domain validation options for the given domain

packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function uppercaseProperties(props: Properties): Properties {
116116

117117
function renderResourceType(resourceType?: string) {
118118
if (!resourceType) {
119-
return CfnCustomResource.resourceTypeName;
119+
return CfnCustomResource.cfnResourceTypeName;
120120
}
121121

122122
if (!resourceType.startsWith('Custom::')) {

packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ export class CloudFrontWebDistribution extends cdk.Construct implements IDistrib
714714
}
715715

716716
const distribution = new CfnDistribution(this, 'CFDistribution', { distributionConfig });
717-
this.domainName = distribution.distributionDomainName;
718-
this.distributionId = distribution.distributionId;
717+
this.domainName = distribution.attrDomainName;
718+
this.distributionId = distribution.refAsString;
719719
}
720720

721721
private toBehavior(input: BehaviorWithOrigin, protoPolicy?: ViewerProtocolPolicy) {

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-s3.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ const dist = new cloudfront.CloudFrontWebDistribution(stack, 'Distribution', {
1717
behaviors: [{ isDefaultBehavior: true }],
1818
s3OriginSource: {
1919
s3BucketSource: bucket,
20-
originAccessIdentityId: oai.cloudFrontOriginAccessIdentityId,
20+
originAccessIdentityId: oai.refAsString,
2121
},
2222
}]
2323
});
2424
bucket.addToResourcePolicy(new iam.PolicyStatement({
2525
actions: ['s3:Get*', 's3:List*'],
2626
resources: [bucket.bucketArn, bucket.arnForObjects('*')],
27-
principals: [new iam.CanonicalUserPrincipal(oai.cloudFrontOriginAccessIdentityS3CanonicalUserId)]
27+
principals: [new iam.CanonicalUserPrincipal(oai.attrS3CanonicalUserId)],
2828
}));
2929

3030
new cdk.CfnOutput(stack, 'DistributionDomainName', { value: dist.domainName });

packages/@aws-cdk/aws-cloudtrail/lib/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class Trail extends Resource {
156156

157157
logsRole.addToPolicy(new iam.PolicyStatement({
158158
actions: ["logs:PutLogEvents", "logs:CreateLogStream"],
159-
resources: [logGroup.logGroupArn],
159+
resources: [logGroup.attrArn],
160160
}));
161161
}
162162
if (props.managementEvents) {
@@ -177,14 +177,14 @@ export class Trail extends Resource {
177177
kmsKeyId: props.kmsKey && props.kmsKey.keyArn,
178178
s3BucketName: s3bucket.bucketName,
179179
s3KeyPrefix: props.s3KeyPrefix,
180-
cloudWatchLogsLogGroupArn: logGroup && logGroup.logGroupArn,
180+
cloudWatchLogsLogGroupArn: logGroup && logGroup.attrArn,
181181
cloudWatchLogsRoleArn: logsRole && logsRole.roleArn,
182182
snsTopicName: props.snsTopic,
183183
eventSelectors: this.eventSelectors
184184
});
185185

186-
this.trailArn = trail.trailArn;
187-
this.trailSnsTopicArn = trail.trailSnsTopicArn;
186+
this.trailArn = trail.attrArn;
187+
this.trailSnsTopicArn = trail.attrSnsTopicArn;
188188

189189
const s3BucketPolicy = s3bucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy;
190190
trail.node.addDependency(s3BucketPolicy);

packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ export class Alarm extends Resource implements IAlarm {
141141
...metricJson(props.metric)
142142
});
143143

144-
this.alarmArn = alarm.alarmArn;
145-
this.alarmName = alarm.alarmName;
144+
this.alarmArn = alarm.attrArn;
145+
this.alarmName = alarm.refAsString;
146146
this.metric = props.metric;
147147
this.annotation = {
148148
// tslint:disable-next-line:max-line-length

packages/@aws-cdk/aws-codebuild/lib/project.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ export class Project extends ProjectBase {
706706
});
707707

708708
const resourceIdentifiers = new ResourceIdentifiers(this, {
709-
arn: resource.projectArn,
710-
name: resource.projectName,
709+
arn: resource.attrArn,
710+
name: resource.refAsString,
711711
arnComponents: {
712712
service: 'codebuild',
713713
resource: 'project',

packages/@aws-cdk/aws-codecommit/lib/repository.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,19 @@ export class Repository extends RepositoryBase {
284284
}
285285

286286
public get repositoryArn() {
287-
return this.repository.repositoryArn;
287+
return this.repository.attrArn;
288288
}
289289

290290
public get repositoryCloneUrlHttp() {
291-
return this.repository.repositoryCloneUrlHttp;
291+
return this.repository.attrCloneUrlHttp;
292292
}
293293

294294
public get repositoryCloneUrlSsh() {
295-
return this.repository.repositoryCloneUrlSsh;
295+
return this.repository.attrCloneUrlSsh;
296296
}
297297

298298
public get repositoryName() {
299-
return this.repository.repositoryName;
299+
return this.repository.attrName;
300300
}
301301

302302
/**

packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
166166
autoRollbackConfiguration: cdk.Lazy.anyValue({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
167167
});
168168

169-
this.deploymentGroupName = resource.deploymentGroupName;
169+
this.deploymentGroupName = resource.refAsString;
170170
this.deploymentGroupArn = arnForDeploymentGroup(this.application.applicationName, this.deploymentGroupName);
171171

172172
if (props.preHook) {
@@ -179,7 +179,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
179179
(props.alias.node.findChild('Resource') as lambda.CfnAlias).options.updatePolicy = {
180180
codeDeployLambdaAliasUpdate: {
181181
applicationName: this.application.applicationName,
182-
deploymentGroupName: resource.deploymentGroupName,
182+
deploymentGroupName: resource.refAsString,
183183
beforeAllowTrafficHook: cdk.Lazy.stringValue({ produce: () => this.preHook && this.preHook.functionName }),
184184
afterAllowTrafficHook: cdk.Lazy.stringValue({ produce: () => this.postHook && this.postHook.functionName }),
185185
}

packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase {
303303
autoRollbackConfiguration: cdk.Lazy.anyValue({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
304304
});
305305

306-
this.deploymentGroupName = resource.deploymentGroupName;
306+
this.deploymentGroupName = resource.refAsString;
307307
this.deploymentGroupArn = arnForDeploymentGroup(this.application.applicationName, this.deploymentGroupName);
308308
}
309309

packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class Pipeline extends PipelineBase {
256256
this.artifactBucket.grantReadWrite(this.role);
257257

258258
this.pipelineName = codePipeline.refAsString;
259-
this.pipelineVersion = codePipeline.pipelineVersion;
259+
this.pipelineVersion = codePipeline.attrVersion;
260260
this.crossRegionReplicationBuckets = props.crossRegionReplicationBuckets || {};
261261
this.artifactStores = {};
262262

packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export class UserPoolClient extends Resource {
7676
explicitAuthFlows: props.enabledAuthFlows
7777
});
7878

79-
this.userPoolClientId = resource.userPoolClientId;
80-
this.userPoolClientClientSecret = resource.userPoolClientClientSecret;
81-
this.userPoolClientName = resource.userPoolClientName;
79+
this.userPoolClientId = resource.refAsString;
80+
this.userPoolClientClientSecret = resource.attrClientSecret;
81+
this.userPoolClientName = resource.attrName;
8282
}
83-
}
83+
}

packages/@aws-cdk/aws-cognito/lib/user-pool.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ export class UserPool extends Resource implements IUserPool {
395395
autoVerifiedAttributes: props.autoVerifiedAttributes,
396396
lambdaConfig: Lazy.anyValue({ produce: () => this.triggers })
397397
});
398-
this.userPoolId = userPool.userPoolId;
399-
this.userPoolArn = userPool.userPoolArn;
400-
this.userPoolProviderName = userPool.userPoolProviderName;
401-
this.userPoolProviderUrl = userPool.userPoolProviderUrl;
398+
this.userPoolId = userPool.refAsString;
399+
this.userPoolArn = userPool.attrArn;
400+
this.userPoolProviderName = userPool.attrProviderName;
401+
this.userPoolProviderUrl = userPool.attrProviderUrl;
402402
}
403403

404404
/**

packages/@aws-cdk/aws-config/lib/rule.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ export class ManagedRule extends RuleNew {
262262
}
263263
});
264264

265-
this.configRuleName = rule.configRuleName;
266-
this.configRuleArn = rule.configRuleArn;
267-
this.configRuleId = rule.configRuleId;
268-
this.configRuleComplianceType = rule.configRuleComplianceType;
265+
this.configRuleName = rule.refAsString;
266+
this.configRuleArn = rule.attrArn;
267+
this.configRuleId = rule.attrConfigRuleId;
268+
this.configRuleComplianceType = rule.attrComplianceType;
269269

270270
this.isManaged = true;
271271
}
@@ -366,10 +366,10 @@ export class CustomRule extends RuleNew {
366366
}
367367
});
368368

369-
this.configRuleName = rule.configRuleName;
370-
this.configRuleArn = rule.configRuleArn;
371-
this.configRuleId = rule.configRuleId;
372-
this.configRuleComplianceType = rule.configRuleComplianceType;
369+
this.configRuleName = rule.refAsString;
370+
this.configRuleArn = rule.attrArn;
371+
this.configRuleId = rule.attrConfigRuleId;
372+
this.configRuleComplianceType = rule.attrComplianceType;
373373

374374
if (props.configurationChanges) {
375375
this.isCustomWithChanges = true;

packages/@aws-cdk/aws-dynamodb/lib/table.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ export class Table extends Resource {
248248

249249
if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.tableName); }
250250

251-
this.tableArn = this.table.tableArn;
252-
this.tableName = this.table.tableName;
253-
this.tableStreamArn = this.table.tableStreamArn;
251+
this.tableArn = this.table.attrArn;
252+
this.tableName = this.table.refAsString;
253+
this.tableStreamArn = this.table.attrStreamArn;
254254

255255
this.scalingRole = this.makeScalingRole();
256256

packages/@aws-cdk/aws-ec2/lib/security-group.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ export class SecurityGroup extends SecurityGroupBase {
280280
vpcId: props.vpc.vpcId,
281281
});
282282

283-
this.securityGroupId = this.securityGroup.securityGroupId;
284-
this.securityGroupVpcId = this.securityGroup.securityGroupVpcId;
285-
this.securityGroupName = this.securityGroup.securityGroupName;
283+
this.securityGroupId = this.securityGroup.attrGroupId;
284+
this.securityGroupVpcId = this.securityGroup.attrVpcId;
285+
this.securityGroupName = this.securityGroup.refAsString;
286286

287287
this.addDefaultEgressRule();
288288
}

0 commit comments

Comments
 (0)