Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: physical names in the entire Construct Library #2878

Merged
merged 56 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5e25de2
Final form of the physical names linter rule.
skinny85 Jun 12, 2019
36685a5
Fix @aws-s3.
skinny85 Jun 13, 2019
b22fb30
Fix @aws-iam.
skinny85 Jun 13, 2019
a78cf61
Fix @aws-cloudwatch.
skinny85 Jun 13, 2019
aaeb328
Fix @aws-events.
skinny85 Jun 13, 2019
0cfe389
Change ruleName in OnEventOptions to PhysicalName (needed for structu…
skinny85 Jun 13, 2019
371d4a8
Fix @aws-kms.
skinny85 Jun 13, 2019
6e40b9b
Fix @aws-ssm.
skinny85 Jun 13, 2019
4fa412c
Fix @aws-applicationautoscaling.
skinny85 Jun 13, 2019
4c02908
Fix @aws-ec2.
skinny85 Jun 13, 2019
68ee714
Fix @aws-ecr.
skinny85 Jun 13, 2019
ce136e9
Fix @aws-logs.
skinny85 Jun 13, 2019
f7f12b1
Fix @aws-stepfunctions.
skinny85 Jun 13, 2019
f9d639b
Fix @aws-cloudtrail.
skinny85 Jun 14, 2019
9ca0e97
Fix @aws-codepipeline.
skinny85 Jun 14, 2019
7b3364b
Fix @aws-dynamodb.
skinny85 Jun 14, 2019
1b28bc3
Fix @aws-elasticloadbalancing.
skinny85 Jun 14, 2019
3cd21d4
Fix @aws-glue.
skinny85 Jun 14, 2019
fb4b7da
Fix @aws-kinesis.
skinny85 Jun 14, 2019
e758472
Fix @aws-route53.
skinny85 Jun 14, 2019
13c81c4
Fix @aws-sns.
skinny85 Jun 14, 2019
d75b17f
Fix @aws-sqs.
skinny85 Jun 14, 2019
9393b69
Fix @aws-codecommit.
skinny85 Jun 14, 2019
2aa379f
Fix @aws-lambda.
skinny85 Jun 14, 2019
ea5371c
Fix @aws-cloudformation.
skinny85 Jun 14, 2019
06e746d
Fix @aws-cognito.
skinny85 Jun 14, 2019
d7e2f49
Fix @aws-secretsmanager.
skinny85 Jun 14, 2019
9901854
Fix @aws-ses.
skinny85 Jun 14, 2019
7a6ce5f
Fix @aws-sns-subscriptions.
skinny85 Jun 14, 2019
b7f0e32
Fix @aws-certificatemanager.
skinny85 Jun 14, 2019
1fa0f8a
Fix @aws-dynamodb-global.
skinny85 Jun 14, 2019
9a04370
Fix @aws-codebuild.
skinny85 Jun 14, 2019
731ab0f
Fix @aws-elasticloadbalancingv2.
skinny85 Jun 14, 2019
1d8aedc
Fix @aws-apigateway.
skinny85 Jun 14, 2019
74a428d
Fix @aws-autoscaling.
skinny85 Jun 14, 2019
1b4300c
Fix @aws-servicediscovery.
skinny85 Jun 14, 2019
45ed1ce
Fix @aws-codedeploy.
skinny85 Jun 14, 2019
8621711
Fix @aws-eks.
skinny85 Jun 14, 2019
5495b51
Undo the chnages in @aws-servicediscovery for now, instead opting for…
skinny85 Jun 14, 2019
39ec5c5
Fix @aws-ecs.
skinny85 Jun 14, 2019
65f19cc
Fix @aws-events-targets.
skinny85 Jun 14, 2019
7e540b5
Fix @aws-codepipeline-actions.
skinny85 Jun 14, 2019
3c09a2e
Fix @aws-config.
skinny85 Jun 14, 2019
23fa6a6
Fix @aws-ecs-patterns.
skinny85 Jun 15, 2019
20b2484
Fix @aws-rds.
skinny85 Jun 15, 2019
8a9bbc2
Change the rule to accept property names that are ending substrings o…
skinny85 Jun 15, 2019
b8756de
Correct @aws-iam prop names.
skinny85 Jun 15, 2019
eb11cdc
Correct @aws-lambda prop names.
skinny85 Jun 15, 2019
11adb55
Correct @aws-cognito prop names.
skinny85 Jun 15, 2019
b47bfb5
Correct @aws-elasticloadbalancingv2 prop names.
skinny85 Jun 15, 2019
2e20289
Correct @aws-codedeploy prop names.
skinny85 Jun 15, 2019
ae5a444
Correct @aws-ecs prop names.
skinny85 Jun 15, 2019
39a512f
Correct @aws-codebuild prop names.
skinny85 Jun 15, 2019
eecc35d
Correct @aws-ec2 prop names.
skinny85 Jun 15, 2019
6ec2ceb
Fix decdk.
skinny85 Jun 16, 2019
773da1b
Fix LoadBalancedFargateService.serviceName.
skinny85 Jun 16, 2019
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
10 changes: 6 additions & 4 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import iam = require('@aws-cdk/aws-iam');
import { CfnOutput, Construct, IResource as IResourceBase, Resource, Stack } from '@aws-cdk/cdk';
import { CfnOutput, Construct, IResource as IResourceBase, PhysicalName, Resource, Stack } from '@aws-cdk/cdk';
import { ApiKey, IApiKey } from './api-key';
import { CfnAccount, CfnRestApi } from './apigateway.generated';
import { Deployment } from './deployment';
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface RestApiProps extends ResourceOptions {
*
* @default - ID of the RestApi construct.
*/
readonly restApiName?: string;
readonly restApiName?: PhysicalName;

/**
* Custom header parameters for the request.
Expand Down Expand Up @@ -204,10 +204,12 @@ export class RestApi extends Resource implements IRestApi {
private readonly methods = new Array<Method>();

constructor(scope: Construct, id: string, props: RestApiProps = { }) {
super(scope, id);
super(scope, id, {
physicalName: props.restApiName,
});

const resource = new CfnRestApi(this, 'Resource', {
name: props.restApiName || id,
name: this.physicalName.value || id,
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
description: props.description,
policy: props.policy,
failOnWarnings: props.failOnWarnings,
Expand Down
12 changes: 7 additions & 5 deletions packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
import { Construct, Resource } from '@aws-cdk/cdk';
import { Construct, PhysicalName, Resource } from '@aws-cdk/cdk';
import { CfnVpcLink } from './apigateway.generated';

/**
Expand All @@ -10,7 +10,7 @@ export interface VpcLinkProps {
* The name used to label and identify the VPC link.
* @default automatically generated name
*/
readonly name?: string;
readonly vpcLinkName?: PhysicalName;

/**
* The description of the VPC link.
Expand All @@ -37,14 +37,16 @@ export class VpcLink extends Resource {
public readonly vpcLinkId: string;

constructor(scope: Construct, id: string, props: VpcLinkProps) {
super(scope, id);
super(scope, id, {
physicalName: props.vpcLinkName,
});

const cfnResource = new CfnVpcLink(this, 'Resource', {
name: props.name || this.node.uniqueId,
name: this.physicalName.value || this.node.uniqueId,
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
description: props.description,
targetArns: props.targets.map(nlb => nlb.loadBalancerArn)
});

this.vpcLinkId = cfnResource.vpcLinkId;
}
}
}
11 changes: 9 additions & 2 deletions packages/@aws-cdk/aws-apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@
},
"awslint": {
"exclude": [
"from-method:@aws-cdk/aws-apigateway.Resource"
"from-method:@aws-cdk/aws-apigateway.Resource",
"props-physical-name:@aws-cdk/aws-apigateway.DeploymentProps",
"props-physical-name:@aws-cdk/aws-apigateway.MethodProps",
"props-physical-name:@aws-cdk/aws-apigateway.ProxyResourceProps",
"props-physical-name:@aws-cdk/aws-apigateway.ResourceProps",
"props-physical-name:@aws-cdk/aws-apigateway.StageProps",
"props-physical-name:@aws-cdk/aws-apigateway.UsagePlanProps",
"props-physical-name:@aws-cdk/aws-apigateway.LambdaRestApiProps"
]
},
"stability": "experimental"
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export = {
runtime: lambda.Runtime.Nodejs810,
});
const alias = new lambda.Alias(stack, 'alias', {
aliasName: 'my-alias',
aliasName: cdk.PhysicalName.of('my-alias'),
version: new lambda.Version(stack, 'version', {
lambda: handler
})
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export = {
const api = new apigateway.RestApi(stack, 'restapi', {
deploy: false,
cloudWatchRole: false,
restApiName: 'my-rest-api'
restApiName: cdk.PhysicalName.of('my-rest-api'),
});

api.root.addMethod('GET');
Expand Down Expand Up @@ -176,7 +176,7 @@ export = {
const api = new apigateway.RestApi(stack, 'restapi', {
deploy: false,
cloudWatchRole: false,
restApiName: 'my-rest-api'
restApiName: cdk.PhysicalName.of('my-rest-api'),
});

// WHEN
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/test/test.vpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export = {

// WHEN
new apigateway.VpcLink(stack, 'VpcLink', {
name: 'MyLink',
vpcLinkName: cdk.PhysicalName.of('MyLink'),
targets: [nlb]
});

Expand All @@ -28,4 +28,4 @@ export = {

test.done();
},
};
};
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,10 @@
"engines": {
"node": ">= 8.10.0"
},
"awslint": {
"exclude": [
"props-physical-name:@aws-cdk/aws-applicationautoscaling.ScalableTargetProps"
]
},
"stability": "experimental"
}
}
10 changes: 6 additions & 4 deletions packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import iam = require('@aws-cdk/aws-iam');
import { Construct, IResource, Resource } from '@aws-cdk/cdk';
import { Construct, IResource, PhysicalName, Resource } from '@aws-cdk/cdk';
import { IAutoScalingGroup } from './auto-scaling-group';
import { CfnLifecycleHook } from './autoscaling.generated';
import { ILifecycleHookTarget } from './lifecycle-hook-target';
Expand All @@ -13,7 +13,7 @@ export interface BasicLifecycleHookProps {
*
* @default - Automatically generated name.
*/
readonly lifecycleHookName?: string;
readonly lifecycleHookName?: PhysicalName;

/**
* The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs.
Expand Down Expand Up @@ -92,7 +92,9 @@ export class LifecycleHook extends Resource implements ILifecycleHook {
public readonly lifecycleHookName: string;

constructor(scope: Construct, id: string, props: LifecycleHookProps) {
super(scope, id);
super(scope, id, {
physicalName: props.lifecycleHookName,
});

this.role = props.role || new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('autoscaling.amazonaws.com')
Expand All @@ -104,7 +106,7 @@ export class LifecycleHook extends Resource implements ILifecycleHook {
autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName,
defaultResult: props.defaultResult,
heartbeatTimeout: props.heartbeatTimeoutSec,
lifecycleHookName: props.lifecycleHookName,
lifecycleHookName: this.physicalName.value,
lifecycleTransition: props.lifecycleTransition,
notificationMetadata: props.notificationMetadata,
notificationTargetArn: targetProps.notificationTargetArn,
Expand Down
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@
"exclude": [
"import-props-interface:@aws-cdk/aws-autoscaling.AutoScalingGroupImportProps",
"resource-interface-extends-construct:@aws-cdk/aws-autoscaling.IAutoScalingGroup",
"export:@aws-cdk/aws-autoscaling.IAutoScalingGroup"
"export:@aws-cdk/aws-autoscaling.IAutoScalingGroup",
"props-physical-name:@aws-cdk/aws-autoscaling.AutoScalingGroupProps",
"props-physical-name:@aws-cdk/aws-autoscaling.ScheduledActionProps"
]
},
"stability": "experimental"
}
}
8 changes: 7 additions & 1 deletion packages/@aws-cdk/aws-certificatemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,11 @@
"engines": {
"node": ">= 8.10.0"
},
"awslint": {
"exclude": [
"props-physical-name:@aws-cdk/aws-certificatemanager.CertificateProps",
"props-physical-name:@aws-cdk/aws-certificatemanager.DnsValidatedCertificateProps"
]
},
"stability": "experimental"
}
}
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-cloudformation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@
"exclude": [
"construct-ctor:@aws-cdk/aws-cloudformation.PipelineCloudFormationAction.<initializer>",
"construct-ctor:@aws-cdk/aws-cloudformation.PipelineCloudFormationDeployAction.<initializer>",
"construct-ctor-props-optional:@aws-cdk/aws-cloudformation.AwsCustomResource"
"construct-ctor-props-optional:@aws-cdk/aws-cloudformation.AwsCustomResource",
"props-physical-name:@aws-cdk/aws-cloudformation.CustomResourceProps"
]
},
"stability": "experimental"
}
}
21 changes: 16 additions & 5 deletions packages/@aws-cdk/aws-cloudtrail/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import iam = require('@aws-cdk/aws-iam');
import kms = require('@aws-cdk/aws-kms');
import logs = require('@aws-cdk/aws-logs');
import s3 = require('@aws-cdk/aws-s3');
import { Construct, Resource, Stack } from '@aws-cdk/cdk';
import { Construct, PhysicalName, Resource, ResourceIdentifiers, Stack } from '@aws-cdk/cdk';
import { CfnTrail } from './cloudtrail.generated';

// AWS::CloudTrail CloudFormation Resources:
Expand Down Expand Up @@ -86,7 +86,7 @@ export interface TrailProps {
*
* @default - AWS CloudFormation generated name.
*/
readonly trailName?: string;
readonly trailName?: PhysicalName;

/** An Amazon S3 object key prefix that precedes the name of all log files.
*
Expand Down Expand Up @@ -125,7 +125,9 @@ export class Trail extends Resource {
private eventSelectors: EventSelector[] = [];

constructor(scope: Construct, id: string, props: TrailProps = {}) {
super(scope, id);
super(scope, id, {
physicalName: props.trailName,
});

const s3bucket = new s3.Bucket(this, 'S3', {encryption: s3.BucketEncryption.Unencrypted});
const cloudTrailPrincipal = "cloudtrail.amazonaws.com";
Expand Down Expand Up @@ -168,7 +170,7 @@ export class Trail extends Resource {
enableLogFileValidation: props.enableFileValidation == null ? true : props.enableFileValidation,
isMultiRegionTrail: props.isMultiRegionTrail == null ? true : props.isMultiRegionTrail,
includeGlobalServiceEvents: props.includeGlobalServiceEvents == null ? true : props.includeGlobalServiceEvents,
trailName: props.trailName,
trailName: this.physicalName.value,
kmsKeyId: props.kmsKey && props.kmsKey.keyArn,
s3BucketName: s3bucket.bucketName,
s3KeyPrefix: props.s3KeyPrefix,
Expand All @@ -178,7 +180,16 @@ export class Trail extends Resource {
eventSelectors: this.eventSelectors
});

this.trailArn = trail.trailArn;
const resourceIdentifiers = new ResourceIdentifiers(this, {
arn: trail.trailArn,
name: trail.trailName,
arnComponents: {
service: 'cloudtrail',
resource: 'trail',
resourceName: this.physicalName.value,
},
});
this.trailArn = resourceIdentifiers.arn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we enforce using this and not just trail.trailArn? Seems voluntary... I am worried that most people will not know to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine; adding this later is a backwards-compatible change.

this.trailSnsTopicArn = trail.trailSnsTopicArn;

const s3BucketPolicy = s3bucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy;
Expand Down
23 changes: 18 additions & 5 deletions packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct, IResource, Lazy, Resource, Stack } from '@aws-cdk/cdk';
import { Construct, IResource, Lazy, Resource, ResourceIdentifiers, Stack } from '@aws-cdk/cdk';
import { IAlarmAction } from './alarm-action';
import { CfnAlarm } from './cloudwatch.generated';
import { HorizontalAnnotation } from './graph';
Expand Down Expand Up @@ -114,14 +114,16 @@ export class Alarm extends Resource implements IAlarm {
private readonly annotation: HorizontalAnnotation;

constructor(scope: Construct, id: string, props: AlarmProps) {
super(scope, id);
super(scope, id, {
physicalName: props.alarmName,
});

const comparisonOperator = props.comparisonOperator || ComparisonOperator.GreaterThanOrEqualToThreshold;

const alarm = new CfnAlarm(this, 'Resource', {
// Meta
alarmDescription: props.alarmDescription,
alarmName: props.alarmName,
alarmName: this.physicalName.value,

// Evaluation
comparisonOperator,
Expand All @@ -141,8 +143,19 @@ export class Alarm extends Resource implements IAlarm {
...metricJson(props.metric)
});

this.alarmArn = alarm.alarmArn;
this.alarmName = alarm.alarmName;
const resourceIdentifiers = new ResourceIdentifiers(this, {
arn: alarm.alarmArn,
name: alarm.alarmName,
arnComponents: {
service: 'cloudwatch',
resource: 'alarm',
resourceName: this.physicalName.value,
sep: ':',
},
});

this.alarmArn = resourceIdentifiers.arn;
this.alarmName = resourceIdentifiers.name;
this.metric = props.metric;
this.annotation = {
// tslint:disable-next-line:max-line-length
Expand Down
10 changes: 6 additions & 4 deletions packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Construct, Lazy, Resource, Stack } from "@aws-cdk/cdk";
import { Construct, Lazy, PhysicalName, Resource, Stack } from "@aws-cdk/cdk";
import { CfnDashboard } from './cloudwatch.generated';
import { Column, Row } from "./layout";
import { IWidget } from "./widget";
Expand All @@ -14,7 +14,7 @@ export interface DashboardProps {
*
* @default Automatically generated name
*/
readonly dashboardName?: string;
readonly dashboardName?: PhysicalName;

/**
* The start of the time range to use for each widget on the dashboard.
Expand Down Expand Up @@ -54,10 +54,12 @@ export class Dashboard extends Resource {
private readonly rows: IWidget[] = [];

constructor(scope: Construct, id: string, props?: DashboardProps) {
super(scope, id);
super(scope, id, {
physicalName: props && props.dashboardName,
});

new CfnDashboard(this, 'Resource', {
dashboardName: (props && props.dashboardName) || undefined,
dashboardName: this.physicalName.value,
dashboardBody: Lazy.stringValue({ produce: () => {
const column = new Column(...this.rows);
column.position(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export interface MetricAlarmProps {
*
* @default Automatically generated name
*/
readonly alarmName?: string;
readonly alarmName?: cdk.PhysicalName;

/**
* Description for the alarm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const alarm = metric.newAlarm(stack, 'Alarm', {
});

const dashboard = new cloudwatch.Dashboard(stack, 'Dash', {
dashboardName: 'MyCustomDashboardName',
dashboardName: cdk.PhysicalName.of('MyCustomDashboardName'),
start: '-9H',
end: '2018-12-17T06:00:00.000Z',
periodOverride: PeriodOverride.Inherit
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudwatch/test/test.dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, haveResource, isSuperObject } from '@aws-cdk/assert';
import { App, Stack } from '@aws-cdk/cdk';
import { App, PhysicalName, Stack } from '@aws-cdk/cdk';
import { Test } from 'nodeunit';
import { Dashboard, GraphWidget, PeriodOverride, TextWidget } from '../lib';

Expand Down Expand Up @@ -127,7 +127,7 @@ export = {

// WHEN
new Dashboard(stack, 'MyDashboard', {
dashboardName: 'MyCustomDashboardName'
dashboardName: PhysicalName.of('MyCustomDashboardName'),
});

// THEN
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ export class Project extends ProjectBase {
public addToRoleInlinePolicy(statement: iam.PolicyStatement) {
if (this.role) {
const policy = new iam.Policy(this, 'PolicyDocument', {
policyName: 'CodeBuildEC2Policy',
policyName: PhysicalName.of('CodeBuildEC2Policy'),
statements: [statement]
});
this.role.attachInlinePolicy(policy);
Expand Down
Loading