diff --git a/packages/@aws-cdk/aws-apigateway/lib/api-key.ts b/packages/@aws-cdk/aws-apigateway/lib/api-key.ts index e1c90d781731e..98a5250d6a47e 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/api-key.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/api-key.ts @@ -92,11 +92,11 @@ export class ApiKey extends Resource implements IApiKey { description: props.description, enabled: props.enabled || true, generateDistinctId: props.generateDistinctId, - name: this.physicalName.value, + name: this.physicalName, stageKeys: this.renderStageKeys(props.resources) }); - this.keyId = resource.refAsString; + this.keyId = resource.ref; } private renderStageKeys(resources: RestApi[] | undefined): CfnApiKey.StageKeyProperty[] | undefined { diff --git a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts index e7f0d0ae7dbe7..df826231200f1 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts @@ -1,4 +1,4 @@ -import { Construct, DeletionPolicy, Lazy, Resource, Stack } from '@aws-cdk/cdk'; +import { CfnDeletionPolicy, Construct, Lazy, Resource, Stack } from '@aws-cdk/cdk'; import crypto = require('crypto'); import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated'; import { IRestApi } from './restapi'; @@ -72,11 +72,11 @@ export class Deployment extends Resource { }); if (props.retainDeployments) { - this.resource.options.deletionPolicy = DeletionPolicy.Retain; + this.resource.options.deletionPolicy = CfnDeletionPolicy.Retain; } this.api = props.api; - this.deploymentId = Lazy.stringValue({ produce: () => this.resource.refAsString }); + this.deploymentId = Lazy.stringValue({ produce: () => this.resource.ref }); } /** diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index 304135163d23e..2f297dd7f3ac6 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -123,7 +123,7 @@ export class Method extends Resource { const resource = new CfnMethod(this, 'Resource', methodProps); - this.methodId = resource.refAsString; + this.methodId = resource.ref; props.resource.restApi._attachMethod(this); diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 440fac0c1d824..c94f8b916caff 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -211,7 +211,7 @@ export class Resource extends ResourceBase { }; const resource = new CfnResource(this, 'Resource', resourceProps); - this.resourceId = resource.refAsString; + this.resourceId = resource.ref; this.restApi = props.parent.restApi; // render resource path (special case for root) diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index f09c931ba4f3c..d6e7733855bd0 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -203,7 +203,7 @@ export class RestApi extends Resource implements IRestApi { }); const resource = new CfnRestApi(this, 'Resource', { - name: this.physicalName.value!, + name: this.physicalName, description: props.description, policy: props.policy, failOnWarnings: props.failOnWarnings, @@ -215,7 +215,7 @@ export class RestApi extends Resource implements IRestApi { parameters: props.parameters, }); - this.restApiId = resource.refAsString; + this.restApiId = resource.ref; this.configureDeployment(props); diff --git a/packages/@aws-cdk/aws-apigateway/lib/stage.ts b/packages/@aws-cdk/aws-apigateway/lib/stage.ts index 6af6431c85759..f0e7111bcba79 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/stage.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/stage.ts @@ -197,7 +197,7 @@ export class Stage extends Resource { methodSettings, }); - this.stageName = resource.refAsString; + this.stageName = resource.ref; this.restApi = props.deployment.api; } diff --git a/packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts b/packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts index f71e452210378..9ecf72f2a0b1e 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts @@ -165,7 +165,7 @@ export class UsagePlan extends Resource { this.apiStages.push(...(props.apiStages || [])); - this.usagePlanId = resource.refAsString; + this.usagePlanId = resource.ref; // Add ApiKey when if (props.apiKey) { diff --git a/packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts b/packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts index b850a8b612d49..b8dc3d296d232 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts @@ -47,12 +47,12 @@ export class VpcLink extends Resource { }); const cfnResource = new CfnVpcLink(this, 'Resource', { - name: this.physicalName.value!, + name: this.physicalName, description: props.description, targetArns: Lazy.listValue({ produce: () => this.renderTargets() }) }); - this.vpcLinkId = cfnResource.refAsString; + this.vpcLinkId = cfnResource.ref; if (props.targets) { this.addTargets(...props.targets); diff --git a/packages/@aws-cdk/aws-apigateway/package.json b/packages/@aws-cdk/aws-apigateway/package.json index 67d99d6a13101..e3c8db96c8db9 100644 --- a/packages/@aws-cdk/aws-apigateway/package.json +++ b/packages/@aws-cdk/aws-apigateway/package.json @@ -98,8 +98,8 @@ "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-type:@aws-cdk/aws-apigateway.StageProps.stageName", "props-physical-name:@aws-cdk/aws-apigateway.LambdaRestApiProps" ] }, diff --git a/packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts b/packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts index 902a4112f5cc8..dfceb4b38c259 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts @@ -81,7 +81,7 @@ export = { runtime: lambda.Runtime.Nodejs810, }); const alias = new lambda.Alias(stack, 'alias', { - aliasName: cdk.PhysicalName.of('my-alias'), + aliasName: 'my-alias', version: new lambda.Version(stack, 'version', { lambda: handler }) diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts index 0710b4c399202..23a2c23389fcb 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts @@ -120,7 +120,7 @@ export class ScalableTarget extends Resource implements IScalableTarget { serviceNamespace: props.serviceNamespace }); - this.scalableTargetId = resource.refAsString; + this.scalableTargetId = resource.ref; } /** diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts index 94b5868a363c6..762e8aceae1ad 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts @@ -93,7 +93,7 @@ export class StepScalingAction extends cdk.Construct { } as CfnScalingPolicy.StepScalingPolicyConfigurationProperty }); - this.scalingPolicyArn = resource.refAsString; + this.scalingPolicyArn = resource.ref; } /** diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts index 7e305ea6571a7..4c00ce658bbe2 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts @@ -141,7 +141,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct { } }); - this.scalingPolicyArn = resource.refAsString; + this.scalingPolicyArn = resource.ref; } } diff --git a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts index 7d837a925a28a..dd6d5cdfbe66f 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts @@ -5,7 +5,7 @@ import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); import iam = require('@aws-cdk/aws-iam'); import sns = require('@aws-cdk/aws-sns'); -import { AutoScalingRollingUpdate, Construct, Fn, IResource, Lazy, Resource, Stack, Tag } from '@aws-cdk/cdk'; +import { CfnAutoScalingRollingUpdate, Construct, Fn, IResource, Lazy, Resource, Stack, Tag } from '@aws-cdk/cdk'; import { CfnAutoScalingGroup, CfnAutoScalingGroupProps, CfnLaunchConfiguration } from './autoscaling.generated'; import { BasicLifecycleHookProps, LifecycleHook } from './lifecycle-hook'; import { BasicScheduledActionProps, ScheduledAction } from './scheduled-action'; @@ -394,7 +394,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements keyName: props.keyName, instanceType: props.instanceType.toString(), securityGroups: securityGroupsToken, - iamInstanceProfile: iamProfile.refAsString, + iamInstanceProfile: iamProfile.ref, userData: userDataToken, associatePublicIpAddress: props.associatePublicIpAddress, spotPrice: props.spotPrice, @@ -419,7 +419,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements minSize: minCapacity.toString(), maxSize: maxCapacity.toString(), desiredCapacity: desiredCapacity.toString(), - launchConfigurationName: launchConfig.refAsString, + launchConfigurationName: launchConfig.ref, loadBalancerNames: Lazy.listValue({ produce: () => this.loadBalancerNames }, { omitEmpty: true }), targetGroupArns: Lazy.listValue({ produce: () => this.targetGroupArns }, { omitEmpty: true }), notificationConfigurations: !props.notificationsTopic ? undefined : [ @@ -442,7 +442,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements this.autoScalingGroup = new CfnAutoScalingGroup(this, 'ASG', asgProps); this.osType = machineImage.os.type; - this.autoScalingGroupName = this.autoScalingGroup.refAsString; + this.autoScalingGroupName = this.autoScalingGroup.ref; this.autoScalingGroupArn = Stack.of(this).formatArn({ service: 'autoscaling', resource: 'autoScalingGroup:*:autoScalingGroupName', @@ -665,7 +665,7 @@ export enum ScalingProcess { /** * Render the rolling update configuration into the appropriate object */ -function renderRollingUpdateConfig(config: RollingUpdateConfiguration = {}): AutoScalingRollingUpdate { +function renderRollingUpdateConfig(config: RollingUpdateConfiguration = {}): CfnAutoScalingRollingUpdate { const waitOnResourceSignals = config.minSuccessfulInstancesPercent !== undefined ? true : false; const pauseTimeSec = config.pauseTimeSec !== undefined ? config.pauseTimeSec : (waitOnResourceSignals ? 300 : 0); diff --git a/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts b/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts index 95ff67ffba3f6..50d8edd0e0cf2 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts @@ -106,7 +106,7 @@ export class LifecycleHook extends Resource implements ILifecycleHook { autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName, defaultResult: props.defaultResult, heartbeatTimeout: props.heartbeatTimeoutSec, - lifecycleHookName: this.physicalName.value, + lifecycleHookName: this.physicalName, lifecycleTransition: props.lifecycleTransition, notificationMetadata: props.notificationMetadata, notificationTargetArn: targetProps.notificationTargetArn, @@ -118,7 +118,7 @@ export class LifecycleHook extends Resource implements ILifecycleHook { // lifecycle hook. resource.node.addDependency(this.role); - this.lifecycleHookName = resource.refAsString; + this.lifecycleHookName = resource.ref; } } diff --git a/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts b/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts index 38b4109dfd2d8..a955fe902be86 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts @@ -81,7 +81,7 @@ export class StepScalingAction extends cdk.Construct { stepAdjustments: cdk.Lazy.anyValue({ produce: () => this.adjustments }), }); - this.scalingPolicyArn = resource.refAsString; + this.scalingPolicyArn = resource.ref; } /** diff --git a/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts b/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts index 77ee46ad820c2..e01d403d98a29 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts @@ -143,7 +143,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct { } }); - this.scalingPolicyArn = this.resource.refAsString; + this.scalingPolicyArn = this.resource.ref; } } diff --git a/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts b/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts index 0ca9bcbba7f68..9355b6fa449be 100644 --- a/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts +++ b/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts @@ -87,7 +87,7 @@ export class Certificate extends Resource implements ICertificate { domainValidationOptions: allDomainNames.map(domainValidationOption), }); - this.certificateArn = cert.refAsString; + this.certificateArn = cert.ref; /** * Return the domain validation options for the given domain diff --git a/packages/@aws-cdk/aws-cloudformation/test/integ.aws-custom-resource.ts b/packages/@aws-cdk/aws-cloudformation/test/integ.aws-custom-resource.ts index b3eb41d3b19df..8aca2b3bf2cc6 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/integ.aws-custom-resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/integ.aws-custom-resource.ts @@ -2,6 +2,7 @@ import sns = require('@aws-cdk/aws-sns'); import ssm = require('@aws-cdk/aws-ssm'); import cdk = require('@aws-cdk/cdk'); +import { Token } from '@aws-cdk/cdk'; import { AwsCustomResource } from '../lib'; const app = new cdk.App(); @@ -46,8 +47,8 @@ const getParameter = new AwsCustomResource(stack, 'GetParameter', { } }); -new cdk.CfnOutput(stack, 'MessageId', { value: snsPublish.getData('MessageId') }); -new cdk.CfnOutput(stack, 'TopicArn', { value: listTopics.getData('Topics.0.TopicArn') }); -new cdk.CfnOutput(stack, 'ParameterValue', { value: getParameter.getData('Parameter.Value') }); +new cdk.CfnOutput(stack, 'MessageId', { value: Token.asString(snsPublish.getData('MessageId')) }); +new cdk.CfnOutput(stack, 'TopicArn', { value: Token.asString(listTopics.getData('Topics.0.TopicArn')) }); +new cdk.CfnOutput(stack, 'ParameterValue', { value: Token.asString(getParameter.getData('Parameter.Value')) }); app.synth(); diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index 3823553af8704..69925ad096bb4 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -715,7 +715,7 @@ export class CloudFrontWebDistribution extends cdk.Construct implements IDistrib const distribution = new CfnDistribution(this, 'CFDistribution', { distributionConfig }); this.domainName = distribution.attrDomainName; - this.distributionId = distribution.refAsString; + this.distributionId = distribution.ref; } private toBehavior(input: BehaviorWithOrigin, protoPolicy?: ViewerProtocolPolicy) { diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-lambda-association.ts b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-lambda-association.ts index a77e9d6da3b5e..70f7fcd46f811 100644 --- a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-lambda-association.ts +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-lambda-association.ts @@ -35,4 +35,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', { ] }); -app.run(); +app.synth(); diff --git a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-s3.ts b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-s3.ts index 0dd1f6b89a1ea..19612e6d83a6e 100644 --- a/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-s3.ts +++ b/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-s3.ts @@ -17,7 +17,7 @@ const dist = new cloudfront.CloudFrontWebDistribution(stack, 'Distribution', { behaviors: [{ isDefaultBehavior: true }], s3OriginSource: { s3BucketSource: bucket, - originAccessIdentityId: oai.refAsString, + originAccessIdentityId: oai.ref, }, }] }); diff --git a/packages/@aws-cdk/aws-cloudtrail/lib/index.ts b/packages/@aws-cdk/aws-cloudtrail/lib/index.ts index dc76d342c39a3..392f9de12e90a 100644 --- a/packages/@aws-cdk/aws-cloudtrail/lib/index.ts +++ b/packages/@aws-cdk/aws-cloudtrail/lib/index.ts @@ -175,7 +175,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: this.physicalName.value, + trailName: this.physicalName, kmsKeyId: props.kmsKey && props.kmsKey.keyArn, s3BucketName: s3bucket.bucketName, s3KeyPrefix: props.s3KeyPrefix, @@ -191,7 +191,7 @@ export class Trail extends Resource { arnComponents: { service: 'cloudtrail', resource: 'trail', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.trailArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts index 7ee032f5bf6bc..a23e2f0fa5fdc 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts @@ -126,7 +126,7 @@ export class Alarm extends Resource implements IAlarm { const alarm = new CfnAlarm(this, 'Resource', { // Meta alarmDescription: props.alarmDescription, - alarmName: this.physicalName.value, + alarmName: this.physicalName, // Evaluation comparisonOperator, @@ -153,11 +153,11 @@ export class Alarm extends Resource implements IAlarm { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: alarm.attrArn, - name: alarm.refAsString, + name: alarm.ref, arnComponents: { service: 'cloudwatch', resource: 'alarm', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts b/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts index 44e6e1815d46c..fcc6c41fee395 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts @@ -68,7 +68,7 @@ export class Dashboard extends Resource { }); new CfnDashboard(this, 'Resource', { - dashboardName: this.physicalName.value, + dashboardName: this.physicalName, dashboardBody: Lazy.stringValue({ produce: () => { const column = new Column(...this.rows); column.position(0, 0); diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 5db6f1d39d076..d8e89469295db 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -335,7 +335,7 @@ const vpc = new ec2.Vpc(stack, 'MyVPC'); const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { allowAllOutbound: true, description: 'Example', - groupName: 'MySecurityGroup', + securityGroupName: 'MySecurityGroup', vpc: vpc, }); new codebuild.Project(stack, 'MyProject', { diff --git a/packages/@aws-cdk/aws-codebuild/lib/project.ts b/packages/@aws-cdk/aws-codebuild/lib/project.ts index e6993fdfdb694..d495985446b91 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/project.ts @@ -691,7 +691,7 @@ export class Project extends ProjectBase { encryptionKey: props.encryptionKey && props.encryptionKey.keyArn, badgeEnabled: props.badge, cache: cache._toCloudFormation(), - name: this.physicalName.value, + name: this.physicalName, timeoutInMinutes: props.timeout, secondarySources: Lazy.anyValue({ produce: () => this.renderSecondarySources() }), secondaryArtifacts: Lazy.anyValue({ produce: () => this.renderSecondaryArtifacts() }), @@ -703,11 +703,11 @@ export class Project extends ProjectBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: resource.attrArn, - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'codebuild', resource: 'project', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.projectArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts index c5dd286d07514..d0998c2eca2a8 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts @@ -13,8 +13,8 @@ const vpc = new ec2.Vpc(stack, 'MyVPC', { const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { allowAllOutbound: true, description: 'Example', - groupName: cdk.PhysicalName.of('Bob'), - vpc, + securityGroupName: cdk.PhysicalName.of('Bob'), + vpc, }); new codebuild.Project(stack, 'MyProject', { buildSpec: codebuild.BuildSpec.fromObject({ diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index 7d8c6ded5aec5..e43c4ab434f66 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -142,7 +142,7 @@ export = { const stack = new cdk.Stack(); const repo = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: cdk.PhysicalName.of('hello-cdk'), + repositoryName: 'hello-cdk', }); const source = codebuild.Source.codeCommit({ repository: repo, cloneDepth: 2 }); @@ -630,7 +630,7 @@ export = { const bucket = new s3.Bucket(stack, 'MyBucket'); const vpc = new ec2.Vpc(stack, 'MyVPC'); const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { - groupName: cdk.PhysicalName.of('Bob'), + securityGroupName: cdk.PhysicalName.of('Bob'), vpc, allowAllOutbound: true, description: 'Example', @@ -677,7 +677,7 @@ export = { const bucket = new s3.Bucket(stack, 'MyBucket'); const vpc = new ec2.Vpc(stack, 'MyVPC'); const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { - groupName: cdk.PhysicalName.of('Bob'), + securityGroupName: cdk.PhysicalName.of('Bob'), vpc, allowAllOutbound: true, description: 'Example', @@ -699,7 +699,7 @@ export = { const bucket = new s3.Bucket(stack, 'MyBucket'); const vpc = new ec2.Vpc(stack, 'MyVPC'); const securityGroup = new ec2.SecurityGroup(stack, 'SecurityGroup1', { - groupName: cdk.PhysicalName.of('Bob'), + securityGroupName: cdk.PhysicalName.of('Bob'), vpc, allowAllOutbound: true, description: 'Example', @@ -1210,7 +1210,7 @@ export = { } const repo = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: cdk.PhysicalName.of('hello-cdk'), + repositoryName: 'hello-cdk', }); const bucket = new s3.Bucket(stack, 'MyBucket'); diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index 00dbd908b310b..684e6bbda33cc 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -210,9 +210,11 @@ abstract class RepositoryBase extends Resource implements IRepository { export interface RepositoryProps { /** - * Name of the repository. This property is required for all repositories. + * Name of the repository. + * + * This property is required for all CodeCommit repositories. */ - readonly repositoryName: PhysicalName; + readonly repositoryName: string; /** * A description of the repository. Use the description to identify the @@ -277,11 +279,11 @@ export class Repository extends RepositoryBase { constructor(scope: Construct, id: string, props: RepositoryProps) { super(scope, id, { - physicalName: props.repositoryName, + physicalName: PhysicalName.of(props.repositoryName), }); this.repository = new CfnRepository(this, 'Resource', { - repositoryName: this.physicalName.value || '', + repositoryName: props.repositoryName, repositoryDescription: props.description, triggers: this.triggers }); @@ -291,7 +293,7 @@ export class Repository extends RepositoryBase { name: this.repository.attrName, arnComponents: { service: 'codecommit', - resource: this.physicalName.value || '', + resource: props.repositoryName, }, }); diff --git a/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-events.ts b/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-events.ts index 19695fc7052d5..184e53534c669 100644 --- a/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-events.ts +++ b/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-events.ts @@ -6,7 +6,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codecommit-events'); const repo = new codecommit.Repository(stack, 'Repo', { - repositoryName: cdk.PhysicalName.of('aws-cdk-codecommit-events'), + repositoryName: 'aws-cdk-codecommit-events', }); const topic = new sns.Topic(stack, 'MyTopic'); diff --git a/packages/@aws-cdk/aws-codecommit/test/test.codecommit.ts b/packages/@aws-cdk/aws-codecommit/test/test.codecommit.ts index a621e0359dd62..5e8e8a846399c 100644 --- a/packages/@aws-cdk/aws-codecommit/test/test.codecommit.ts +++ b/packages/@aws-cdk/aws-codecommit/test/test.codecommit.ts @@ -1,5 +1,5 @@ import { expect } from '@aws-cdk/assert'; -import { PhysicalName, Stack } from '@aws-cdk/cdk'; +import { Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { Repository, RepositoryProps } from '../lib'; @@ -9,7 +9,7 @@ export = { const stack = new Stack(); const props: RepositoryProps = { - repositoryName: PhysicalName.of('MyRepository'), + repositoryName: 'MyRepository', }; const snsArn = 'arn:aws:sns:*:123456789012:my_topic'; @@ -43,7 +43,7 @@ export = { const stack = new Stack(); const myRepository = new Repository(stack, 'MyRepository', { - repositoryName: PhysicalName.of('MyRepository'), + repositoryName: 'MyRepository', }).notify('myTrigger'); test.throws(() => myRepository.notify('myTrigger')); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts b/packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts index 5c24d1ea562d0..c35f46b65ebb7 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts @@ -65,17 +65,17 @@ export class LambdaApplication extends Resource implements ILambdaApplication { }); const resource = new CfnApplication(this, 'Resource', { - applicationName: this.physicalName.value, + applicationName: this.physicalName, computePlatform: 'Lambda' }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: arnForApplication(resource.refAsString), - name: resource.refAsString, + arn: arnForApplication(resource.ref), + name: resource.ref, arnComponents: { service: 'codedeploy', resource: 'application', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts index e4d1350283625..fd4aa8bf71f54 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts @@ -158,7 +158,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy const resource = new CfnDeploymentGroup(this, 'Resource', { applicationName: this.application.applicationName, serviceRoleArn: this.role.roleArn, - deploymentGroupName: this.physicalName.value, + deploymentGroupName: this.physicalName, deploymentConfigName: (props.deploymentConfig || LambdaDeploymentConfig.AllAtOnce).deploymentConfigName, deploymentStyle: { deploymentType: 'BLUE_GREEN', @@ -169,12 +169,12 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy }); const resourceIdentifiers = new cdk.ResourceIdentifiers(this, { - arn: arnForDeploymentGroup(this.application.applicationName, resource.refAsString), - name: resource.refAsString, + arn: arnForDeploymentGroup(this.application.applicationName, resource.ref), + name: resource.ref, arnComponents: { service: 'codedeploy', resource: 'deploymentgroup', - resourceName: `${this.application.physicalName.value}/${this.physicalName.value}`, + resourceName: `${this.application.physicalName}/${this.physicalName}`, sep: ':', }, }); @@ -188,10 +188,10 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy this.addPostHook(props.postHook); } - (props.alias.node.findChild('Resource') as lambda.CfnAlias).options.updatePolicy = { + (props.alias.node.defaultChild as lambda.CfnAlias).options.updatePolicy = { codeDeployLambdaAliasUpdate: { applicationName: this.application.applicationName, - deploymentGroupName: resource.refAsString, + deploymentGroupName: resource.ref, beforeAllowTrafficHook: cdk.Lazy.stringValue({ produce: () => this.preHook && this.preHook.functionName }), afterAllowTrafficHook: cdk.Lazy.stringValue({ produce: () => this.postHook && this.postHook.functionName }), } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/application.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/application.ts index e6ba379b3fe8a..31d87edc7df68 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/application.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/application.ts @@ -66,17 +66,17 @@ export class ServerApplication extends Resource implements IServerApplication { }); const resource = new CfnApplication(this, 'Resource', { - applicationName: this.physicalName.value, + applicationName: this.physicalName, computePlatform: 'Server', }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: arnForApplication(resource.refAsString), - name: resource.refAsString, + arn: arnForApplication(resource.ref), + name: resource.ref, arnComponents: { service: 'codedeploy', resource: 'application', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts index 9bbab3a996f81..5ac99e284ec7b 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts @@ -111,11 +111,11 @@ export class ServerDeploymentConfig extends cdk.Resource implements IServerDeplo }); const resource = new CfnDeploymentConfig(this, 'Resource', { - deploymentConfigName: this.physicalName.value, + deploymentConfigName: this.physicalName, minimumHealthyHosts: props.minimumHealthyHosts._json, }); - this.deploymentConfigName = resource.refAsString; + this.deploymentConfigName = resource.ref; this.deploymentConfigArn = arnForDeploymentConfig(this.deploymentConfigName); } } diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts index e2e53dff867dd..b9f845d4db290 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts @@ -288,7 +288,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { const resource = new CfnDeploymentGroup(this, 'Resource', { applicationName: this.application.applicationName, - deploymentGroupName: this.physicalName.value, + deploymentGroupName: this.physicalName, serviceRoleArn: this.role.roleArn, deploymentConfigName: props.deploymentConfig && props.deploymentConfig.deploymentConfigName, @@ -306,12 +306,12 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { }); const resourceIdentifiers = new cdk.ResourceIdentifiers(this, { - arn: arnForDeploymentGroup(this.application.applicationName, resource.refAsString), - name: resource.refAsString, + arn: arnForDeploymentGroup(this.application.applicationName, resource.ref), + name: resource.ref, arnComponents: { service: 'codedeploy', resource: 'deploymentgroup', - resourceName: `${this.application.physicalName.value}/${this.physicalName.value}`, + resourceName: `${this.application.physicalName}/${this.physicalName}`, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.ts index 605c3f754c638..72eb4f69d6cff 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.ts @@ -15,7 +15,7 @@ const handler = new lambda.Function(stack, `Handler`, { }); const version = handler.addVersion('1'); const blueGreenAlias = new lambda.Alias(stack, `Alias`, { - aliasName: cdk.PhysicalName.of('alias'), + aliasName: 'alias', version }); diff --git a/packages/@aws-cdk/aws-codedeploy/test/lambda/test.deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/test/lambda/test.deployment-group.ts index 8c70a948fcbe0..c9fe4e5a35eaa 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/lambda/test.deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/test/lambda/test.deployment-group.ts @@ -16,7 +16,7 @@ function mockFunction(stack: cdk.Stack, id: string) { } function mockAlias(stack: cdk.Stack) { return new lambda.Alias(stack, 'Alias', { - aliasName: cdk.PhysicalName.of('my-alias'), + aliasName: 'my-alias', version: new lambda.Version(stack, 'Version', { lambda: mockFunction(stack, 'Function') }) diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts index 376e42bdec238..aa51df74012af 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts @@ -22,7 +22,7 @@ export = { /** Source! */ const repo = new Repository(stack, 'MyVeryImportantRepo', { - repositoryName: cdk.PhysicalName.of('my-very-important-repo'), + repositoryName: 'my-very-important-repo', }); const sourceOutput = new codepipeline.Artifact('SourceArtifact'); @@ -433,7 +433,7 @@ class TestFixture extends cdk.Stack { this.sourceStage = this.pipeline.addStage({ stageName: 'Source' }); this.deployStage = this.pipeline.addStage({ stageName: 'Deploy' }); this.repo = new Repository(this, 'MyVeryImportantRepo', { - repositoryName: cdk.PhysicalName.of('my-very-important-repo'), + repositoryName: 'my-very-important-repo', }); this.sourceOutput = new codepipeline.Artifact('SourceArtifact'); const source = new cpactions.CodeCommitSourceAction({ diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.cfn-template-from-repo.lit.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.cfn-template-from-repo.lit.ts index 38ec644d1d204..0e1d7dec0bc12 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.cfn-template-from-repo.lit.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.cfn-template-from-repo.lit.ts @@ -9,7 +9,7 @@ const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-cloudformation'); /// !show // Source stage: read from repository const repo = new codecommit.Repository(stack, 'TemplateRepo', { - repositoryName: cdk.PhysicalName.of('template-repo'), + repositoryName: 'template-repo', }); const sourceOutput = new codepipeline.Artifact('SourceArtifact'); const source = new cpactions.CodeCommitSourceAction({ diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts index 865965b35f556..901d563dc88fb 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts @@ -26,7 +26,7 @@ const pipeline = new codepipeline.Pipeline(pipelineStack, 'Pipeline'); const cdkSourceOutput = new codepipeline.Artifact(); const cdkSourceAction = new codepipeline_actions.CodeCommitSourceAction({ repository: new codecommit.Repository(pipelineStack, 'CdkCodeRepo', { - repositoryName: cdk.PhysicalName.of('CdkCodeRepo'), + repositoryName: 'CdkCodeRepo', }), actionName: 'CdkCode_Source', output: cdkSourceOutput, @@ -34,7 +34,7 @@ const cdkSourceAction = new codepipeline_actions.CodeCommitSourceAction({ const lambdaSourceOutput = new codepipeline.Artifact(); const lambdaSourceAction = new codepipeline_actions.CodeCommitSourceAction({ repository: new codecommit.Repository(pipelineStack, 'LambdaCodeRepo', { - repositoryName: cdk.PhysicalName.of('LambdaCodeRepo'), + repositoryName: 'LambdaCodeRepo', }), actionName: 'LambdaCode_Source', output: lambdaSourceOutput, diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts index 95abfe3dad53e..c14abced15c11 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts @@ -10,7 +10,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-codebuild-multiple-inputs-outputs'); const repository = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: cdk.PhysicalName.of('MyIntegTestTempRepo'), + repositoryName: 'MyIntegTestTempRepo', }); const bucket = new s3.Bucket(stack, 'MyBucket', { versioned: true, diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts index 08507ddebd8d8..42e64c80c0688 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts @@ -9,7 +9,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-codecommit-codebuild'); const repository = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: cdk.PhysicalName.of('my-repo'), + repositoryName: 'my-repo', }); const sourceOutput = new codepipeline.Artifact('SourceArtifact'); const sourceAction = new cpactions.CodeCommitSourceAction({ diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit.ts index 1a76865f59db5..37caee0fe9f3f 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit.ts @@ -8,7 +8,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-codecommit'); const repo = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: cdk.PhysicalName.of('my-repo'), + repositoryName: 'my-repo', }); new codepipeline.Pipeline(stack, 'Pipeline', { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts index d34b69a6f18f8..47a6d2afc9776 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts @@ -16,7 +16,7 @@ const stack = new cdk.Stack(app, 'aws-cdk-pipeline-event-target'); const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline'); const repository = new codecommit.Repository(stack, 'CodeCommitRepo', { - repositoryName: cdk.PhysicalName.of('foo'), + repositoryName: 'foo', }); const project = new codebuild.PipelineProject(stack, 'BuildProject'); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts index d6b6c662c5de2..f34ef11dc7c58 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts @@ -18,7 +18,7 @@ export = { const stack = new Stack(); const repository = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: PhysicalName.of('my-repo'), + repositoryName: 'my-repo', }); const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); @@ -870,6 +870,6 @@ function stageForTesting(stack: Stack): codepipeline.IStage { function repositoryForTesting(stack: Stack): codecommit.Repository { return new codecommit.Repository(stack, 'Repository', { - repositoryName: PhysicalName.of('Repository'), + repositoryName: 'Repository', }); } diff --git a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts index 1b06b4810e0c7..93d651aa37afd 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts @@ -223,7 +223,7 @@ export class Pipeline extends PipelineBase { physicalName: props.pipelineName, }); - validateName('Pipeline', this.physicalName.value); + validateName('Pipeline', this.physicalName); // If a bucket has been provided, use it - otherwise, create a bucket. let propsBucket = props.artifactBucket; @@ -249,7 +249,7 @@ export class Pipeline extends PipelineBase { stages: Lazy.anyValue({ produce: () => this.renderStages() }), roleArn: this.role.roleArn, restartExecutionOnUpdate: props && props.restartExecutionOnUpdate, - name: this.physicalName.value, + name: this.physicalName, }); // this will produce a DependsOn for both the role and the policy resources. @@ -259,10 +259,10 @@ export class Pipeline extends PipelineBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: '', - name: codePipeline.refAsString, + name: codePipeline.ref, arnComponents: { service: 'codepipeline', - resource: this.physicalName.value || '', + resource: this.physicalName, }, }); this.pipelineName = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts b/packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts index 6e436c122f8e8..7bd88176749c6 100644 --- a/packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts +++ b/packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts @@ -27,7 +27,7 @@ export interface UserPoolClientProps { * Name of the application client * @default cloudformation generated name */ - readonly clientName?: PhysicalName; + readonly userPoolClientName?: PhysicalName; /** * The UserPool resource this client will have access to @@ -68,17 +68,17 @@ export class UserPoolClient extends Resource { constructor(scope: Construct, id: string, props: UserPoolClientProps) { super(scope, id, { - physicalName: props.clientName, + physicalName: props.userPoolClientName, }); const resource = new CfnUserPoolClient(this, 'Resource', { - clientName: this.physicalName.value, + clientName: this.physicalName, generateSecret: props.generateSecret, userPoolId: props.userPool.userPoolId, explicitAuthFlows: props.enabledAuthFlows }); - this.userPoolClientId = resource.refAsString; + this.userPoolClientId = resource.ref; this.userPoolClientClientSecret = resource.attrClientSecret; this.userPoolClientName = resource.attrName; } diff --git a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts index ab2a29c3bc6ce..ea2b452c44837 100644 --- a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts +++ b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts @@ -206,7 +206,7 @@ export interface UserPoolProps { * * @default - automatically generated name by CloudFormation at deploy time */ - readonly poolName?: PhysicalName; + readonly userPoolName?: PhysicalName; /** * Method used for user registration & sign in. @@ -336,7 +336,7 @@ export class UserPool extends Resource implements IUserPool { constructor(scope: Construct, id: string, props: UserPoolProps = {}) { super(scope, id, { - physicalName: props.poolName, + physicalName: props.userPoolName, }); let aliasAttributes: UserPoolAttribute[] | undefined; @@ -391,7 +391,7 @@ export class UserPool extends Resource implements IUserPool { } const userPool = new CfnUserPool(this, 'Resource', { - userPoolName: this.physicalName.value, + userPoolName: this.physicalName, usernameAttributes, aliasAttributes, autoVerifiedAttributes: props.autoVerifiedAttributes, @@ -400,11 +400,11 @@ export class UserPool extends Resource implements IUserPool { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: userPool.attrArn, - name: userPool.refAsString, + name: userPool.ref, arnComponents: { service: 'cognito', resource: 'userpool', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.userPoolId = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-cognito/test/test.user-pool.ts b/packages/@aws-cdk/aws-cognito/test/test.user-pool.ts index 8894bbf1146f8..5971c7900430d 100644 --- a/packages/@aws-cdk/aws-cognito/test/test.user-pool.ts +++ b/packages/@aws-cdk/aws-cognito/test/test.user-pool.ts @@ -11,7 +11,7 @@ export = { // WHEN new cognito.UserPool(stack, 'Pool', { - poolName: cdk.PhysicalName.of('myPool'), + userPoolName: cdk.PhysicalName.of('myPool'), }); // THEN diff --git a/packages/@aws-cdk/aws-config/lib/rule.ts b/packages/@aws-cdk/aws-config/lib/rule.ts index 12271082b4c30..4b82fa7923254 100644 --- a/packages/@aws-cdk/aws-config/lib/rule.ts +++ b/packages/@aws-cdk/aws-config/lib/rule.ts @@ -193,7 +193,7 @@ export interface RuleProps { * * @default a CloudFormation generated name */ - readonly ruleName?: PhysicalName; + readonly configRuleName?: PhysicalName; /** * A description about this AWS Config rule. @@ -249,11 +249,11 @@ export class ManagedRule extends RuleNew { constructor(scope: Construct, id: string, props: ManagedRuleProps) { super(scope, id, { - physicalName: props.ruleName, + physicalName: props.configRuleName, }); const rule = new CfnConfigRule(this, 'Resource', { - configRuleName: this.physicalName.value, + configRuleName: this.physicalName, description: props.description, inputParameters: props.inputParameters, maximumExecutionFrequency: props.maximumExecutionFrequency, @@ -264,7 +264,7 @@ export class ManagedRule extends RuleNew { } }); - this.configRuleName = rule.refAsString; + this.configRuleName = rule.ref; this.configRuleArn = rule.attrArn; this.configRuleId = rule.attrConfigRuleId; this.configRuleComplianceType = rule.attrComplianceType; @@ -316,7 +316,7 @@ export class CustomRule extends RuleNew { constructor(scope: Construct, id: string, props: CustomRuleProps) { super(scope, id, { - physicalName: props.ruleName, + physicalName: props.configRuleName, }); if (!props.configurationChanges && !props.periodic) { @@ -358,7 +358,7 @@ export class CustomRule extends RuleNew { this.node.addDependency(props.lambdaFunction); const rule = new CfnConfigRule(this, 'Resource', { - configRuleName: this.physicalName.value, + configRuleName: this.physicalName, description: props.description, inputParameters: props.inputParameters, maximumExecutionFrequency: props.maximumExecutionFrequency, @@ -370,7 +370,7 @@ export class CustomRule extends RuleNew { } }); - this.configRuleName = rule.refAsString; + this.configRuleName = rule.ref; this.configRuleArn = rule.attrArn; this.configRuleId = rule.attrConfigRuleId; this.configRuleComplianceType = rule.attrComplianceType; diff --git a/packages/@aws-cdk/aws-config/test/test.rule.ts b/packages/@aws-cdk/aws-config/test/test.rule.ts index f311a40d6fcde..e460bfe549f77 100644 --- a/packages/@aws-cdk/aws-config/test/test.rule.ts +++ b/packages/@aws-cdk/aws-config/test/test.rule.ts @@ -18,7 +18,7 @@ export = { key: 'value' }, maximumExecutionFrequency: config.MaximumExecutionFrequency.THREE_HOURS, - ruleName: cdk.PhysicalName.of('cool rule'), + configRuleName: cdk.PhysicalName.of('cool rule'), }); // THEN @@ -56,7 +56,7 @@ export = { }, lambdaFunction: fn, maximumExecutionFrequency: config.MaximumExecutionFrequency.SIX_HOURS, - ruleName: cdk.PhysicalName.of('cool rule'), + configRuleName: cdk.PhysicalName.of('cool rule'), periodic: true }); diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index 2adc3c5c996c9..b410994c94396 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -232,7 +232,7 @@ export class Table extends Resource { this.validateProvisioning(props); this.table = new CfnTable(this, 'Resource', { - tableName: this.physicalName.value, + tableName: this.physicalName, keySchema: this.keySchema, attributeDefinitions: this.attributeDefinitions, globalSecondaryIndexes: Lazy.anyValue({ produce: () => this.globalSecondaryIndexes }, { omitEmptyArray: true }), @@ -252,11 +252,11 @@ export class Table extends Resource { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: this.table.attrArn, - name: this.table.refAsString, + name: this.table.ref, arnComponents: { service: 'dynamodb', resource: 'table', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.tableArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-ec2/lib/security-group.ts b/packages/@aws-cdk/aws-ec2/lib/security-group.ts index 6ea32fdbc5a42..d63d2b8f187e4 100644 --- a/packages/@aws-cdk/aws-ec2/lib/security-group.ts +++ b/packages/@aws-cdk/aws-ec2/lib/security-group.ts @@ -192,7 +192,7 @@ export interface SecurityGroupProps { * @default If you don't specify a GroupName, AWS CloudFormation generates a * unique physical ID and uses that ID for the group name. */ - readonly groupName?: PhysicalName; + readonly securityGroupName?: PhysicalName; /** * A description of the security group. @@ -267,7 +267,7 @@ export class SecurityGroup extends SecurityGroupBase { constructor(scope: Construct, id: string, props: SecurityGroupProps) { super(scope, id, { - physicalName: props.groupName + physicalName: props.securityGroupName }); const groupDescription = props.description || this.node.path; @@ -275,7 +275,7 @@ export class SecurityGroup extends SecurityGroupBase { this.allowAllOutbound = props.allowAllOutbound !== false; this.securityGroup = new CfnSecurityGroup(this, 'Resource', { - groupName: this.physicalName.value, + groupName: this.physicalName, groupDescription, securityGroupIngress: Lazy.anyValue({ produce: () => this.directIngressRules }), securityGroupEgress: Lazy.anyValue({ produce: () => this.directEgressRules }), @@ -284,7 +284,7 @@ export class SecurityGroup extends SecurityGroupBase { this.securityGroupId = this.securityGroup.attrGroupId; this.securityGroupVpcId = this.securityGroup.attrVpcId; - this.securityGroupName = this.securityGroup.refAsString; + this.securityGroupName = this.securityGroup.ref; this.addDefaultEgressRule(); } diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts b/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts index 4ab5b930280db..42de37c85c24b 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts @@ -179,7 +179,7 @@ export class GatewayVpcEndpoint extends VpcEndpoint implements IGatewayVpcEndpoi vpcId: props.vpc.vpcId }); - this.vpcEndpointId = endpoint.refAsString; + this.vpcEndpointId = endpoint.ref; this.vpcEndpointCreationTimestamp = endpoint.attrCreationTimestamp; this.vpcEndpointDnsEntries = endpoint.attrDnsEntries; this.vpcEndpointNetworkInterfaceIds = endpoint.attrNetworkInterfaceIds; @@ -381,7 +381,7 @@ export class InterfaceVpcEndpoint extends VpcEndpoint implements IInterfaceVpcEn vpcId: props.vpc.vpcId }); - this.vpcEndpointId = endpoint.refAsString; + this.vpcEndpointId = endpoint.ref; this.vpcEndpointCreationTimestamp = endpoint.attrCreationTimestamp; this.vpcEndpointDnsEntries = endpoint.attrDnsEntries; this.vpcEndpointNetworkInterfaceIds = endpoint.attrNetworkInterfaceIds; diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index ba1b898be5562..b7c65cde4a86e 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -821,7 +821,7 @@ export class Vpc extends VpcBase { const maxAZs = props.maxAZs !== undefined ? props.maxAZs : 3; this.availabilityZones = this.availabilityZones.slice(0, maxAZs); - this.vpcId = this.resource.refAsString; + this.vpcId = this.resource.ref; this.subnetConfiguration = ifUndefined(props.subnetConfiguration, Vpc.DEFAULT_SUBNETS); // subnetConfiguration and natGateways must be set before calling createSubnets @@ -836,12 +836,12 @@ export class Vpc extends VpcBase { }); this.internetDependencies.push(igw); const att = new CfnVPCGatewayAttachment(this, 'VPCGW', { - internetGatewayId: igw.refAsString, - vpcId: this.resource.refAsString + internetGatewayId: igw.ref, + vpcId: this.resource.ref }); (this.publicSubnets as PublicSubnet[]).forEach(publicSubnet => { - publicSubnet.addDefaultInternetRoute(igw.refAsString, att); + publicSubnet.addDefaultInternetRoute(igw.ref, att); }); // if gateways are needed create them @@ -870,10 +870,10 @@ export class Vpc extends VpcBase { const attachment = new CfnVPCGatewayAttachment(this, 'VPCVPNGW', { vpcId: this.vpcId, - vpnGatewayId: vpnGateway.refAsString, + vpnGatewayId: vpnGateway.ref, }); - this.vpnGatewayId = vpnGateway.refAsString; + this.vpnGatewayId = vpnGateway.ref; // Propagate routes on route tables associated with the right subnets const vpnRoutePropagation = props.vpnRoutePropagation || [{ subnetType: SubnetType.PRIVATE }]; @@ -959,7 +959,7 @@ export class Vpc extends VpcBase { natSubnets = natSubnets.slice(0, natCount); for (const sub of natSubnets) { const gateway = sub.addNatGateway(); - this.natGatewayByAZ[sub.availabilityZone] = gateway.refAsString; + this.natGatewayByAZ[sub.availabilityZone] = gateway.ref; this.natDependencies.push(gateway); } } @@ -1141,7 +1141,7 @@ export class Subnet extends Resource implements ISubnet { availabilityZone: props.availabilityZone, mapPublicIpOnLaunch: props.mapPublicIpOnLaunch, }); - this.subnetId = subnet.refAsString; + this.subnetId = subnet.ref; this.subnetVpcId = subnet.attrVpcId; this.subnetAvailabilityZone = subnet.attrAvailabilityZone; this.subnetIpv6CidrBlocks = subnet.attrIpv6CidrBlocks; @@ -1150,12 +1150,12 @@ export class Subnet extends Resource implements ISubnet { const table = new CfnRouteTable(this, 'RouteTable', { vpcId: props.vpcId, }); - this.routeTableId = table.refAsString; + this.routeTableId = table.ref; // Associate the public route table for this subnet, to this subnet new CfnSubnetRouteTableAssociation(this, 'RouteTableAssociation', { subnetId: this.subnetId, - routeTableId: table.refAsString + routeTableId: table.ref }); } diff --git a/packages/@aws-cdk/aws-ec2/lib/vpn.ts b/packages/@aws-cdk/aws-ec2/lib/vpn.ts index 9a5cde4633eb7..45eb809aed8da 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpn.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpn.ts @@ -162,7 +162,7 @@ export class VpnConnection extends cdk.Construct implements IVpnConnection { type }); - this.customerGatewayId = customerGateway.refAsString; + this.customerGatewayId = customerGateway.ref; this.customerGatewayAsn = bgpAsn; this.customerGatewayIp = props.ip; @@ -199,13 +199,13 @@ export class VpnConnection extends cdk.Construct implements IVpnConnection { const vpnConnection = new CfnVPNConnection(this, 'Resource', { type, - customerGatewayId: customerGateway.refAsString, + customerGatewayId: customerGateway.ref, staticRoutesOnly: props.staticRoutes ? true : false, vpnGatewayId: props.vpc.vpnGatewayId, vpnTunnelOptionsSpecifications: props.tunnelOptions }); - this.vpnId = vpnConnection.refAsString; + this.vpnId = vpnConnection.ref; if (props.staticRoutes) { props.staticRoutes.forEach(route => { diff --git a/packages/@aws-cdk/aws-ec2/package.json b/packages/@aws-cdk/aws-ec2/package.json index cb662e1da44ac..5674617487f66 100644 --- a/packages/@aws-cdk/aws-ec2/package.json +++ b/packages/@aws-cdk/aws-ec2/package.json @@ -89,7 +89,6 @@ }, "awslint": { "exclude": [ - "resource-attribute:@aws-cdk/aws-ec2.ISecurityGroup.securityGroupVpcId", "props-physical-name:@aws-cdk/aws-ec2.GatewayVpcEndpointProps", "props-physical-name:@aws-cdk/aws-ec2.PrivateSubnetProps", "props-physical-name:@aws-cdk/aws-ec2.PublicSubnetProps", diff --git a/packages/@aws-cdk/aws-ec2/test/export-helper.ts b/packages/@aws-cdk/aws-ec2/test/export-helper.ts deleted file mode 100644 index bfc3443a4402f..0000000000000 --- a/packages/@aws-cdk/aws-ec2/test/export-helper.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { CfnOutput, Construct, StringListCfnOutput } from '@aws-cdk/cdk'; -import { ISubnet, SubnetType, Vpc } from '../lib'; -import { defaultSubnetName, range, subnetName } from '../lib/util'; - -export function exportVpc(vpc: Vpc) { - const pub = new ExportSubnetGroup(vpc, 'PublicSubnetIDs', vpc.publicSubnets, SubnetType.PUBLIC, vpc.availabilityZones.length); - const priv = new ExportSubnetGroup(vpc, 'PrivateSubnetIDs', vpc.privateSubnets, SubnetType.PRIVATE, vpc.availabilityZones.length); - const iso = new ExportSubnetGroup(vpc, 'IsolatedSubnetIDs', vpc.isolatedSubnets, SubnetType.ISOLATED, vpc.availabilityZones.length); - - const vpnGatewayId = vpc.vpnGatewayId - ? new CfnOutput(vpc, 'VpnGatewayId', { value: vpc.vpnGatewayId }).makeImportValue().toString() - : undefined; - - return { - vpcId: new CfnOutput(vpc, 'VpcId', { value: vpc.vpcId }).makeImportValue().toString(), - vpnGatewayId, - availabilityZones: vpc.availabilityZones, - publicSubnetIds: pub.ids, - publicSubnetNames: pub.names, - privateSubnetIds: priv.ids, - privateSubnetNames: priv.names, - isolatedSubnetIds: iso.ids, - isolatedSubnetNames: iso.names, - }; -} - -/** - * Helper class to export/import groups of subnets - */ -export class ExportSubnetGroup { - public readonly ids?: string[]; - public readonly names?: string[]; - - private readonly groups: number; - - constructor( - scope: Construct, - exportName: string, - private readonly subnets: ISubnet[], - private readonly type: SubnetType, - private readonly azs: number) { - - this.groups = subnets.length / azs; - - // ASSERTION - if (Math.floor(this.groups) !== this.groups) { - throw new Error(`Number of subnets (${subnets.length}) must be a multiple of number of availability zones (${azs})`); - } - - this.ids = this.exportIds(scope, exportName); - this.names = this.exportNames(); - } - - private exportIds(scope: Construct, name: string): string[] | undefined { - if (this.subnets.length === 0) { return undefined; } - return new StringListCfnOutput(scope, name, { values: this.subnets.map(s => s.subnetId) }).makeImportValues().map(x => x.toString()); - } - - /** - * Return the list of subnet names if they're not equal to the default - */ - private exportNames(): string[] | undefined { - if (this.subnets.length === 0) { return undefined; } - const netNames = this.subnets.map(subnetName); - - // Do some assertion that the 'netNames' array is laid out like this: - // - // [ INGRESS, INGRESS, INGRESS, EGRESS, EGRESS, EGRESS, ... ] - for (let i = 0; i < netNames.length; i++) { - const k = Math.floor(i / this.azs); - if (netNames[i] !== netNames[k * this.azs]) { - throw new Error(`Subnets must be grouped by name, got: ${JSON.stringify(netNames)}`); - } - } - - // Splat down to [ INGRESS, EGRESS, ... ] - const groupNames = range(this.groups).map(i => netNames[i * this.azs]); - if (groupNames.length === 1 && groupNames[0] === defaultSubnetName(this.type)) { return undefined; } - - return groupNames; - } -} diff --git a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts index c4a39456abcfa..dcc26d107a3e5 100644 --- a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts +++ b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts @@ -1,8 +1,7 @@ import { countResources, expect, haveResource, haveResourceLike, isSuperObject } from '@aws-cdk/assert'; -import { Construct, Stack, Tag } from '@aws-cdk/cdk'; +import { Stack, Tag } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; -import { CfnVPC, DefaultInstanceTenancy, IVpc, SubnetType, Vpc } from '../lib'; -import { exportVpc } from './export-helper'; +import { CfnVPC, DefaultInstanceTenancy, SubnetType, Vpc } from '../lib'; export = { "When creating a VPC": { @@ -704,118 +703,12 @@ export = { test.done(); } }, - - 'export/import': { - 'simple VPC'(test: Test) { - // WHEN - const vpc2 = doImportExportTest(stack => { - return new Vpc(stack, 'TheVPC'); - }); - - // THEN - test.deepEqual(Stack.of(vpc2).resolve(vpc2.vpcId), { - 'Fn::ImportValue': 'TestStack:TheVPCVpcIdD346CDBA' - }); - - test.done(); - }, - - 'multiple subnets of the same type'(test: Test) { - // WHEN - const imported = doImportExportTest(stack => { - return new Vpc(stack, 'TheVPC', { - subnetConfiguration: [ - { name: 'Ingress', subnetType: SubnetType.PUBLIC }, - { name: 'Egress', subnetType: SubnetType.PUBLIC }, - ] - }); - }); - - // THEN - test.deepEqual(Stack.of(imported).resolve(imported.vpcId), { - 'Fn::ImportValue': 'TestStack:TheVPCVpcIdD346CDBA' - }); - - test.equal(6, imported.publicSubnets.length); - - for (let i = 0; i < 3; i++) { - // tslint:disable-next-line:max-line-length - test.equal(true, imported.publicSubnets[i].node.id.startsWith('Ingress'), `${imported.publicSubnets[i].node.id} does not start with "Ingress"`); - } - for (let i = 3; i < 6; i++) { - // tslint:disable-next-line:max-line-length - test.equal(true, imported.publicSubnets[i].node.id.startsWith('Egress'), `${imported.publicSubnets[i].node.id} does not start with "Egress"`); - } - - test.done(); - }, - - 'can select isolated subnets by type'(test: Test) { - // GIVEN - const importedVpc = doImportExportTest(stack => { - return new Vpc(stack, 'TheVPC', { - subnetConfiguration: [ - { subnetType: SubnetType.PRIVATE, name: 'Private' }, - { subnetType: SubnetType.ISOLATED, name: 'Isolated' }, - ] - }); - }); - - // WHEN - const { subnetIds } = importedVpc.selectSubnets({ subnetType: SubnetType.ISOLATED }); - - // THEN - test.equal(3, importedVpc.isolatedSubnets.length); - test.deepEqual(subnetIds, importedVpc.isolatedSubnets.map(s => s.subnetId)); - - test.done(); - }, - - 'can select isolated subnets by name'(test: Test) { - // Do the test with both default name and custom name - for (const isolatedName of ['Isolated', 'LeaveMeAlone']) { - // GIVEN - const importedVpc = doImportExportTest(stack => { - return new Vpc(stack, 'TheVPC', { - subnetConfiguration: [ - { subnetType: SubnetType.PRIVATE, name: 'Private' }, - { subnetType: SubnetType.ISOLATED, name: isolatedName }, - ] - }); - }); - - // WHEN - const { subnetIds } = importedVpc.selectSubnets({ subnetName: isolatedName }); - - // THEN - test.equal(3, importedVpc.isolatedSubnets.length); - test.deepEqual(subnetIds, importedVpc.isolatedSubnets.map(s => s.subnetId)); - } - - test.done(); - }, - }, - }; function getTestStack(): Stack { return new Stack(undefined, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' } }); } -/** - * Do a complete import/export test, return the imported VPC - */ -function doImportExportTest(constructFn: (scope: Construct) => Vpc): IVpc { - // GIVEN - const stack1 = getTestStack(); - const stack2 = getTestStack(); - - const vpc1 = constructFn(stack1); - - // WHEN - return Vpc.fromVpcAttributes(stack2, 'VPC2', exportVpc(vpc1)); -} - function toCfnTags(tags: any): Array<{Key: string, Value: string}> { return Object.keys(tags).map( key => { return {Key: key, Value: tags[key]}; diff --git a/packages/@aws-cdk/aws-ecr/lib/repository.ts b/packages/@aws-cdk/aws-ecr/lib/repository.ts index 7da17a6686a9d..3de357cc1a35d 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository.ts @@ -340,7 +340,7 @@ export class Repository extends RepositoryBase { }); const resource = new CfnRepository(this, 'Resource', { - repositoryName: this.physicalName.value, + repositoryName: this.physicalName, // It says "Text", but they actually mean "Object". repositoryPolicyText: Lazy.anyValue({ produce: () => this.policyDocument }), lifecyclePolicy: Lazy.anyValue({ produce: () => this.renderLifecyclePolicy() }), @@ -355,11 +355,11 @@ export class Repository extends RepositoryBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: resource.attrArn, - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'ecr', resource: 'repository', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.repositoryName = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.ts b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.ts index 89627269e9576..3043cfb86d900 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.ts @@ -24,4 +24,4 @@ new ecsPatterns.LoadBalancedFargateService(stack, 'L3', { }) }); -app.run(); +app.synth(); diff --git a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts index 969adcce23f0f..55e1e773e3631 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts @@ -147,7 +147,7 @@ export abstract class BaseService extends Resource this.resource = new CfnService(this, "Service", { desiredCount: props.desiredCount, - serviceName: this.physicalName.value, + serviceName: this.physicalName, loadBalancers: Lazy.anyValue({ produce: () => this.loadBalancers }), deploymentConfiguration: { maximumPercent: props.maximumPercent || 200, @@ -164,16 +164,16 @@ export abstract class BaseService extends Resource // are enabled for the principal in a given region. const longArnEnabled = props.longArnEnabled !== undefined ? props.longArnEnabled : false; const serviceName = longArnEnabled - ? cdk.Fn.select(2, cdk.Fn.split('/', this.resource.refAsString)) + ? cdk.Fn.select(2, cdk.Fn.split('/', this.resource.ref)) : this.resource.attrName; const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: this.resource.refAsString, + arn: this.resource.ref, name: serviceName, arnComponents: { service: 'ecs', resource: 'service', - resourceName: `${props.cluster.physicalName.value}/${this.physicalName.value}`, + resourceName: `${props.cluster.physicalName}/${this.physicalName}`, }, }); this.serviceArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts index 0b99b08e229de..d04b25c72fb3f 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts @@ -283,7 +283,7 @@ export class TaskDefinition extends TaskDefinitionBase { props.placementConstraints.forEach(pc => this.addPlacementConstraint(pc)); } - this.taskDefinitionArn = taskDef.refAsString; + this.taskDefinitionArn = taskDef.ref; } public get executionRole(): iam.IRole | undefined { diff --git a/packages/@aws-cdk/aws-ecs/lib/cluster.ts b/packages/@aws-cdk/aws-ecs/lib/cluster.ts index 7bc08dfd44f95..5b1cbe3d15f79 100644 --- a/packages/@aws-cdk/aws-ecs/lib/cluster.ts +++ b/packages/@aws-cdk/aws-ecs/lib/cluster.ts @@ -72,16 +72,16 @@ export class Cluster extends Resource implements ICluster { }); const cluster = new CfnCluster(this, 'Resource', { - clusterName: this.physicalName.value, + clusterName: this.physicalName, }); const resourceIdentifiers = new ResourceIdentifiers(this, { arn: cluster.attrArn, - name: cluster.refAsString, + name: cluster.ref, arnComponents: { service: 'ecs', resource: 'cluster', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.clusterArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-eks/lib/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster.ts index edd6a267d9785..bf024edbff3f3 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster.ts @@ -231,7 +231,7 @@ export class Cluster extends Resource implements ICluster { const subnetIds = [...new Set(Array().concat(...placements.map(s => props.vpc.selectSubnets(s).subnetIds)))]; const resource = new CfnCluster(this, 'Resource', { - name: this.physicalName.value, + name: this.physicalName, roleArn: this.role.roleArn, version: props.version, resourcesVpcConfig: { @@ -242,11 +242,11 @@ export class Cluster extends Resource implements ICluster { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: resource.attrArn, - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'eks', resource: 'cluster', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.clusterName = resourceIdentifiers.name; @@ -255,7 +255,7 @@ export class Cluster extends Resource implements ICluster { this.clusterEndpoint = resource.attrEndpoint; this.clusterCertificateAuthorityData = resource.attrCertificateAuthorityData; - new CfnOutput(this, 'ClusterName', { value: this.clusterName, disableExport: true }); + new CfnOutput(this, 'ClusterName', { value: this.clusterName }); } /** @@ -329,7 +329,6 @@ export class Cluster extends Resource implements ICluster { // Create an CfnOutput for the Instance Role ARN (need to paste it into aws-auth-cm.yaml) new CfnOutput(autoScalingGroup, 'InstanceRoleARN', { - disableExport: true, value: autoScalingGroup.role.roleArn }); } diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index fd33454bab454..94d7b30eb507f 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -292,7 +292,7 @@ export class LoadBalancer extends Resource implements IConnectable { * @attribute */ public get loadBalancerName() { - return this.elb.refAsString; + return this.elb.ref; } /** diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts index 200f0e9852aef..a52d4351cc35b 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts @@ -147,7 +147,7 @@ export class ApplicationListenerRule extends cdk.Construct { this.addFixedResponse(props.fixedResponse); } - this.listenerRuleArn = resource.refAsString; + this.listenerRuleArn = resource.ref; } /** diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index 406db3cd7ea33..298ea0739bbd9 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -21,7 +21,7 @@ export abstract class BaseListener extends Resource { defaultActions: Lazy.anyValue({ produce: () => this.defaultActions }), }); - this.listenerArn = resource.refAsString; + this.listenerArn = resource.ref; } /** diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index 0f986b2cb502f..8a04ebacae7a8 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -135,7 +135,7 @@ export abstract class BaseLoadBalancer extends Resource { this.vpc = baseProps.vpc; const resource = new CfnLoadBalancer(this, 'Resource', { - name: this.physicalName.value, + name: this.physicalName, subnets: subnetIds, scheme: internetFacing ? 'internet-facing' : 'internal', loadBalancerAttributes: Lazy.anyValue({ produce: () => renderAttributes(this.attributes) }), @@ -151,7 +151,7 @@ export abstract class BaseLoadBalancer extends Resource { this.loadBalancerDnsName = resource.attrDnsName; this.loadBalancerFullName = resource.attrLoadBalancerFullName; this.loadBalancerName = resource.attrLoadBalancerName; - this.loadBalancerArn = resource.refAsString; + this.loadBalancerArn = resource.ref; this.loadBalancerSecurityGroups = resource.attrSecurityGroups; } diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index af25fbd28c211..3cb221280f172 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -234,7 +234,7 @@ export abstract class TargetGroupBase extends cdk.Construct implements ITargetGr }); this.targetGroupLoadBalancerArns = this.resource.attrLoadBalancerArns; - this.targetGroupArn = this.resource.refAsString; + this.targetGroupArn = this.resource.ref; this.targetGroupFullName = this.resource.attrTargetGroupFullName; this.loadBalancerArns = this.resource.attrLoadBalancerArns.toString(); this.targetGroupName = this.resource.attrTargetGroupName; diff --git a/packages/@aws-cdk/aws-events-targets/test/codebuild/integ.project-events.ts b/packages/@aws-cdk/aws-events-targets/test/codebuild/integ.project-events.ts index 54aadb36d71ba..62d67211aada2 100644 --- a/packages/@aws-cdk/aws-events-targets/test/codebuild/integ.project-events.ts +++ b/packages/@aws-cdk/aws-events-targets/test/codebuild/integ.project-events.ts @@ -13,7 +13,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codebuild-events'); const repo = new codecommit.Repository(stack, 'MyRepo', { - repositoryName: cdk.PhysicalName.of('aws-cdk-codebuild-events'), + repositoryName: 'aws-cdk-codebuild-events', }); const project = new codebuild.Project(stack, 'MyProject', { source: codebuild.Source.codeCommit({ repository: repo }), diff --git a/packages/@aws-cdk/aws-events-targets/test/codepipeline/integ.pipeline-event-target.ts b/packages/@aws-cdk/aws-events-targets/test/codepipeline/integ.pipeline-event-target.ts index c9944cbe8d5b1..24d9059395147 100644 --- a/packages/@aws-cdk/aws-events-targets/test/codepipeline/integ.pipeline-event-target.ts +++ b/packages/@aws-cdk/aws-events-targets/test/codepipeline/integ.pipeline-event-target.ts @@ -14,7 +14,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'pipeline-events'); const repo = new codecommit.Repository(stack, 'Repo', { - repositoryName: cdk.PhysicalName.of('TestRepository'), + repositoryName: 'TestRepository', }); const pipeline = new codepipeline.Pipeline(stack, 'pipelinePipeline22F2A91D'); diff --git a/packages/@aws-cdk/aws-events/lib/rule.ts b/packages/@aws-cdk/aws-events/lib/rule.ts index 2104ef73d2c95..16717025bb0be 100644 --- a/packages/@aws-cdk/aws-events/lib/rule.ts +++ b/packages/@aws-cdk/aws-events/lib/rule.ts @@ -96,7 +96,7 @@ export class Rule extends Resource implements IRule { }); const resource = new CfnRule(this, 'Resource', { - name: this.physicalName.value, + name: this.physicalName, description: props.description, state: props.enabled == null ? 'ENABLED' : (props.enabled ? 'ENABLED' : 'DISABLED'), scheduleExpression: Lazy.stringValue({ produce: () => this.scheduleExpression }), @@ -110,7 +110,7 @@ export class Rule extends Resource implements IRule { arnComponents: { service: 'events', resource: 'rule', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.ruleArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-glue/lib/database.ts b/packages/@aws-cdk/aws-glue/lib/database.ts index f5a6dca67087a..5904308995e68 100644 --- a/packages/@aws-cdk/aws-glue/lib/database.ts +++ b/packages/@aws-cdk/aws-glue/lib/database.ts @@ -32,7 +32,7 @@ export interface DatabaseProps { /** * The name of the database. */ - readonly databaseName: PhysicalName; + readonly databaseName: string; /** * The location of the database (for example, an HDFS path). @@ -87,21 +87,21 @@ export class Database extends Resource implements IDatabase { constructor(scope: Construct, id: string, props: DatabaseProps) { super(scope, id, { - physicalName: props.databaseName, + physicalName: PhysicalName.of(props.databaseName), }); if (props.locationUri) { this.locationUri = props.locationUri; } else { const bucket = new s3.Bucket(this, 'Bucket'); - this.locationUri = `s3://${bucket.bucketName}/${props.databaseName.value}`; + this.locationUri = `s3://${bucket.bucketName}/${props.databaseName}`; } this.catalogId = Stack.of(this).account; const resource = new CfnDatabase(this, 'Resource', { catalogId: this.catalogId, databaseInput: { - name: this.physicalName.value, + name: this.physicalName, locationUri: this.locationUri } }); @@ -111,13 +111,13 @@ export class Database extends Resource implements IDatabase { arn: Stack.of(this).formatArn({ service: 'glue', resource: 'database', - resourceName: resource.refAsString, + resourceName: resource.ref, }), - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'glue', resource: 'database', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.databaseName = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-glue/lib/table.ts b/packages/@aws-cdk/aws-glue/lib/table.ts index 9135f89e91ca1..f8748fc87ae98 100644 --- a/packages/@aws-cdk/aws-glue/lib/table.ts +++ b/packages/@aws-cdk/aws-glue/lib/table.ts @@ -63,7 +63,7 @@ export interface TableProps { /** * Name of the table. */ - readonly tableName: PhysicalName; + readonly tableName: string; /** * Description of the table. @@ -231,7 +231,7 @@ export class Table extends Resource implements ITable { constructor(scope: Construct, id: string, props: TableProps) { super(scope, id, { - physicalName: props.tableName, + physicalName: PhysicalName.of(props.tableName), }); this.database = props.database; @@ -254,8 +254,8 @@ export class Table extends Resource implements ITable { databaseName: props.database.databaseName, tableInput: { - name: this.physicalName.value, - description: props.description || `${props.tableName.value} generated by CDK`, + name: this.physicalName, + description: props.description || `${props.tableName} generated by CDK`, partitionKeys: renderColumns(props.partitionKeys), @@ -282,13 +282,13 @@ export class Table extends Resource implements ITable { arn: Stack.of(this).formatArn({ service: 'glue', resource: 'table', - resourceName: `${this.database.databaseName}/${tableResource.refAsString}` + resourceName: `${this.database.databaseName}/${tableResource.ref}` }), - name: tableResource.refAsString, + name: tableResource.ref, arnComponents: { service: 'glue', resource: 'table', - resourceName: `${this.database.physicalName.value}/${this.physicalName.value}` + resourceName: `${this.database.physicalName}/${this.physicalName}` }, }); this.tableName = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-glue/test/integ.table.ts b/packages/@aws-cdk/aws-glue/test/integ.table.ts index da6267689291c..4dd92193d01fa 100644 --- a/packages/@aws-cdk/aws-glue/test/integ.table.ts +++ b/packages/@aws-cdk/aws-glue/test/integ.table.ts @@ -9,12 +9,12 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-glue'); const database = new glue.Database(stack, 'MyDatabase', { - databaseName: cdk.PhysicalName.of('my_database'), + databaseName: 'my_database', }); const ordinaryTable = new glue.Table(stack, 'MyTable', { database, - tableName: cdk.PhysicalName.of('my_table'), + tableName: 'my_table', columns: [{ name: 'col1', type: glue.Schema.string @@ -44,7 +44,7 @@ const ordinaryTable = new glue.Table(stack, 'MyTable', { const encryptedTable = new glue.Table(stack, 'MyEncryptedTable', { database, - tableName: cdk.PhysicalName.of('my_encrypted_table'), + tableName: 'my_encrypted_table', columns: [{ name: 'col1', type: glue.Schema.string diff --git a/packages/@aws-cdk/aws-glue/test/test.database.ts b/packages/@aws-cdk/aws-glue/test/test.database.ts index 7fa03609c4056..58fbc58869652 100644 --- a/packages/@aws-cdk/aws-glue/test/test.database.ts +++ b/packages/@aws-cdk/aws-glue/test/test.database.ts @@ -1,5 +1,5 @@ import { expect } from '@aws-cdk/assert'; -import { PhysicalName, Stack } from '@aws-cdk/cdk'; +import { Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import glue = require('../lib'); @@ -8,7 +8,7 @@ export = { const stack = new Stack(); new glue.Database(stack, 'Database', { - databaseName: PhysicalName.of('test_database'), + databaseName: 'test_database', }); expect(stack).toMatch({ @@ -50,7 +50,7 @@ export = { const stack = new Stack(); new glue.Database(stack, 'Database', { - databaseName: PhysicalName.of('test_database'), + databaseName: 'test_database', locationUri: 's3://my-uri/' }); diff --git a/packages/@aws-cdk/aws-glue/test/test.table.ts b/packages/@aws-cdk/aws-glue/test/test.table.ts index f01be63f5d4de..0e2447fd5a2e7 100644 --- a/packages/@aws-cdk/aws-glue/test/test.table.ts +++ b/packages/@aws-cdk/aws-glue/test/test.table.ts @@ -11,13 +11,13 @@ export = { const app = new cdk.App(); const dbStack = new cdk.Stack(app, 'db'); const database = new glue.Database(dbStack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const tableStack = new cdk.Stack(app, 'table'); const table = new glue.Table(tableStack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -82,13 +82,13 @@ export = { const app = new cdk.App(); const dbStack = new cdk.Stack(app, 'db'); const database = new glue.Database(dbStack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const tableStack = new cdk.Stack(app, 'table'); const table = new glue.Table(tableStack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -159,12 +159,12 @@ export = { 'compressed table'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -226,12 +226,12 @@ export = { 'SSE-S3'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -305,12 +305,12 @@ export = { 'SSE-KMS (implicitly created key)'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -434,13 +434,13 @@ export = { 'SSE-KMS (explicitly created key)'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const encryptionKey = new kms.Key(stack, 'MyKey'); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -565,12 +565,12 @@ export = { 'SSE-KMS_MANAGED'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -644,12 +644,12 @@ export = { 'CSE-KMS (implicitly created key)'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -755,13 +755,13 @@ export = { 'CSE-KMS (explicitly created key)'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const encryptionKey = new kms.Key(stack, 'MyKey'); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -868,14 +868,14 @@ export = { 'CSE-KMS (explicitly passed bucket and key)'(test: Test) { const stack = new cdk.Stack(); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const bucket = new s3.Bucket(stack, 'Bucket'); const encryptionKey = new kms.Key(stack, 'MyKey'); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -987,14 +987,14 @@ export = { const stack = new cdk.Stack(app, 'app'); const bucket = new s3.Bucket(stack, 'ExplicitBucket'); const database = new glue.Database(dbStack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); new glue.Table(stack, 'Table', { database, bucket, s3Prefix: 'prefix/', - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -1054,12 +1054,12 @@ export = { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -1160,12 +1160,12 @@ export = { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -1264,12 +1264,12 @@ export = { const stack = new cdk.Stack(); const user = new iam.User(stack, 'User'); const database = new glue.Database(stack, 'Database', { - databaseName: cdk.PhysicalName.of('database'), + databaseName: 'database', }); const table = new glue.Table(stack, 'Table', { database, - tableName: cdk.PhysicalName.of('table'), + tableName: 'table', columns: [{ name: 'col', type: glue.Schema.string @@ -1380,7 +1380,7 @@ export = { test.throws(() => { createTable({ columns: [], - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', }); }, undefined, 'you must specify at least one column for the table'); @@ -1390,7 +1390,7 @@ export = { 'unique column names'(test: Test) { test.throws(() => { createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1406,7 +1406,7 @@ export = { 'unique partition keys'(test: Test) { test.throws(() => createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1425,7 +1425,7 @@ export = { 'column names and partition keys are all unique'(test: Test) { test.throws(() => createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1441,7 +1441,7 @@ export = { 'can not specify an explicit bucket and encryption'(test: Test) { test.throws(() => createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1454,7 +1454,7 @@ export = { 'can explicitly pass bucket if Encryption undefined'(test: Test) { test.doesNotThrow(() => createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1467,7 +1467,7 @@ export = { 'can explicitly pass bucket if Unencrypted'(test: Test) { test.doesNotThrow(() => createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1480,7 +1480,7 @@ export = { 'can explicitly pass bucket if ClientSideKms'(test: Test) { test.doesNotThrow(() => createTable({ - tableName: cdk.PhysicalName.of('name'), + tableName: 'name', columns: [{ name: 'col1', type: glue.Schema.string @@ -1511,7 +1511,7 @@ function createTable(props: Pick this.managedPolicies.map(p => p.managedPolicyArn) }, { omitEmpty: true }), path: props.path, }); const resourceIdentifiers = new ResourceIdentifiers(this, { arn: group.attrArn, - name: group.refAsString, + name: group.ref, arnComponents: { region: '', // IAM is global in each partition service: 'iam', resource: 'group', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.groupName = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-iam/lib/policy.ts b/packages/@aws-cdk/aws-iam/lib/policy.ts index c38ef82ab6417..73a5b39dcf671 100644 --- a/packages/@aws-cdk/aws-iam/lib/policy.ts +++ b/packages/@aws-cdk/aws-iam/lib/policy.ts @@ -101,13 +101,13 @@ export class Policy extends Resource implements IPolicy { const resource = new CfnPolicy(this, 'Resource', { policyDocument: this.document, - policyName: this.physicalName.value!, // guaranteed to be not null because of above `super` call + policyName: this.physicalName, // guaranteed to be not null because of above `super` call roles: undefinedIfEmpty(() => this.roles.map(r => r.roleName)), users: undefinedIfEmpty(() => this.users.map(u => u.userName)), groups: undefinedIfEmpty(() => this.groups.map(g => g.groupName)), }); - this.policyName = this.physicalName.value!; + this.policyName = this.physicalName!; if (props.users) { props.users.forEach(u => this.attachToUser(u)); diff --git a/packages/@aws-cdk/aws-iam/lib/role.ts b/packages/@aws-cdk/aws-iam/lib/role.ts index 0a51516ee4252..8f4a33be606d0 100644 --- a/packages/@aws-cdk/aws-iam/lib/role.ts +++ b/packages/@aws-cdk/aws-iam/lib/role.ts @@ -214,19 +214,19 @@ export class Role extends Resource implements IRole { managedPolicyArns: Lazy.listValue({ produce: () => this.managedPolicies.map(p => p.managedPolicyArn) }, { omitEmpty: true }), policies: _flatten(props.inlinePolicies), path: props.path, - roleName: this.physicalName.value, + roleName: this.physicalName, maxSessionDuration: props.maxSessionDurationSec, }); this.roleId = role.attrRoleId; const resourceIdentifiers = new ResourceIdentifiers(this, { arn: role.attrArn, - name: role.refAsString, + name: role.ref, arnComponents: { region: '', // IAM is global in each partition service: 'iam', resource: 'role', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.roleArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-iam/lib/user.ts b/packages/@aws-cdk/aws-iam/lib/user.ts index 833ee9d81bca0..52d8f9aefe5b0 100644 --- a/packages/@aws-cdk/aws-iam/lib/user.ts +++ b/packages/@aws-cdk/aws-iam/lib/user.ts @@ -108,7 +108,7 @@ export class User extends Resource implements IIdentity { }); const user = new CfnUser(this, 'Resource', { - userName: this.physicalName.value, + userName: this.physicalName, groups: undefinedIfEmpty(() => this.groups), managedPolicyArns: Lazy.listValue({ produce: () => this.managedPolicies.map(p => p.managedPolicyArn) }, { omitEmpty: true }), path: props.path, @@ -117,12 +117,12 @@ export class User extends Resource implements IIdentity { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: user.attrArn, - name: user.refAsString, + name: user.ref, arnComponents: { region: '', // IAM is global in each partition service: 'iam', resource: 'user', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.userName = resourceIdentifiers.name; diff --git a/packages/@aws-cdk/aws-kinesis/lib/stream.ts b/packages/@aws-cdk/aws-kinesis/lib/stream.ts index 329b6324eec23..dac29555daa9f 100644 --- a/packages/@aws-cdk/aws-kinesis/lib/stream.ts +++ b/packages/@aws-cdk/aws-kinesis/lib/stream.ts @@ -254,7 +254,7 @@ export class Stream extends StreamBase { const { streamEncryption, encryptionKey } = this.parseEncryption(props); this.stream = new CfnStream(this, "Resource", { - name: this.physicalName.value, + name: this.physicalName, retentionPeriodHours, shardCount, streamEncryption @@ -262,11 +262,11 @@ export class Stream extends StreamBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: this.stream.attrArn, - name: this.stream.refAsString, + name: this.stream.ref, arnComponents: { service: 'kinesis', resource: 'stream', - resourceName: this.physicalName.value, + resourceName: this.physicalName, }, }); this.streamArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-kms/lib/alias.ts b/packages/@aws-cdk/aws-kms/lib/alias.ts index 26a068caa4363..416c28f34ef68 100644 --- a/packages/@aws-cdk/aws-kms/lib/alias.ts +++ b/packages/@aws-cdk/aws-kms/lib/alias.ts @@ -33,7 +33,7 @@ export interface AliasProps { * forward slash, such as alias/. You can't specify aliases that begin with * alias/AWS. These aliases are reserved. */ - readonly name: string; + readonly aliasName: string; /** * The ID of the key for which you are creating the alias. Specify the key's @@ -81,26 +81,26 @@ export class Alias extends AliasBase { constructor(scope: Construct, id: string, props: AliasProps) { super(scope, id); - if (!Token.isUnresolved(props.name)) { - if (!props.name.startsWith(REQUIRED_ALIAS_PREFIX)) { - throw new Error(`Alias must start with the prefix "${REQUIRED_ALIAS_PREFIX}": ${props.name}`); + if (!Token.isUnresolved(props.aliasName)) { + if (!props.aliasName.startsWith(REQUIRED_ALIAS_PREFIX)) { + throw new Error(`Alias must start with the prefix "${REQUIRED_ALIAS_PREFIX}": ${props.aliasName}`); } - if (props.name === REQUIRED_ALIAS_PREFIX) { - throw new Error(`Alias must include a value after "${REQUIRED_ALIAS_PREFIX}": ${props.name}`); + if (props.aliasName === REQUIRED_ALIAS_PREFIX) { + throw new Error(`Alias must include a value after "${REQUIRED_ALIAS_PREFIX}": ${props.aliasName}`); } - if (props.name.startsWith(DISALLOWED_PREFIX)) { - throw new Error(`Alias cannot start with ${DISALLOWED_PREFIX}: ${props.name}`); + if (props.aliasName.startsWith(DISALLOWED_PREFIX)) { + throw new Error(`Alias cannot start with ${DISALLOWED_PREFIX}: ${props.aliasName}`); } - if (!props.name.match(/^[a-zA-Z0-9:/_-]{1,256}$/)) { + if (!props.aliasName.match(/^[a-zA-Z0-9:/_-]{1,256}$/)) { throw new Error(`Alias name must be between 1 and 256 characters in a-zA-Z0-9:/_-`); } } const resource = new CfnAlias(this, 'Resource', { - aliasName: props.name, + aliasName: props.aliasName, targetKeyId: props.targetKey.keyArn }); diff --git a/packages/@aws-cdk/aws-kms/lib/key.ts b/packages/@aws-cdk/aws-kms/lib/key.ts index 94bb1ec8e438e..e69f997ad5695 100644 --- a/packages/@aws-cdk/aws-kms/lib/key.ts +++ b/packages/@aws-cdk/aws-kms/lib/key.ts @@ -68,7 +68,7 @@ abstract class KeyBase extends Resource implements IKey { * Defines a new alias for the key. */ public addAlias(alias: string): Alias { - return new Alias(this, 'Alias', { name: alias, targetKey: this }); + return new Alias(this, 'Alias', { aliasName: alias, targetKey: this }); } /** diff --git a/packages/@aws-cdk/aws-kms/package.json b/packages/@aws-cdk/aws-kms/package.json index d5f5ce88df197..2e9ec59da5169 100644 --- a/packages/@aws-cdk/aws-kms/package.json +++ b/packages/@aws-cdk/aws-kms/package.json @@ -83,7 +83,6 @@ }, "awslint": { "exclude": [ - "props-physical-name:@aws-cdk/aws-kms.AliasProps", "props-physical-name:@aws-cdk/aws-kms.KeyProps" ] }, diff --git a/packages/@aws-cdk/aws-kms/test/test.alias.ts b/packages/@aws-cdk/aws-kms/test/test.alias.ts index c9549e319f940..c4d3d0219b840 100644 --- a/packages/@aws-cdk/aws-kms/test/test.alias.ts +++ b/packages/@aws-cdk/aws-kms/test/test.alias.ts @@ -10,7 +10,7 @@ export = { const stack = new Stack(app, 'Test'); const key = new Key(stack, 'Key'); - new Alias(stack, 'Alias', { targetKey: key, name: 'alias/foo' }); + new Alias(stack, 'Alias', { targetKey: key, aliasName: 'alias/foo' }); expect(stack).to(haveResource('AWS::KMS::Alias', { AliasName: 'alias/foo', @@ -30,7 +30,7 @@ export = { }); test.throws(() => new Alias(stack, 'Alias', { - name: 'foo', + aliasName: 'foo', targetKey: key })); @@ -47,7 +47,7 @@ export = { }); test.throws(() => new Alias(stack, 'Alias', { - name: 'alias/', + aliasName: 'alias/', targetKey: key })); @@ -64,7 +64,7 @@ export = { }); test.throws(() => new Alias(stack, 'Alias', { - name: 'alias/@Nope', + aliasName: 'alias/@Nope', targetKey: key }), 'a-zA-Z0-9:/_-'); @@ -81,17 +81,17 @@ export = { }); test.throws(() => new Alias(stack, 'Alias', { - name: 'alias/aws/', + aliasName: 'alias/aws/', targetKey: key })); test.throws(() => new Alias(stack, 'Alias', { - name: 'alias/aws/Awesome', + aliasName: 'alias/aws/Awesome', targetKey: key })); test.throws(() => new Alias(stack, 'Alias', { - name: 'alias/AWS/awesome', + aliasName: 'alias/AWS/awesome', targetKey: key })); diff --git a/packages/@aws-cdk/aws-lambda/lib/alias.ts b/packages/@aws-cdk/aws-lambda/lib/alias.ts index 291ff7609c4f1..bb65598f3582f 100644 --- a/packages/@aws-cdk/aws-lambda/lib/alias.ts +++ b/packages/@aws-cdk/aws-lambda/lib/alias.ts @@ -39,7 +39,7 @@ export interface AliasProps { /** * Name of this alias */ - readonly aliasName: PhysicalName; + readonly aliasName: string; /** * Additional versions with individual weights this alias points to @@ -115,11 +115,11 @@ export class Alias extends QualifiedFunctionBase implements IAlias { constructor(scope: Construct, id: string, props: AliasProps) { super(scope, id, { - physicalName: props.aliasName, + physicalName: PhysicalName.of(props.aliasName), }); this.lambda = props.version.lambda; - this.aliasName = this.physicalName.value || ''; + this.aliasName = this.physicalName; this.version = props.version; const alias = new CfnAlias(this, 'Resource', { @@ -131,12 +131,12 @@ export class Alias extends QualifiedFunctionBase implements IAlias { }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: alias.refAsString, + arn: alias.ref, name: this.aliasName, arnComponents: { service: 'lambda', resource: 'function', - resourceName: `${this.lambda.physicalName.value}:${this.physicalName.value}`, + resourceName: `${this.lambda.physicalName}:${this.physicalName}`, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-lambda/lib/function.ts b/packages/@aws-cdk/aws-lambda/lib/function.ts index 0d43a451e565c..ffe7bdedb9678 100644 --- a/packages/@aws-cdk/aws-lambda/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda/lib/function.ts @@ -419,7 +419,7 @@ export class Function extends FunctionBase { } const resource: CfnFunction = new CfnFunction(this, 'Resource', { - functionName: this.physicalName.value, + functionName: this.physicalName, description: props.description, code: Lazy.anyValue({ produce: () => props.code._toJSON(resource) }), layers: Lazy.listValue({ produce: () => this.layers.map(layer => layer.layerVersionArn) }, { omitEmpty: true }), @@ -439,11 +439,11 @@ export class Function extends FunctionBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: resource.attrArn, - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'lambda', resource: 'function', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts index fe354288e383e..c8b0daa36425b 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts @@ -105,7 +105,7 @@ export class Version extends QualifiedFunctionBase implements IVersion { }); this.version = version.attrVersion; - this.functionArn = version.refAsString; + this.functionArn = version.ref; this.functionName = `${this.lambda.functionName}:${this.version}`; } diff --git a/packages/@aws-cdk/aws-lambda/lib/layers.ts b/packages/@aws-cdk/aws-lambda/lib/layers.ts index 16f9ab6b82c80..ba8f4d20bc90f 100644 --- a/packages/@aws-cdk/aws-lambda/lib/layers.ts +++ b/packages/@aws-cdk/aws-lambda/lib/layers.ts @@ -176,11 +176,11 @@ export class LayerVersion extends LayerVersionBase { compatibleRuntimes: props.compatibleRuntimes && props.compatibleRuntimes.map(r => r.name), content: Lazy.anyValue({ produce: () => props.code._toJSON(resource) }), description: props.description, - layerName: this.physicalName.value, + layerName: this.physicalName, licenseInfo: props.license, }); - this.layerVersionArn = resource.refAsString; + this.layerVersionArn = resource.ref; this.compatibleRuntimes = props.compatibleRuntimes; } } diff --git a/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts b/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts index 4c8d9044ba544..4832356abd86d 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.lambda.ts @@ -20,7 +20,7 @@ fn.addToRolePolicy(new iam.PolicyStatement({ const version = fn.addVersion('1'); const alias = new lambda.Alias(stack, 'Alias', { - aliasName: cdk.PhysicalName.of('prod'), + aliasName: 'prod', version, }); alias.addPermission('AliasPermission', { diff --git a/packages/@aws-cdk/aws-lambda/test/test.alias.ts b/packages/@aws-cdk/aws-lambda/test/test.alias.ts index a6b98916220fe..5eb7398ee2865 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.alias.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.alias.ts @@ -16,7 +16,7 @@ export = { const version = fn.addVersion('1'); new lambda.Alias(stack, 'Alias', { - aliasName: PhysicalName.of('prod'), + aliasName: 'prod', version, }); @@ -49,7 +49,7 @@ export = { }); new lambda.Alias(stack, 'Alias', { - aliasName: PhysicalName.of('latest'), + aliasName: 'latest', version: fn.latestVersion, }); @@ -74,7 +74,7 @@ export = { const version = fn.addVersion('NewVersion'); new lambda.Alias(stack, 'Alias', { - aliasName: PhysicalName.of('prod'), + aliasName: 'prod', version, }); @@ -103,7 +103,7 @@ export = { const version2 = fn.addVersion('2'); new lambda.Alias(stack, 'Alias', { - aliasName: PhysicalName.of('prod'), + aliasName: 'prod', version: version1, additionalVersions: [{ version: version2, weight: 0.1 }] }); @@ -137,7 +137,7 @@ export = { // WHEN: Individual weight too high test.throws(() => { new lambda.Alias(stack, 'Alias1', { - aliasName: PhysicalName.of('prod'), version, + aliasName: 'prod', version, additionalVersions: [{ version, weight: 5 }] }); }); @@ -145,7 +145,7 @@ export = { // WHEN: Sum too high test.throws(() => { new lambda.Alias(stack, 'Alias2', { - aliasName: PhysicalName.of('prod'), version, + aliasName: 'prod', version, additionalVersions: [{ version, weight: 0.5 }, { version, weight: 0.6 }] }); }); @@ -164,7 +164,7 @@ export = { }); const version = fn.addVersion('1'); - const alias = new lambda.Alias(stack, 'Alias', { aliasName: PhysicalName.of('prod'), version }); + const alias = new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version }); // WHEN new cloudwatch.Alarm(stack, 'Alarm', { @@ -214,7 +214,7 @@ export = { }); const version = fn.addVersion('1'); - const alias = new lambda.Alias(stack, 'Alias', { aliasName: PhysicalName.of('prod'), version }); + const alias = new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version }); // THEN test.equals(alias.role, fn.role); @@ -233,7 +233,7 @@ export = { }); const version = fn.addVersion('1'); - const alias = new lambda.Alias(stack, 'Alias', { aliasName: PhysicalName.of('prod'), version }); + const alias = new lambda.Alias(stack, 'Alias', { aliasName: 'prod', version }); // WHEN test.deepEqual(stack.resolve(alias.functionName), { diff --git a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts index 043ae2e73bf7a..b9f628f5f6f9c 100644 --- a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts +++ b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts @@ -73,7 +73,7 @@ export class CrossAccountDestination extends cdk.Resource implements ILogSubscri }); this.resource = new CfnDestination(this, 'Resource', { - destinationName: this.physicalName.value!, + destinationName: this.physicalName!, // Must be stringified policy destinationPolicy: this.lazyStringifiedPolicyDocument(), roleArn: props.role.roleArn, @@ -82,11 +82,11 @@ export class CrossAccountDestination extends cdk.Resource implements ILogSubscri const resourceIdentifiers = new ResourceIdentifiers(this, { arn: this.resource.attrArn, - name: this.resource.refAsString, + name: this.resource.ref, arnComponents: { service: 'logs', resource: 'destination', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-logs/lib/log-group.ts b/packages/@aws-cdk/aws-logs/lib/log-group.ts index 2fae3647099b7..a0e8f7ae4707d 100644 --- a/packages/@aws-cdk/aws-logs/lib/log-group.ts +++ b/packages/@aws-cdk/aws-logs/lib/log-group.ts @@ -335,7 +335,7 @@ export class LogGroup extends LogGroupBase { } const resource = new CfnLogGroup(this, 'Resource', { - logGroupName: this.physicalName.value, + logGroupName: this.physicalName, retentionInDays, }); @@ -343,11 +343,11 @@ export class LogGroup extends LogGroupBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: resource.attrArn, - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'logs', resource: 'log-group', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-logs/lib/log-stream.ts b/packages/@aws-cdk/aws-logs/lib/log-stream.ts index 0f58274d9fea1..034e18be578c9 100644 --- a/packages/@aws-cdk/aws-logs/lib/log-stream.ts +++ b/packages/@aws-cdk/aws-logs/lib/log-stream.ts @@ -70,18 +70,18 @@ export class LogStream extends Resource implements ILogStream { const resource = new CfnLogStream(this, 'Resource', { logGroupName: props.logGroup.logGroupName, - logStreamName: this.physicalName.value, + logStreamName: this.physicalName, }); resource.applyRemovalPolicy(props.removalPolicy); const resourceIdentifiers = new ResourceIdentifiers(this, { arn: '', - name: resource.refAsString, + name: resource.ref, arnComponents: { service: 'logs', resource: 'log-group', - resourceName: `log-stream:${this.physicalName.value}`, + resourceName: `log-stream:${this.physicalName}`, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-rds/lib/cluster.ts b/packages/@aws-cdk/aws-rds/lib/cluster.ts index 9339efffff502..e284675f8e111 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster.ts @@ -301,7 +301,7 @@ export class DatabaseCluster extends DatabaseClusterBase { engine: props.engine.name, engineVersion: props.engineVersion, dbClusterIdentifier: props.clusterIdentifier, - dbSubnetGroupName: subnetGroup.refAsString, + dbSubnetGroupName: subnetGroup.ref, vpcSecurityGroupIds: [this.securityGroupId], port: props.port, dbClusterParameterGroupName: props.parameterGroup && props.parameterGroup.parameterGroupName, @@ -325,7 +325,7 @@ export class DatabaseCluster extends DatabaseClusterBase { applyToUpdateReplacePolicy: true }); - this.clusterIdentifier = cluster.refAsString; + this.clusterIdentifier = cluster.ref; // create a number token that represents the port of the cluster const portAttribute = Token.asNumber(cluster.attrEndpointPort); @@ -358,13 +358,13 @@ export class DatabaseCluster extends DatabaseClusterBase { // Link to cluster engine: props.engine.name, engineVersion: props.engineVersion, - dbClusterIdentifier: cluster.refAsString, + dbClusterIdentifier: cluster.ref, dbInstanceIdentifier: instanceIdentifier, // Instance properties dbInstanceClass: databaseInstanceType(props.instanceProps.instanceType), publiclyAccessible, // This is already set on the Cluster. Unclear to me whether it should be repeated or not. Better yes. - dbSubnetGroupName: subnetGroup.refAsString, + dbSubnetGroupName: subnetGroup.ref, dbParameterGroupName: props.instanceProps.parameterGroup && props.instanceProps.parameterGroup.parameterGroupName, }); @@ -376,7 +376,7 @@ export class DatabaseCluster extends DatabaseClusterBase { // things in the right order. instance.node.addDependency(internetConnected); - this.instanceIdentifiers.push(instance.refAsString); + this.instanceIdentifiers.push(instance.ref); this.instanceEndpoints.push(new Endpoint(instance.attrEndpointAddress, portAttribute)); } diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index d5cbcd66d6af5..db6ca4fe74bc2 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -505,7 +505,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData copyTagsToSnapshot: props.copyTagsToSnapshot !== undefined ? props.copyTagsToSnapshot : true, dbInstanceClass: `db.${props.instanceClass}`, dbInstanceIdentifier: props.instanceIdentifier, - dbSubnetGroupName: subnetGroup.refAsString, + dbSubnetGroupName: subnetGroup.ref, deleteAutomatedBackups: props.deleteAutomatedBackups, deletionProtection, enableCloudwatchLogsExports: this.cloudwatchLogsExports, @@ -733,7 +733,7 @@ export class DatabaseInstance extends DatabaseInstanceSource implements IDatabas storageEncrypted: props.kmsKey ? true : props.storageEncrypted }); - this.instanceIdentifier = instance.refAsString; + this.instanceIdentifier = instance.ref; this.dbInstanceEndpointAddress = instance.attrEndpointAddress; this.dbInstanceEndpointPort = instance.attrEndpointPort; @@ -827,7 +827,7 @@ export class DatabaseInstanceFromSnapshot extends DatabaseInstanceSource impleme : undefined), }); - this.instanceIdentifier = instance.refAsString; + this.instanceIdentifier = instance.ref; this.dbInstanceEndpointAddress = instance.attrEndpointAddress; this.dbInstanceEndpointPort = instance.attrEndpointPort; @@ -904,7 +904,7 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements storageEncrypted: props.kmsKey ? true : props.storageEncrypted, }); - this.instanceIdentifier = instance.refAsString; + this.instanceIdentifier = instance.ref; this.dbInstanceEndpointAddress = instance.attrEndpointAddress; this.dbInstanceEndpointPort = instance.attrEndpointPort; diff --git a/packages/@aws-cdk/aws-rds/lib/option-group.ts b/packages/@aws-cdk/aws-rds/lib/option-group.ts index d18318736d4aa..ae7f3c3a8ca01 100644 --- a/packages/@aws-cdk/aws-rds/lib/option-group.ts +++ b/packages/@aws-cdk/aws-rds/lib/option-group.ts @@ -122,7 +122,7 @@ export class OptionGroup extends Resource implements IOptionGroup { optionConfigurations: this.renderConfigurations(props.configurations) }); - this.optionGroupName = optionGroup.refAsString; + this.optionGroupName = optionGroup.ref; } /** diff --git a/packages/@aws-cdk/aws-rds/lib/parameter-group.ts b/packages/@aws-cdk/aws-rds/lib/parameter-group.ts index 1bc0722195535..a0be5a2661265 100644 --- a/packages/@aws-cdk/aws-rds/lib/parameter-group.ts +++ b/packages/@aws-cdk/aws-rds/lib/parameter-group.ts @@ -85,7 +85,7 @@ export class ParameterGroup extends ParameterGroupBase { parameters: props.parameters, }); - this.parameterGroupName = resource.refAsString; + this.parameterGroupName = resource.ref; } } @@ -116,6 +116,6 @@ export class ClusterParameterGroup extends ParameterGroupBase { parameters: props.parameters, }); - this.parameterGroupName = resource.refAsString; + this.parameterGroupName = resource.ref; } } diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts index 87d2f346b103e..e848e5633bbeb 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts @@ -121,7 +121,7 @@ export class HostedZone extends Resource implements IHostedZone { vpcs: Lazy.anyValue({ produce: () => this.vpcs.length === 0 ? undefined : this.vpcs }) }); - this.hostedZoneId = resource.refAsString; + this.hostedZoneId = resource.ref; this.hostedZoneNameServers = resource.attrNameServers; this.zoneName = props.zoneName; diff --git a/packages/@aws-cdk/aws-route53/lib/record-set.ts b/packages/@aws-cdk/aws-route53/lib/record-set.ts index 1d178c6abc69d..a4548b16e1e3f 100644 --- a/packages/@aws-cdk/aws-route53/lib/record-set.ts +++ b/packages/@aws-cdk/aws-route53/lib/record-set.ts @@ -122,7 +122,7 @@ export class RecordSet extends Resource implements IRecordSet { comment: props.comment }); - this.domainName = recordSet.refAsString; + this.domainName = recordSet.ref; } } diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index fb79be37d2713..bbbc8db81ff48 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -889,12 +889,11 @@ export class Bucket extends BucketBase { }); const { bucketEncryption, encryptionKey } = this.parseEncryption(props); - if (props.bucketName && !Token.isUnresolved(props.bucketName)) { - this.validateBucketName(props.bucketName); - } + + this.validateBucketName(this.physicalName); const resource = new CfnBucket(this, 'Resource', { - bucketName: this.physicalName.value, + bucketName: this.physicalName, bucketEncryption, versioningConfiguration: props.versioned ? { status: 'Enabled' } : undefined, lifecycleConfiguration: Lazy.anyValue({ produce: () => this.parseLifecycleConfiguration() }), @@ -911,12 +910,12 @@ export class Bucket extends BucketBase { const resourceIdentifiers = new ResourceIdentifiers(this, { arn: resource.attrArn, - name: resource.refAsString, + name: resource.ref, arnComponents: { region: '', account: '', service: 's3', - resource: this.physicalName.value || '', + resource: this.physicalName, }, }); this.bucketArn = resourceIdentifiers.arn; @@ -1025,8 +1024,8 @@ export class Bucket extends BucketBase { return this.addEventNotification(EventType.OBJECT_REMOVED, dest, ...filters); } - private validateBucketName(physicalName: PhysicalName): void { - const bucketName = physicalName.value; + private validateBucketName(physicalName: string): void { + const bucketName = physicalName; if (!bucketName || Token.isUnresolved(bucketName)) { // the name is a late-bound value, not a defined string, // so skip validation diff --git a/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts b/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts index 435c49bf1a9d5..fffe1a2b0792f 100644 --- a/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts +++ b/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts @@ -187,16 +187,16 @@ export class Secret extends SecretBase { description: props.description, kmsKeyId: props.encryptionKey && props.encryptionKey.keyArn, generateSecretString: props.generateSecretString || {}, - name: this.physicalName.value, + name: this.physicalName, }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: resource.refAsString, - name: this.physicalName.value || '', + arn: resource.ref, + name: this.physicalName, arnComponents: { service: 'secretsmanager', resource: 'secret', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); @@ -322,8 +322,8 @@ export class SecretTargetAttachment extends SecretBase implements ISecretTargetA this.encryptionKey = props.secret.encryptionKey; // This allows to reference the secret after attachment (dependency). - this.secretArn = attachment.refAsString; - this.secretTargetAttachmentSecretArn = attachment.refAsString; + this.secretArn = attachment.ref; + this.secretTargetAttachmentSecretArn = attachment.ref; } } diff --git a/packages/@aws-cdk/aws-servicediscovery/lib/alias-target-instance.ts b/packages/@aws-cdk/aws-servicediscovery/lib/alias-target-instance.ts index dbcbb65b1b56a..f3ce0c744e669 100644 --- a/packages/@aws-cdk/aws-servicediscovery/lib/alias-target-instance.ts +++ b/packages/@aws-cdk/aws-servicediscovery/lib/alias-target-instance.ts @@ -70,7 +70,7 @@ export class AliasTargetInstance extends InstanceBase { }); this.service = props.service; - this.instanceId = resource.refAsString; + this.instanceId = resource.ref; this.dnsName = props.dnsName; } } diff --git a/packages/@aws-cdk/aws-servicediscovery/lib/cname-instance.ts b/packages/@aws-cdk/aws-servicediscovery/lib/cname-instance.ts index a1f559e6c1a02..3bdaf1ffeb77d 100644 --- a/packages/@aws-cdk/aws-servicediscovery/lib/cname-instance.ts +++ b/packages/@aws-cdk/aws-servicediscovery/lib/cname-instance.ts @@ -67,7 +67,7 @@ export class CnameInstance extends InstanceBase { }); this.service = props.service; - this.instanceId = resource.refAsString; + this.instanceId = resource.ref; this.cname = props.instanceCname; } } diff --git a/packages/@aws-cdk/aws-servicediscovery/lib/ip-instance.ts b/packages/@aws-cdk/aws-servicediscovery/lib/ip-instance.ts index 8c7b36c1d042b..1724cb7dbee3e 100644 --- a/packages/@aws-cdk/aws-servicediscovery/lib/ip-instance.ts +++ b/packages/@aws-cdk/aws-servicediscovery/lib/ip-instance.ts @@ -114,7 +114,7 @@ export class IpInstance extends InstanceBase { }); this.service = props.service; - this.instanceId = resource.refAsString; + this.instanceId = resource.ref; this.ipv4 = props.ipv4 || ''; this.ipv6 = props.ipv6 || ''; this.port = port; diff --git a/packages/@aws-cdk/aws-servicediscovery/lib/non-ip-instance.ts b/packages/@aws-cdk/aws-servicediscovery/lib/non-ip-instance.ts index 69435c507e641..1346fdcf02eb7 100644 --- a/packages/@aws-cdk/aws-servicediscovery/lib/non-ip-instance.ts +++ b/packages/@aws-cdk/aws-servicediscovery/lib/non-ip-instance.ts @@ -55,6 +55,6 @@ export class NonIpInstance extends InstanceBase { }); this.service = props.service; - this.instanceId = resource.refAsString; + this.instanceId = resource.ref; } } diff --git a/packages/@aws-cdk/aws-ses/lib/receipt-filter.ts b/packages/@aws-cdk/aws-ses/lib/receipt-filter.ts index bd18c74cbd07c..14058110b6fd6 100644 --- a/packages/@aws-cdk/aws-ses/lib/receipt-filter.ts +++ b/packages/@aws-cdk/aws-ses/lib/receipt-filter.ts @@ -58,7 +58,7 @@ export class ReceiptFilter extends Resource { cidr: props.ip || '0.0.0.0/0', policy: props.policy || ReceiptFilterPolicy.BLOCK, }, - name: this.physicalName.value, + name: this.physicalName, } }); } diff --git a/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts b/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts index e3a0927943565..e753a87a47c90 100644 --- a/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts +++ b/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts @@ -102,10 +102,10 @@ export class ReceiptRuleSet extends ReceiptRuleSetBase { }); const resource = new CfnReceiptRuleSet(this, 'Resource', { - ruleSetName: this.physicalName.value, + ruleSetName: this.physicalName, }); - this.receiptRuleSetName = resource.refAsString; + this.receiptRuleSetName = resource.ref; if (props) { const rules = props.rules || []; diff --git a/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts b/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts index 700168fa79d2e..30be18d86c53c 100644 --- a/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts +++ b/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts @@ -122,7 +122,7 @@ export class ReceiptRule extends Resource implements IReceiptRule { rule: { actions: Lazy.anyValue({ produce: () => this.getRenderedActions() }), enabled: props.enabled === undefined ? true : props.enabled, - name: this.physicalName.value, + name: this.physicalName, recipients: props.recipients, scanEnabled: props.scanEnabled, tlsPolicy: props.tlsPolicy @@ -130,7 +130,7 @@ export class ReceiptRule extends Resource implements IReceiptRule { ruleSetName: props.ruleSet.receiptRuleSetName }); - this.receiptRuleName = resource.refAsString; + this.receiptRuleName = resource.ref; if (props.actions) { props.actions.forEach(action => this.addAction(action)); diff --git a/packages/@aws-cdk/aws-sns/lib/topic.ts b/packages/@aws-cdk/aws-sns/lib/topic.ts index f8a9e8d23c7c9..f0e8a7559a5ef 100644 --- a/packages/@aws-cdk/aws-sns/lib/topic.ts +++ b/packages/@aws-cdk/aws-sns/lib/topic.ts @@ -52,15 +52,15 @@ export class Topic extends TopicBase { const resource = new CfnTopic(this, 'Resource', { displayName: props.displayName, - topicName: this.physicalName.value, + topicName: this.physicalName, }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: resource.refAsString, + arn: resource.ref, name: resource.attrTopicName, arnComponents: { service: 'sns', - resource: this.physicalName.value || '', + resource: this.physicalName, }, }); this.topicArn = resourceIdentifiers.arn; diff --git a/packages/@aws-cdk/aws-sqs/lib/queue.ts b/packages/@aws-cdk/aws-sqs/lib/queue.ts index a92a0f95c045f..85685e41bc74d 100644 --- a/packages/@aws-cdk/aws-sqs/lib/queue.ts +++ b/packages/@aws-cdk/aws-sqs/lib/queue.ts @@ -246,7 +246,7 @@ export class Queue extends QueueBase { const { encryptionMasterKey, encryptionProps } = _determineEncryptionProps.call(this); const queue = new CfnQueue(this, 'Resource', { - queueName: this.physicalName.value, + queueName: this.physicalName, ...this.determineFifoProps(props), ...encryptionProps, redrivePolicy, @@ -262,13 +262,13 @@ export class Queue extends QueueBase { name: queue.attrQueueName, arnComponents: { service: 'sqs', - resource: this.physicalName.value || '', + resource: this.physicalName, }, }); this.queueArn = resourceIdentifiers.arn; this.queueName = resourceIdentifiers.name; this.encryptionMasterKey = encryptionMasterKey; - this.queueUrl = queue.refAsString; + this.queueUrl = queue.ref; function _determineEncryptionProps(this: Queue): { encryptionProps: EncryptionProps, encryptionMasterKey?: kms.IKey } { let encryption = props.encryption || QueueEncryption.UNENCRYPTED; diff --git a/packages/@aws-cdk/aws-ssm/lib/parameter.ts b/packages/@aws-cdk/aws-ssm/lib/parameter.ts index f5706cd2d703d..8dfc5f99c6df2 100644 --- a/packages/@aws-cdk/aws-ssm/lib/parameter.ts +++ b/packages/@aws-cdk/aws-ssm/lib/parameter.ts @@ -285,18 +285,18 @@ export class StringParameter extends ParameterBase implements IStringParameter { const resource = new ssm.CfnParameter(this, 'Resource', { allowedPattern: props.allowedPattern, description: props.description, - name: this.physicalName.value, + name: this.physicalName, type: STRING_PARAM_TYPE, value: props.stringValue, }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: arnForParameterName(this, resource.refAsString), - name: resource.refAsString, + arn: arnForParameterName(this, resource.ref), + name: resource.ref, arnComponents: { service: 'ssm', resource: 'parameter', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: '', // `sep` is empty because parameterName starts with a / already! }, }); @@ -349,17 +349,17 @@ export class StringListParameter extends ParameterBase implements IStringListPar const resource = new ssm.CfnParameter(this, 'Resource', { allowedPattern: props.allowedPattern, description: props.description, - name: this.physicalName.value, + name: this.physicalName, type: STRINGLIST_PARAM_TYPE, value: props.stringListValue.join(','), }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: arnForParameterName(this, resource.refAsString), - name: resource.refAsString, + arn: arnForParameterName(this, resource.ref), + name: resource.ref, arnComponents: { service: 'ssm', resource: 'parameter', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: '', // `sep` is empty because parameterName starts with a / already! }, }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.invoke-function.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.invoke-function.ts index 2f0e1d2a797ec..647ae674d73aa 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.invoke-function.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.invoke-function.ts @@ -54,4 +54,4 @@ new sfn.StateMachine(stack, 'StateMachine', { timeoutSec: 30 }); -app.run(); \ No newline at end of file +app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts b/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts index b1fea496569d1..df969a3d7520c 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts @@ -58,16 +58,16 @@ export class Activity extends Resource implements IActivity { }); const resource = new CfnActivity(this, 'Resource', { - name: this.physicalName.value! // not null because of above call to `super` + name: this.physicalName! // not null because of above call to `super` }); const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: resource.refAsString, + arn: resource.ref, name: resource.attrName, arnComponents: { service: 'states', resource: 'activity', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index 04d0f8029caa0..cd72201930bed 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -99,7 +99,7 @@ export class StateMachine extends StateMachineBase { graph.timeoutSeconds = props.timeoutSec; const resource = new CfnStateMachine(this, 'Resource', { - stateMachineName: this.physicalName.value, + stateMachineName: this.physicalName, roleArn: this.role.roleArn, definitionString: Stack.of(this).toJsonString(graph.toGraphJson()), }); @@ -109,12 +109,12 @@ export class StateMachine extends StateMachineBase { } const resourceIdentifiers = new ResourceIdentifiers(this, { - arn: resource.refAsString, + arn: resource.ref, name: resource.attrName, arnComponents: { service: 'states', resource: 'stateMachine', - resourceName: this.physicalName.value, + resourceName: this.physicalName, sep: ':', }, }); diff --git a/packages/@aws-cdk/cdk/lib/app.ts b/packages/@aws-cdk/cdk/lib/app.ts index 8c52b1b84539f..dec5fe1720128 100644 --- a/packages/@aws-cdk/cdk/lib/app.ts +++ b/packages/@aws-cdk/cdk/lib/app.ts @@ -1,7 +1,7 @@ import cxapi = require('@aws-cdk/cx-api'); import { CloudAssembly } from '@aws-cdk/cx-api'; import { Construct, ConstructNode } from './construct'; -import { collectRuntimeInformation } from './runtime-info'; +import { collectRuntimeInformation } from './private/runtime-info'; const APP_SYMBOL = Symbol.for('@aws-cdk/cdk.App'); @@ -131,13 +131,6 @@ export class App extends Construct { return assembly; } - /** - * @deprecated use `synth()` - */ - public run() { - return this.synth(); - } - private loadContext(defaults: { [key: string]: string } = { }) { // prime with defaults passed through constructor for (const [ k, v ] of Object.entries(defaults)) { diff --git a/packages/@aws-cdk/cdk/lib/arn.ts b/packages/@aws-cdk/cdk/lib/arn.ts index 2a74dbb0f89f9..31a6a22106d65 100644 --- a/packages/@aws-cdk/cdk/lib/arn.ts +++ b/packages/@aws-cdk/cdk/lib/arn.ts @@ -1,4 +1,4 @@ -import { Fn } from './fn'; +import { Fn } from './cfn-fn'; import { Stack } from './stack'; import { Token } from './token'; import { filterUndefined } from './util'; diff --git a/packages/@aws-cdk/cdk/lib/cfn-condition.ts b/packages/@aws-cdk/cdk/lib/cfn-condition.ts index d232ce7ed21c4..492bd2dbc0e3c 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-condition.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-condition.ts @@ -16,8 +16,6 @@ export interface CfnConditionProps { * the determination must be made at deploy time. */ export class CfnCondition extends CfnElement implements ICfnConditionExpression, IResolvable { - public readonly displayHint: string | undefined; - /** * The condition statement. */ @@ -29,7 +27,6 @@ export class CfnCondition extends CfnElement implements ICfnConditionExpression, */ constructor(scope: Construct, id: string, props?: CfnConditionProps) { super(scope, id); - this.displayHint = `Cond${id}`; this.expression = props && props.expression; } @@ -79,29 +76,14 @@ export class CfnCondition extends CfnElement implements ICfnConditionExpression, * capabilities; however, for the test environment, you want to use less * capabilities to save costs. With conditions, you can define which resources * are created and how they're configured for each environment type. + * + * You can use `toString` when you wish to embed a condition expression + * in a property value that accepts a `string`. For example: + * + * ```ts + * new sqs.Queue(this, 'MyQueue', { + * queueName: Fn.conditionIf('Condition', 'Hello', 'World').toString() + * }); + * ``` */ -export interface ICfnConditionExpression { - /** - * Returns a JSON node that represents this condition expression - */ - resolve(context: IResolveContext): any; - - /** - * Returns a string token representation of this condition expression, which - * resolves to the CloudFormation condition JSON during synthesis. - * - * You can use `toString` when you wish to embed a condition expression - * in a property value that accepts a `string`. For example: - * - * ```ts - * new sqs.Queue(this, 'MyQueue', { - * queueName: Fn.conditionIf('Condition', 'Hello', 'World').toString() - * }); - * ``` - * - * NOTE: we need this explicitly here despite the fact that in JavaScript this would - * "just work" since conditions are eventually tokens that implement `toString`, - * in order for jsii languages like Java to proxy this to jsii. - */ - toString(): string; -} +export interface ICfnConditionExpression extends IResolvable { } diff --git a/packages/@aws-cdk/cdk/lib/cfn-dynamic-reference.ts b/packages/@aws-cdk/cdk/lib/cfn-dynamic-reference.ts index f545f77aa62eb..9727d7356a821 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-dynamic-reference.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-dynamic-reference.ts @@ -3,7 +3,7 @@ import { Intrinsic } from "./private/intrinsic"; /** * Properties for a Dynamic Reference */ -export interface DynamicReferenceProps { +export interface CfnDynamicReferenceProps { /** * The service to retrieve the dynamic reference from */ diff --git a/packages/@aws-cdk/cdk/lib/cfn-element.ts b/packages/@aws-cdk/cdk/lib/cfn-element.ts index 25014794a8c10..4b24d7560e757 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-element.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-element.ts @@ -164,17 +164,13 @@ export abstract class CfnElement extends Construct { */ export abstract class CfnRefElement extends CfnElement { /** - * Return a token that will CloudFormation { Ref } this stack element - */ - public get ref(): IResolvable { - return CfnReference.for(this, 'Ref'); - } - - /** - * Return a string that will CloudFormation { Ref } this stack element + * Return a string that will be resolved to a CloudFormation `{ Ref }` for this element. + * + * If, by any chance, the intrinsic reference of a resource is not a string, you could + * coerce it to an IResolvable through `Lazy.any({ produce: resource.ref })`. */ - public get refAsString(): string { - return Token.asString(this.ref); + public get ref(): string { + return Token.asString(CfnReference.for(this, 'Ref')); } } @@ -185,5 +181,4 @@ function notTooLong(x: string) { import { CfnReference } from "./private/cfn-reference"; import { findTokens } from "./private/resolve"; -import { IResolvable } from "./resolvable"; import { Stack } from './stack'; diff --git a/packages/@aws-cdk/cdk/lib/fn.ts b/packages/@aws-cdk/cdk/lib/cfn-fn.ts similarity index 99% rename from packages/@aws-cdk/cdk/lib/fn.ts rename to packages/@aws-cdk/cdk/lib/cfn-fn.ts index 41a03d589c5af..0f235f4c80bea 100644 --- a/packages/@aws-cdk/cdk/lib/fn.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-fn.ts @@ -1,5 +1,5 @@ import { ICfnConditionExpression } from './cfn-condition'; -import { minimalCloudFormationJoin } from './cloudformation-lang'; +import { minimalCloudFormationJoin } from './private/cloudformation-lang'; import { Intrinsic } from './private/intrinsic'; import { IResolvable, IResolveContext } from './resolvable'; import { captureStackTrace } from './stack-trace'; diff --git a/packages/@aws-cdk/cdk/lib/include.ts b/packages/@aws-cdk/cdk/lib/cfn-include.ts similarity index 87% rename from packages/@aws-cdk/cdk/lib/include.ts rename to packages/@aws-cdk/cdk/lib/cfn-include.ts index b63e7cff1493e..667c31ad34c23 100644 --- a/packages/@aws-cdk/cdk/lib/include.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-include.ts @@ -1,7 +1,7 @@ import { CfnElement } from './cfn-element'; import { Construct } from './construct'; -export interface IncludeProps { +export interface CfnIncludeProps { /** * The CloudFormation template to include in the stack (as is). */ @@ -12,7 +12,7 @@ export interface IncludeProps { * Includes a CloudFormation template into a stack. All elements of the template will be merged into * the current stack, together with any elements created programmatically. */ -export class Include extends CfnElement { +export class CfnInclude extends CfnElement { /** * The included template. */ @@ -26,7 +26,7 @@ export class Include extends CfnElement { * @param id The ID of this construct * @param template The template to adopt. */ - constructor(scope: Construct, id: string, props: IncludeProps) { + constructor(scope: Construct, id: string, props: CfnIncludeProps) { super(scope, id); this.template = props.template; } diff --git a/packages/@aws-cdk/cdk/lib/cfn-mapping.ts b/packages/@aws-cdk/cdk/lib/cfn-mapping.ts index d02a435bc3024..cdafb76ddb27e 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-mapping.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-mapping.ts @@ -1,6 +1,6 @@ import { CfnRefElement } from './cfn-element'; +import { Fn } from './cfn-fn'; import { Construct } from './construct'; -import { Fn } from './fn'; import { Token } from './token'; export interface CfnMappingProps { diff --git a/packages/@aws-cdk/cdk/lib/cfn-output.ts b/packages/@aws-cdk/cdk/lib/cfn-output.ts index e5f2a764d777d..ecc8fd03bb7bb 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-output.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-output.ts @@ -15,33 +15,20 @@ export interface CfnOutputProps { * The value of an output can include literals, parameter references, pseudo-parameters, * a mapping value, or intrinsic functions. */ - readonly value: any; + readonly value: string; /** * The name used to export the value of this output across stacks. * - * To import the value from another stack, use `FnImportValue(export)`. You - * can create an import value token by calling `output.makeImportValue()`. + * To import the value from another stack, use `Fn.importValue(exportName)`. * - * @default - Automatically allocate a name when `makeImportValue()` is - * called. + * @default - the output is not exported */ - readonly export?: string; + readonly exportName?: string; /** - * Disables the automatic allocation of an export name for this output. - * - * This prohibits exporting this value, either by specifying `export` or - * by calling `makeImportValue()`. - * - * @default false - */ - readonly disableExport?: boolean; - - /** - * A condition from the "Conditions" section to associate with this output - * value. If the condition evaluates to `false`, this output value will not - * be included in the stack. + * A condition to associate with this output value. If the condition evaluates + * to `false`, this output value will not be included in the stack. * * @default - No condition is associated with the output. */ @@ -49,30 +36,10 @@ export interface CfnOutputProps { } export class CfnOutput extends CfnElement { - /** - * A String type that describes the output value. - * The description can be a maximum of 4 K in length. - */ - public readonly description?: string; - - /** - * The name of the resource output to be exported for a cross-stack reference. - * By default, the logical ID of the CfnOutput element is used as it's export name. - * - * May be undefined if the CfnOutput hasn't been exported yet. - */ - public export?: string; - - /** - * A condition from the "Conditions" section to associate with this output - * value. If the condition evaluates to `false`, this output value will not - * be included in the stack. - */ - public readonly condition?: CfnCondition; - - private _value?: any; - - private disableExport: boolean; + private readonly _description?: string; + private readonly _condition?: CfnCondition; + private readonly _value?: any; + private readonly _export?: string; /** * Creates an CfnOutput value for this stack. @@ -86,37 +53,10 @@ export class CfnOutput extends CfnElement { throw new Error(`Missing value for CloudFormation output at path "${this.node.path}"`); } - this.description = props.description; + this._description = props.description; this._value = props.value; - this.condition = props.condition; - - this.disableExport = props.disableExport !== undefined ? props.disableExport : false; - - if (props.export && this.disableExport) { - throw new Error('Cannot set `disableExport` and specify an export name'); - } - - this.export = props.export; - - if (props.export) { - this.export = props.export; - } - } - - /** - * The value of the property returned by the aws cloudformation describe-stacks command. - * The value of an output can include literals, parameter references, pseudo-parameters, - * a mapping value, or intrinsic functions. - */ - public get value(): any { - return this._value; - } - - /** - * Returns an FnImportValue bound to this export name. - */ - public makeImportValue() { - return fn().importValue(this.obtainExportName()); + this._condition = props.condition; + this._export = props.exportName; } /** @@ -126,150 +66,14 @@ export class CfnOutput extends CfnElement { return { Outputs: { [this.logicalId]: { - Description: this.description, - Value: this.value, - Export: this.export != null ? { Name: this.export } : undefined, - Condition: this.condition ? this.condition.logicalId : undefined + Description: this._description, + Value: this._value, + Export: this._export != null ? { Name: this._export } : undefined, + Condition: this._condition ? this._condition.logicalId : undefined } } }; } - - /** - * Allocate an export name for this `CfnOutput` if not already done. - */ - public obtainExportName(): string { - if (!this.export && this.disableExport) { - throw new Error('Cannot create an ImportValue; `disableExport` has been set.'); - } - if (!this.export) { - this.export = this.uniqueOutputName(); - } - return this.export; - } - - /** - * Automatically determine an output name for use with FnImportValue - * - * This gets called in case the user hasn't specified an export name but is - * taking an action that requires exporting. We namespace with the stack name - * to reduce chances of collissions between CDK apps. - */ - private uniqueOutputName() { - // prefix export name with stack name since exports are global within account + region. - const stackName = this.stack.stackName; - return (stackName ? stackName + ':' : '') + this.logicalId; - } -} - -/** - * Properties for ListOutput - */ -export interface StringListCfnOutputProps { - /** - * A String type that describes the output value. - * The description can be a maximum of 4 K in length. - * - * @default - No description. - */ - readonly description?: string; - - /** - * The list of primitives to export - */ - readonly values: any[]; - - /** - * The separator to use to separate stringified values - * - * @default "," - */ - readonly separator?: string; - - /** - * The name used to export the value of this output across stacks. To import - * the value from another stack, use `FnImportValue(export)`. You can create - * an import value token by calling `output.makeImportValue()`. - * - * @default The default behavior is to automatically allocate an export name - * for outputs based on the stack name and the output's logical ID. To - * create an output without an export, set `disableExport: true`. - */ - readonly export?: string; - - /** - * Disables the automatic allocation of an export name for this output. - * - * @default false, which means that an export name is either explicitly - * specified or allocated based on the output's logical ID and stack name. - */ - readonly disableExport?: boolean; - - /** - * A condition from the "Conditions" section to associate with this output - * value. If the condition evaluates to `false`, this output value will not - * be included in the stack. - * - * @default - None. - */ - readonly condition?: CfnCondition; -} - -/** - * An output for a list of strings. - * - * Exports a list of Tokens via an CfnOutput variable, and return a list of Tokens - * that selects the imported values for them. - */ -export class StringListCfnOutput extends Construct { - /** - * Number of elements in the stringlist - */ - public readonly length: number; - - /** - * The separator used to combine the string values - */ - private readonly separator: string; - - /** - * The CfnOutput object that was created - */ - private readonly output: CfnOutput; - - constructor(scope: Construct, id: string, props: StringListCfnOutputProps) { - super(scope, id); - - this.separator = props.separator || ','; - this.length = props.values.length; - - this.output = new CfnOutput(this, 'Resource', { - description: props.description, - condition: props.condition, - disableExport: props.disableExport, - export: props.export, - value: fn().join(this.separator, props.values) - }); - } - - /** - * Return an array of imported values for this CfnOutput - */ - public makeImportValues(): string[] { - const combined = this.output.makeImportValue(); - - const ret = []; - for (let i = 0; i < this.length; i++) { - ret.push(fn().select(i, fn().split(this.separator, combined))); - } - - return ret; - } -} - -function fn() { - // Lazy loading of "Fn" module to break dependency cycles on startup - return require('./fn').Fn; } import { CfnCondition } from './cfn-condition'; diff --git a/packages/@aws-cdk/cdk/lib/cfn-parameter.ts b/packages/@aws-cdk/cdk/lib/cfn-parameter.ts index 15004490a079f..7a8d3ae6845ca 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-parameter.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-parameter.ts @@ -90,22 +90,15 @@ export interface CfnParameterProps { } /** + * A CloudFormation parameter. + * * Use the optional Parameters section to customize your templates. * Parameters enable you to input custom values to your template each time you create or * update a stack. */ -export class CfnParameter extends CfnElement implements IResolvable { - public readonly displayHint: string | undefined; - - /** - * Indicates if this parameter has "NoEcho" set. - */ - public readonly noEcho: boolean; - +export class CfnParameter extends CfnElement { private readonly type: string; - private properties: CfnParameterProps; - /** * Creates a parameter construct. * Note that the name (logical ID) of the parameter will derive from it's `coname` and location @@ -114,12 +107,17 @@ export class CfnParameter extends CfnElement implements IResolvable { * @param scope The parent construct. * @param props The parameter properties. */ - constructor(scope: Construct, id: string, props: CfnParameterProps = {}) { + constructor(scope: Construct, id: string, private readonly props: CfnParameterProps = {}) { super(scope, id); + this.type = props.type || 'String'; - this.displayHint = `Param${id}`; - this.properties = props; - this.noEcho = props.noEcho || false; + } + + /** + * Indicates if this parameter is configured with "NoEcho" enabled. + */ + public get noEcho(): boolean { + return !!this.props.noEcho; } /** @@ -167,16 +165,16 @@ export class CfnParameter extends CfnElement implements IResolvable { Parameters: { [this.logicalId]: { Type: this.type, - Default: this.properties.default, - AllowedPattern: this.properties.allowedPattern, - AllowedValues: this.properties.allowedValues, - ConstraintDescription: this.properties.constraintDescription, - Description: this.properties.description, - MaxLength: this.properties.maxLength, - MaxValue: this.properties.maxValue, - MinLength: this.properties.minLength, - MinValue: this.properties.minValue, - NoEcho: this.properties.noEcho + Default: this.props.default, + AllowedPattern: this.props.allowedPattern, + AllowedValues: this.props.allowedValues, + ConstraintDescription: this.props.constraintDescription, + Description: this.props.description, + MaxLength: this.props.maxLength, + MaxValue: this.props.maxValue, + MinLength: this.props.minLength, + MinValue: this.props.minValue, + NoEcho: this.props.noEcho } } }; diff --git a/packages/@aws-cdk/cdk/lib/pseudo.ts b/packages/@aws-cdk/cdk/lib/cfn-pseudo.ts similarity index 100% rename from packages/@aws-cdk/cdk/lib/pseudo.ts rename to packages/@aws-cdk/cdk/lib/cfn-pseudo.ts diff --git a/packages/@aws-cdk/cdk/lib/resource-policy.ts b/packages/@aws-cdk/cdk/lib/cfn-resource-policy.ts similarity index 94% rename from packages/@aws-cdk/cdk/lib/resource-policy.ts rename to packages/@aws-cdk/cdk/lib/cfn-resource-policy.ts index a3ff6b9d84691..c7f65d39ef881 100644 --- a/packages/@aws-cdk/cdk/lib/resource-policy.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-resource-policy.ts @@ -14,25 +14,25 @@ * signal to the instance after the applications are installed and configured. For a detailed example, see Deploying Applications * on Amazon EC2 with AWS CloudFormation. */ -export interface CreationPolicy { +export interface CfnCreationPolicy { /** * For an Auto Scaling group replacement update, specifies how many instances must signal success for the * update to succeed. */ - readonly autoScalingCreationPolicy?: AutoScalingCreationPolicy; + readonly autoScalingCreationPolicy?: CfnResourceAutoScalingCreationPolicy; /** * When AWS CloudFormation creates the associated resource, configures the number of required success signals and * the length of time that AWS CloudFormation waits for those signals. */ - readonly resourceSignal?: ResourceSignal; + readonly resourceSignal?: CfnResourceSignal; } /** * For an Auto Scaling group replacement update, specifies how many instances must signal success for the * update to succeed. */ -export interface AutoScalingCreationPolicy { +export interface CfnResourceAutoScalingCreationPolicy { /** * Specifies the percentage of instances in an Auto Scaling replacement update that must signal success for the * update to succeed. You can specify a value from 0 to 100. AWS CloudFormation rounds to the nearest tenth of a percent. @@ -47,7 +47,7 @@ export interface AutoScalingCreationPolicy { * When AWS CloudFormation creates the associated resource, configures the number of required success signals and * the length of time that AWS CloudFormation waits for those signals. */ -export interface ResourceSignal { +export interface CfnResourceSignal { /** * The number of success signals AWS CloudFormation must receive before it sets the resource status as CREATE_COMPLETE. @@ -70,7 +70,7 @@ export interface ResourceSignal { * attribute, AWS CloudFormation deletes the resource by default. Note that this capability also applies to update operations * that lead to resources being removed. */ -export enum DeletionPolicy { +export enum CfnDeletionPolicy { /** * AWS CloudFormation deletes the resource and all its content if applicable during stack deletion. You can add this * deletion policy to any resource type. By default, if you don't specify a DeletionPolicy, AWS CloudFormation deletes @@ -101,34 +101,34 @@ export enum DeletionPolicy { * resource. AWS CloudFormation invokes one of three update policies depending on the type of change you make or whether a * scheduled action is associated with the Auto Scaling group. */ -export interface UpdatePolicy { +export interface CfnUpdatePolicy { /** * Specifies whether an Auto Scaling group and the instances it contains are replaced during an update. During replacement, * AWS CloudFormation retains the old group until it finishes creating the new one. If the update fails, AWS CloudFormation * can roll back to the old Auto Scaling group and delete the new Auto Scaling group. */ - readonly autoScalingReplacingUpdate?: AutoScalingReplacingUpdate; + readonly autoScalingReplacingUpdate?: CfnAutoScalingReplacingUpdate; /** * To specify how AWS CloudFormation handles rolling updates for an Auto Scaling group, use the AutoScalingRollingUpdate * policy. Rolling updates enable you to specify whether AWS CloudFormation updates instances that are in an Auto Scaling * group in batches or all at once. */ - readonly autoScalingRollingUpdate?: AutoScalingRollingUpdate; + readonly autoScalingRollingUpdate?: CfnAutoScalingRollingUpdate; /** * To specify how AWS CloudFormation handles updates for the MinSize, MaxSize, and DesiredCapacity properties when * the AWS::AutoScaling::AutoScalingGroup resource has an associated scheduled action, use the AutoScalingScheduledAction * policy. */ - readonly autoScalingScheduledAction?: AutoScalingScheduledAction; + readonly autoScalingScheduledAction?: CfnAutoScalingScheduledAction; /** * To perform an AWS CodeDeploy deployment when the version changes on an AWS::Lambda::Alias resource, * use the CodeDeployLambdaAliasUpdate update policy. */ - readonly codeDeployLambdaAliasUpdate?: CodeDeployLambdaAliasUpdate; + readonly codeDeployLambdaAliasUpdate?: CfnCodeDeployLambdaAliasUpdate; /** * To modify a replication group's shards by adding or removing shards, rather than replacing the entire @@ -143,7 +143,7 @@ export interface UpdatePolicy { * policy. Rolling updates enable you to specify whether AWS CloudFormation updates instances that are in an Auto Scaling * group in batches or all at once. */ -export interface AutoScalingRollingUpdate { +export interface CfnAutoScalingRollingUpdate { /** * Specifies the maximum number of instances that AWS CloudFormation updates. @@ -219,7 +219,7 @@ export interface AutoScalingRollingUpdate { * (specified in the CreationPolicy policy), the replacement update fails and AWS CloudFormation rolls back to the old * Auto Scaling group. */ -export interface AutoScalingReplacingUpdate { +export interface CfnAutoScalingReplacingUpdate { readonly willReplace?: boolean; } @@ -233,7 +233,7 @@ export interface AutoScalingReplacingUpdate { * effect, use the AutoScalingScheduledAction update policy to prevent AWS CloudFormation from changing the MinSize, MaxSize, * or DesiredCapacity properties unless you have modified these values in your template.\ */ -export interface AutoScalingScheduledAction { +export interface CfnAutoScalingScheduledAction { /* * Specifies whether AWS CloudFormation ignores differences in group size properties between your current Auto Scaling * group and the Auto Scaling group described in the AWS::AutoScaling::AutoScalingGroup resource of your template during @@ -247,7 +247,7 @@ export interface AutoScalingScheduledAction { * To perform an AWS CodeDeploy deployment when the version changes on an AWS::Lambda::Alias resource, * use the CodeDeployLambdaAliasUpdate update policy. */ -export interface CodeDeployLambdaAliasUpdate { +export interface CfnCodeDeployLambdaAliasUpdate { /** * The name of the AWS CodeDeploy application. */ diff --git a/packages/@aws-cdk/cdk/lib/cfn-resource.ts b/packages/@aws-cdk/cdk/lib/cfn-resource.ts index 3fff5bc52d9ad..306fb6c847238 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-resource.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-resource.ts @@ -3,48 +3,32 @@ import { CfnCondition } from './cfn-condition'; // import required to be here, otherwise causes a cycle when running the generated JavaScript // tslint:disable-next-line:ordered-imports import { CfnRefElement } from './cfn-element'; +import { CfnCreationPolicy, CfnDeletionPolicy, CfnUpdatePolicy } from './cfn-resource-policy'; import { Construct, IConstruct } from './construct'; import { CfnReference } from './private/cfn-reference'; import { RemovalPolicy, RemovalPolicyOptions } from './removal-policy'; import { IResolvable } from './resolvable'; -import { CreationPolicy, DeletionPolicy, UpdatePolicy } from './resource-policy'; import { TagManager } from './tag-manager'; import { capitalizePropertyNames, ignoreEmpty, PostResolveToken } from './util'; export interface CfnResourceProps { /** - * CloudFormation resource type. + * CloudFormation resource type (e.g. `AWS::S3::Bucket`). */ readonly type: string; /** - * CloudFormation properties. + * Resource properties. * * @default - No resource properties. */ - readonly properties?: any; + readonly properties?: { [name: string]: any }; } /** * Represents a CloudFormation resource. */ export class CfnResource extends CfnRefElement { - /** - * A decoration used to create a CloudFormation attribute property. - * @param customName Custom name for the attribute (default is the name of the property) - * NOTE: we return "any" here to satistfy jsii, which doesn't support lambdas. - */ - public static attribute(customName?: string): any { - return (prototype: any, key: string) => { - const name = customName || key; - Object.defineProperty(prototype, key, { - get() { - return (this as any).getAtt(name); - } - }); - }; - } - /** * Check whether the given construct is a CfnResource */ @@ -116,11 +100,11 @@ export class CfnResource extends CfnRefElement { switch (policy) { case RemovalPolicy.Destroy: - deletionPolicy = DeletionPolicy.Delete; + deletionPolicy = CfnDeletionPolicy.Delete; break; case RemovalPolicy.Retain: - deletionPolicy = DeletionPolicy.Retain; + deletionPolicy = CfnDeletionPolicy.Retain; break; default: @@ -315,7 +299,7 @@ export interface IResourceOptions { * resource, you can use the cfn-signal helper script or SignalResource API. AWS CloudFormation publishes valid signals * to the stack events so that you track the number of signals sent. */ - creationPolicy?: CreationPolicy; + creationPolicy?: CfnCreationPolicy; /** * With the DeletionPolicy attribute you can preserve or (in some cases) backup a resource when its stack is deleted. @@ -323,20 +307,20 @@ export interface IResourceOptions { * attribute, AWS CloudFormation deletes the resource by default. Note that this capability also applies to update operations * that lead to resources being removed. */ - deletionPolicy?: DeletionPolicy; + deletionPolicy?: CfnDeletionPolicy; /** * Use the UpdatePolicy attribute to specify how AWS CloudFormation handles updates to the AWS::AutoScaling::AutoScalingGroup * resource. AWS CloudFormation invokes one of three update policies depending on the type of change you make or whether a * scheduled action is associated with the Auto Scaling group. */ - updatePolicy?: UpdatePolicy; + updatePolicy?: CfnUpdatePolicy; /** * Use the UpdateReplacePolicy attribute to retain or (in some cases) backup the existing physical instance of a resource * when it is replaced during a stack update operation. */ - updateReplacePolicy?: DeletionPolicy; + updateReplacePolicy?: CfnDeletionPolicy; /** * Metadata associated with the CloudFormation resource. This is not the same as the construct metadata which can be added @@ -349,7 +333,7 @@ export interface IResourceOptions { * Merges `source` into `target`, overriding any existing values. * `null`s will cause a value to be deleted. */ -export function deepMerge(target: any, ...sources: any[]) { +function deepMerge(target: any, ...sources: any[]) { for (const source of sources) { if (typeof(source) !== 'object' || typeof(target) !== 'object') { throw new Error(`Invalid usage. Both source (${JSON.stringify(source)}) and target (${JSON.stringify(target)}) must be objects`); diff --git a/packages/@aws-cdk/cdk/lib/cfn-rule.ts b/packages/@aws-cdk/cdk/lib/cfn-rule.ts index bf41309eb0bbc..9ce9417eff7e9 100644 --- a/packages/@aws-cdk/cdk/lib/cfn-rule.ts +++ b/packages/@aws-cdk/cdk/lib/cfn-rule.ts @@ -38,7 +38,7 @@ export interface CfnRuleProps { * * @default - No assertions for the rule. */ - readonly assertions?: RuleAssertion[]; + readonly assertions?: CfnRuleAssertion[]; } /** @@ -57,16 +57,8 @@ export interface CfnRuleProps { * @link https://docs.aws.amazon.com/servicecatalog/latest/adminguide/reference-template_constraint_rules.html */ export class CfnRule extends CfnRefElement { - /** - * If the rule condition evaluates to false, the rule doesn't take effect. - * If the function in the rule condition evaluates to true, expressions in each assert are evaluated and applied. - */ - public ruleCondition?: ICfnConditionExpression; - - /** - * Assertions which define the rule. - */ - public assertions?: RuleAssertion[]; + private ruleCondition?: ICfnConditionExpression; + private assertions?: CfnRuleAssertion[]; /** * Creates and adds a rule. @@ -114,7 +106,7 @@ export class CfnRule extends CfnRefElement { /** * A rule assertion. */ -export interface RuleAssertion { +export interface CfnRuleAssertion { /** * The assertion. */ diff --git a/packages/@aws-cdk/cdk/lib/tag.ts b/packages/@aws-cdk/cdk/lib/cfn-tag.ts similarity index 100% rename from packages/@aws-cdk/cdk/lib/tag.ts rename to packages/@aws-cdk/cdk/lib/cfn-tag.ts diff --git a/packages/@aws-cdk/cdk/lib/construct.ts b/packages/@aws-cdk/cdk/lib/construct.ts index 3a94d1eabe3d3..68c744c357966 100644 --- a/packages/@aws-cdk/cdk/lib/construct.ts +++ b/packages/@aws-cdk/cdk/lib/construct.ts @@ -1,10 +1,10 @@ import cxapi = require('@aws-cdk/cx-api'); import { IAspect } from './aspect'; import { DependableTrait, IDependable } from './dependency'; +import { makeUniqueId } from './private/uniqueid'; import { IResolvable } from './resolvable'; import { captureStackTrace } from './stack-trace'; import { Token } from './token'; -import { makeUniqueId } from './uniqueid'; const CONSTRUCT_SYMBOL = Symbol.for('@aws-cdk/cdk.Construct'); @@ -13,7 +13,7 @@ const CONSTRUCT_SYMBOL = Symbol.for('@aws-cdk/cdk.Construct'); */ export interface IConstruct extends IDependable { /** - * The construct node in the scope tree. + * The construct node in the tree. */ readonly node: ConstructNode; } @@ -198,7 +198,7 @@ export class ConstructNode { /** * Return a descendant by path * - * Throws an exception if the descendant is not found. + * Throws an error if the descendant is not found. * * Note that if the original ID of the construct you are looking for contained * a '/', then it would have been replaced by '--'. @@ -215,7 +215,7 @@ export class ConstructNode { } /** - * Returns the child construct that has the id "Default" or "Resource". + * Returns the child construct that has the id `Default` or `Resource"` * @throws if there is more than one child * @returns a construct or undefined if there is no default child */ diff --git a/packages/@aws-cdk/cdk/lib/index.ts b/packages/@aws-cdk/cdk/lib/index.ts index a624d4cdf9892..41aef513150de 100644 --- a/packages/@aws-cdk/cdk/lib/index.ts +++ b/packages/@aws-cdk/cdk/lib/index.ts @@ -11,19 +11,19 @@ export * from './string-fragments'; export * from './reference'; export * from './cfn-condition'; -export * from './fn'; -export * from './include'; +export * from './cfn-fn'; +export * from './cfn-include'; export * from './cfn-mapping'; export * from './cfn-output'; export * from './cfn-parameter'; -export * from './pseudo'; +export * from './cfn-pseudo'; export * from './cfn-resource'; -export * from './resource-policy'; +export * from './cfn-resource-policy'; export * from './cfn-rule'; export * from './stack'; export * from './cfn-element'; export * from './cfn-dynamic-reference'; -export * from './tag'; +export * from './cfn-tag'; export * from './removal-policy'; export * from './arn'; export * from './stack-trace'; diff --git a/packages/@aws-cdk/cdk/lib/lazy.ts b/packages/@aws-cdk/cdk/lib/lazy.ts index 6c6d8ee35d99f..9c7d3d0faa0f9 100644 --- a/packages/@aws-cdk/cdk/lib/lazy.ts +++ b/packages/@aws-cdk/cdk/lib/lazy.ts @@ -5,7 +5,7 @@ import { Token } from "./token"; /** * Interface for lazy string producers */ -export interface IStringValue { +export interface IStringProducer { /** * Produce the string value */ @@ -99,7 +99,7 @@ export interface LazyAnyValueOptions { * will only be calculated later, during synthesis. */ export class Lazy { - public static stringValue(producer: IStringValue, options: LazyStringValueOptions = {}) { + public static stringValue(producer: IStringProducer, options: LazyStringValueOptions = {}) { return Token.asString(new LazyString(producer), options); } @@ -143,7 +143,7 @@ abstract class LazyBase implements IResolvable { } class LazyString extends LazyBase { - constructor(private readonly producer: IStringValue) { + constructor(private readonly producer: IStringProducer) { super(); } diff --git a/packages/@aws-cdk/cdk/lib/physical-name.ts b/packages/@aws-cdk/cdk/lib/physical-name.ts index b1a8b0d88fe98..cf814901292ab 100644 --- a/packages/@aws-cdk/cdk/lib/physical-name.ts +++ b/packages/@aws-cdk/cdk/lib/physical-name.ts @@ -1,5 +1,5 @@ import { Lazy } from "./lazy"; -import { generatePhysicalName } from "./physical-name-generator"; +import { generatePhysicalName } from "./private/physical-name-generator"; import { IResource } from './resource'; /** @@ -62,7 +62,7 @@ export abstract class PhysicalName { * can be `undefined`, if a physical name was not provided, * or an opaque Token, if a generated name should be assigned lazily at synthesis time. */ - public abstract get value(): string | undefined; + public abstract get value(): string; /** * A callback method called if the resource this physical name @@ -96,20 +96,18 @@ class LateBoundPhysicalName extends PhysicalName { * either a Token string if crossEnvironment is true, * or undefined otherwise. */ - public readonly value: string | undefined; + public readonly value: string; + private name?: string; - constructor(options: AutoPhysicalNameOptions) { + constructor(private readonly options: AutoPhysicalNameOptions) { super(); - - this.value = options.crossEnvironment - ? Lazy.stringValue({ produce: () => this.name }) - : undefined; + this.value = Lazy.stringValue({ produce: () => this.name }); } /** @internal */ public _resolveCrossEnvironment(resource: IResource): void { - if (!this.value) { + if (!this.options.crossEnvironment) { // error out - a deploy-time name cannot be used across environments throw new Error(`Cannot use resource '${resource.node.path}' in a cross-environment fashion, ` + "as it doesn't have a physical name set. Use PhysicalName.auto({ crossEnvironment: true }) to enable cross env name allocation"); diff --git a/packages/@aws-cdk/cdk/lib/private/cfn-reference.ts b/packages/@aws-cdk/cdk/lib/private/cfn-reference.ts index 538d8cf987e43..24aca74187b74 100644 --- a/packages/@aws-cdk/cdk/lib/private/cfn-reference.ts +++ b/packages/@aws-cdk/cdk/lib/private/cfn-reference.ts @@ -1,4 +1,5 @@ import { Reference } from "../reference"; +import { makeUniqueId } from './uniqueid'; const CFN_REFERENCE_SYMBOL = Symbol.for('@aws-cdk/cdk.CfnReference'); @@ -122,7 +123,7 @@ export class CfnReference extends Reference { if (this.producingStack && this.producingStack !== consumingStack && !this.replacementTokens.has(consumingStack)) { // We're trying to resolve a cross-stack reference consumingStack.addDependency(this.producingStack, `${consumingConstruct.node.path} -> ${this.target.node.path}.${this.originalDisplayName}`); - this.replacementTokens.set(consumingStack, this.exportValue(this, consumingStack)); + this.replacementTokens.set(consumingStack, this.exportValue(consumingStack)); } } @@ -140,7 +141,7 @@ export class CfnReference extends Reference { * * Works by mutating the producing stack in-place. */ - private exportValue(tokenValue: Token, consumingStack: Stack): IResolvable { + private exportValue(consumingStack: Stack): IResolvable { const producingStack = this.producingStack!; if (producingStack.environment !== consumingStack.environment) { @@ -159,16 +160,25 @@ export class CfnReference extends Reference { } // Ensure a singleton CfnOutput for this value - const resolved = producingStack.resolve(tokenValue); + const resolved = producingStack.resolve(this); const id = 'Output' + JSON.stringify(resolved); + const exportName = this.generateExportName(stackExports, id); let output = stackExports.node.tryFindChild(id) as CfnOutput; if (!output) { - output = new CfnOutput(stackExports, id, { value: tokenValue }); + output = new CfnOutput(stackExports, id, { value: Token.asString(this), exportName }); } // We want to return an actual FnImportValue Token here, but Fn.importValue() returns a 'string', // so construct one in-place. - return new Intrinsic({ 'Fn::ImportValue': output.obtainExportName() }); + return new Intrinsic({ 'Fn::ImportValue': exportName }); + } + + private generateExportName(stackExports: Construct, id: string) { + const stack = Stack.of(stackExports); + const components = [...stackExports.node.scopes.slice(2).map(c => c.node.id), id]; + const prefix = stack.stackName ? stack.stackName + ':' : ''; + const exportName = prefix + makeUniqueId(components); + return exportName; } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation-lang.ts b/packages/@aws-cdk/cdk/lib/private/cloudformation-lang.ts similarity index 95% rename from packages/@aws-cdk/cdk/lib/cloudformation-lang.ts rename to packages/@aws-cdk/cdk/lib/private/cloudformation-lang.ts index b373959aed6d0..b290f4c3b0142 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation-lang.ts +++ b/packages/@aws-cdk/cdk/lib/private/cloudformation-lang.ts @@ -1,9 +1,9 @@ -import { Lazy } from "./lazy"; -import { Intrinsic } from "./private/intrinsic"; -import { resolve } from "./private/resolve"; -import { DefaultTokenResolver, IFragmentConcatenator, IPostProcessor, IResolvable, IResolveContext } from "./resolvable"; -import { TokenizedStringFragments } from "./string-fragments"; -import { Token } from "./token"; +import { Lazy } from "../lazy"; +import { DefaultTokenResolver, IFragmentConcatenator, IPostProcessor, IResolvable, IResolveContext } from "../resolvable"; +import { TokenizedStringFragments } from "../string-fragments"; +import { Token } from "../token"; +import { Intrinsic } from "./intrinsic"; +import { resolve } from "./resolve"; /** * Routines that know how to do operations at the CloudFormation document language level diff --git a/packages/@aws-cdk/cdk/lib/private/cross-environment-token.ts b/packages/@aws-cdk/cdk/lib/private/cross-environment-token.ts index 9c64511f43e72..bc3c8378218a1 100644 --- a/packages/@aws-cdk/cdk/lib/private/cross-environment-token.ts +++ b/packages/@aws-cdk/cdk/lib/private/cross-environment-token.ts @@ -1,6 +1,6 @@ import { ArnComponents } from '../arn'; import { IResolvable, IResolveContext } from '../resolvable'; -import { IResource } from '../resource'; +import { Resource } from '../resource'; import { Stack } from '../stack'; import { captureStackTrace } from '../stack-trace'; @@ -21,7 +21,7 @@ export abstract class CrossEnvironmentToken implements IResolvable { * @param displayName a short name to be used in Token display */ protected constructor(private readonly regularValue: string, private readonly crossEnvironmentValue: any, - private readonly resource: IResource) { + private readonly resource: Resource) { this.resource = resource; this.creationStack = captureStackTrace(); } @@ -31,7 +31,7 @@ export abstract class CrossEnvironmentToken implements IResolvable { const owningStack = Stack.of(this.resource); if (consumingStack.environment !== owningStack.environment) { - this.resource.physicalName._resolveCrossEnvironment(this.resource); + this.resource._enableCrossEnvironment(); return this.crossEnvironmentValue; } else { return this.regularValue; @@ -40,13 +40,13 @@ export abstract class CrossEnvironmentToken implements IResolvable { } export class CrossEnvironmentPhysicalArnToken extends CrossEnvironmentToken { - constructor(regularValue: string, arnComponents: ArnComponents, resource: IResource) { + constructor(regularValue: string, arnComponents: ArnComponents, resource: Resource) { super(regularValue, Stack.of(resource).formatArn(arnComponents), resource); } } export class CrossEnvironmentPhysicalNameToken extends CrossEnvironmentToken { - constructor(regularValue: string, resource: IResource) { - super(regularValue, resource.physicalName.value, resource); + constructor(regularValue: string, resource: Resource) { + super(regularValue, resource.physicalName, resource); } } diff --git a/packages/@aws-cdk/cdk/lib/logical-id.ts b/packages/@aws-cdk/cdk/lib/private/logical-id.ts similarity index 100% rename from packages/@aws-cdk/cdk/lib/logical-id.ts rename to packages/@aws-cdk/cdk/lib/private/logical-id.ts diff --git a/packages/@aws-cdk/cdk/lib/node-version.ts b/packages/@aws-cdk/cdk/lib/private/node-version.ts similarity index 100% rename from packages/@aws-cdk/cdk/lib/node-version.ts rename to packages/@aws-cdk/cdk/lib/private/node-version.ts diff --git a/packages/@aws-cdk/cdk/lib/physical-name-generator.ts b/packages/@aws-cdk/cdk/lib/private/physical-name-generator.ts similarity index 93% rename from packages/@aws-cdk/cdk/lib/physical-name-generator.ts rename to packages/@aws-cdk/cdk/lib/private/physical-name-generator.ts index c57e9abc6a8d4..21aa333ff7f36 100644 --- a/packages/@aws-cdk/cdk/lib/physical-name-generator.ts +++ b/packages/@aws-cdk/cdk/lib/private/physical-name-generator.ts @@ -1,7 +1,7 @@ import crypto = require('crypto'); -import { IResource } from './resource'; -import { Stack } from './stack'; -import { Token } from './token'; +import { IResource } from '../resource'; +import { Stack } from '../stack'; +import { Token } from '../token'; export function generatePhysicalName(resource: IResource): string { const stack = Stack.of(resource); diff --git a/packages/@aws-cdk/cdk/lib/runtime-info.ts b/packages/@aws-cdk/cdk/lib/private/runtime-info.ts similarity index 100% rename from packages/@aws-cdk/cdk/lib/runtime-info.ts rename to packages/@aws-cdk/cdk/lib/private/runtime-info.ts diff --git a/packages/@aws-cdk/cdk/lib/uniqueid.ts b/packages/@aws-cdk/cdk/lib/private/uniqueid.ts similarity index 96% rename from packages/@aws-cdk/cdk/lib/uniqueid.ts rename to packages/@aws-cdk/cdk/lib/private/uniqueid.ts index d7d3f7a48b027..d27ff454beaf4 100644 --- a/packages/@aws-cdk/cdk/lib/uniqueid.ts +++ b/packages/@aws-cdk/cdk/lib/private/uniqueid.ts @@ -1,5 +1,6 @@ // tslint:disable-next-line:no-var-requires import crypto = require('crypto'); +import { unresolved } from './encoding'; /** * Resources with this ID are hidden from humans @@ -36,7 +37,7 @@ export function makeUniqueId(components: string[]) { } // Lazy require in order to break a module dependency cycle - const unresolvedTokens = components.filter(c => require('./private/encoding').unresolved(c)); + const unresolvedTokens = components.filter(c => unresolved(c)); if (unresolvedTokens.length > 0) { throw new Error(`ID components may not include unresolved tokens: ${unresolvedTokens.join(',')}`); } diff --git a/packages/@aws-cdk/cdk/lib/removal-policy.ts b/packages/@aws-cdk/cdk/lib/removal-policy.ts index 5e32c42749207..eae0e6d2a938e 100644 --- a/packages/@aws-cdk/cdk/lib/removal-policy.ts +++ b/packages/@aws-cdk/cdk/lib/removal-policy.ts @@ -22,6 +22,7 @@ export interface RemovalPolicyOptions { /** * Apply the same deletion policy to the resource's "UpdateReplacePolicy" + * @default false */ readonly applyToUpdateReplacePolicy?: boolean; } diff --git a/packages/@aws-cdk/cdk/lib/resource-identifiers.ts b/packages/@aws-cdk/cdk/lib/resource-identifiers.ts index 022131e762da6..6ca04b0b9dae3 100644 --- a/packages/@aws-cdk/cdk/lib/resource-identifiers.ts +++ b/packages/@aws-cdk/cdk/lib/resource-identifiers.ts @@ -1,6 +1,6 @@ import { ArnComponents } from './arn'; import { CrossEnvironmentPhysicalArnToken, CrossEnvironmentPhysicalNameToken } from './private/cross-environment-token'; -import { IResource } from './resource'; +import { Resource } from './resource'; import { Token } from './token'; /** @@ -26,12 +26,14 @@ export interface ResourceIdentifiersProps { /** * The identifiers (name and ARN) for a given L2. * These should be only used inside the Construct Library implementation. + * + * @experimental */ export class ResourceIdentifiers { public readonly arn: string; public readonly name: string; - constructor(resource: IResource, props: ResourceIdentifiersProps) { + constructor(resource: Resource, props: ResourceIdentifiersProps) { this.arn = Token.asString(new CrossEnvironmentPhysicalArnToken( props.arn, props.arnComponents, diff --git a/packages/@aws-cdk/cdk/lib/resource.ts b/packages/@aws-cdk/cdk/lib/resource.ts index 32d69f9a8b211..f822b39935869 100644 --- a/packages/@aws-cdk/cdk/lib/resource.ts +++ b/packages/@aws-cdk/cdk/lib/resource.ts @@ -6,9 +6,14 @@ import { PhysicalName } from './physical-name'; */ export interface IResource extends IConstruct { /** - * The physical (that is, visible in the AWS Console) name of this resource. + * Returns the physical name, as a String. + * + * If the user assigned a physical name to the resource, it will be returned, + * unchanged; can be `undefined`, if a physical name was not provided, or an + * opaque Token, if a generated name should be assigned lazily at synthesis + * time. */ - readonly physicalName: PhysicalName; + readonly physicalName: string; } /** @@ -17,8 +22,8 @@ export interface IResource extends IConstruct { export interface ResourceProps { /** * The physical (that is, visible in the AWS Console) name of this resource. - * By default, the name will be automatically generated by CloudFormation, - * at deploy time. + * By default, the name will be automatically generated by CloudFormation, at + * deploy time. * * @default PhysicalName.auto() */ @@ -29,11 +34,22 @@ export interface ResourceProps { * A construct which represents an AWS resource. */ export abstract class Resource extends Construct implements IResource { - public readonly physicalName: PhysicalName; + private readonly _physicalName: PhysicalName; constructor(scope: Construct, id: string, props: ResourceProps = {}) { super(scope, id); - this.physicalName = props.physicalName || PhysicalName.auto(); + this._physicalName = props.physicalName || PhysicalName.auto(); + } + + public get physicalName(): string { + return this._physicalName.value; + } + + /** + * @internal + */ + public _enableCrossEnvironment(): void { + this._physicalName._resolveCrossEnvironment(this); } } diff --git a/packages/@aws-cdk/cdk/lib/runtime.ts b/packages/@aws-cdk/cdk/lib/runtime.ts index 78694558a6755..ff8d3673a0e44 100644 --- a/packages/@aws-cdk/cdk/lib/runtime.ts +++ b/packages/@aws-cdk/cdk/lib/runtime.ts @@ -57,7 +57,7 @@ export function cfnTagToCloudFormation(x: any): any { export function listMapper(elementMapper: Mapper): Mapper { return (x: any) => { - if (!canInspect(x)) { return x; } + if (!canInspect(x)) { return x; } return x.map(elementMapper); }; } @@ -250,7 +250,7 @@ export function validateObject(x: any): ValidationResult { } export function validateCfnTag(x: any): ValidationResult { - if (!canInspect(x)) { return VALIDATION_SUCCESS; } + if (!canInspect(x)) { return VALIDATION_SUCCESS; } if (x.key == null || x.value == null) { return new ValidationResult(`${JSON.stringify(x)} should have a 'key' and a 'value' property`); @@ -264,7 +264,7 @@ export function validateCfnTag(x: any): ValidationResult { */ export function listValidator(elementValidator: Validator): Validator { return (x: any) => { - if (!canInspect(x)) { return VALIDATION_SUCCESS; } + if (!canInspect(x)) { return VALIDATION_SUCCESS; } if (!x.forEach) { return new ValidationResult(`${JSON.stringify(x)} should be a list`); diff --git a/packages/@aws-cdk/cdk/lib/stack.ts b/packages/@aws-cdk/cdk/lib/stack.ts index 3672ddb3b0a4d..bb48ff67d36f0 100644 --- a/packages/@aws-cdk/cdk/lib/stack.ts +++ b/packages/@aws-cdk/cdk/lib/stack.ts @@ -2,13 +2,13 @@ import cxapi = require('@aws-cdk/cx-api'); import { EnvironmentUtils } from '@aws-cdk/cx-api'; import fs = require('fs'); import path = require('path'); -import { CLOUDFORMATION_TOKEN_RESOLVER, CloudFormationLang } from './cloudformation-lang'; import { Construct, ConstructNode, IConstruct, ISynthesisSession } from './construct'; import { ContextProvider } from './context-provider'; import { Environment } from './environment'; -import { LogicalIDs } from './logical-id'; +import { CLOUDFORMATION_TOKEN_RESOLVER, CloudFormationLang } from './private/cloudformation-lang'; +import { LogicalIDs } from './private/logical-id'; import { resolve } from './private/resolve'; -import { makeUniqueId } from './uniqueid'; +import { makeUniqueId } from './private/uniqueid'; const STACK_SYMBOL = Symbol.for('@aws-cdk/cdk.Stack'); const VALID_STACK_NAME_REGEX = /^[A-Za-z][A-Za-z0-9-]*$/; @@ -335,43 +335,6 @@ export class Stack extends Construct implements ITaggable { return Arn.format(components, this); } - /** - * Returnst the list of AZs that are availability in the AWS environment - * (account/region) associated with this stack. - * - * If the stack is environment-agnostic (either account and/or region are - * tokens), this property will return an array with 2 tokens that will resolve - * at deploy-time to the first two availability zones returned from CloudFormation's - * `Fn::GetAZs` intrinsic function. - * - * If they are not available in the context, returns a set of dummy values and - * reports them as missing, and let the CLI resolve them by calling EC2 - * `DescribeAvailabilityZones` on the target environment. - */ - public get availabilityZones() { - // if account/region are tokens, we can't obtain AZs through the context - // provider, so we fallback to use Fn::GetAZs. the current lowest common - // denominator is 2 AZs across all AWS regions. - const agnostic = Token.isUnresolved(this.account) || Token.isUnresolved(this.region); - if (agnostic) { - return this.node.tryGetContext(cxapi.AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY) || [ - Fn.select(0, Fn.getAZs()), - Fn.select(1, Fn.getAZs()) - ]; - } - - const value = ContextProvider.getValue(this, { - provider: cxapi.AVAILABILITY_ZONE_PROVIDER, - dummyValue: ['dummy1a', 'dummy1b', 'dummy1c'], - }); - - if (!Array.isArray(value)) { - throw new Error(`Provider ${cxapi.AVAILABILITY_ZONE_PROVIDER} expects a list`); - } - - return value; - } - /** * Given an ARN, parses it and returns components. * @@ -414,6 +377,43 @@ export class Stack extends Construct implements ITaggable { return Arn.parse(arn, sepIfToken, hasName); } + /** + * Returnst the list of AZs that are availability in the AWS environment + * (account/region) associated with this stack. + * + * If the stack is environment-agnostic (either account and/or region are + * tokens), this property will return an array with 2 tokens that will resolve + * at deploy-time to the first two availability zones returned from CloudFormation's + * `Fn::GetAZs` intrinsic function. + * + * If they are not available in the context, returns a set of dummy values and + * reports them as missing, and let the CLI resolve them by calling EC2 + * `DescribeAvailabilityZones` on the target environment. + */ + public get availabilityZones() { + // if account/region are tokens, we can't obtain AZs through the context + // provider, so we fallback to use Fn::GetAZs. the current lowest common + // denominator is 2 AZs across all AWS regions. + const agnostic = Token.isUnresolved(this.account) || Token.isUnresolved(this.region); + if (agnostic) { + return this.node.tryGetContext(cxapi.AVAILABILITY_ZONE_FALLBACK_CONTEXT_KEY) || [ + Fn.select(0, Fn.getAZs()), + Fn.select(1, Fn.getAZs()) + ]; + } + + const value = ContextProvider.getValue(this, { + provider: cxapi.AVAILABILITY_ZONE_PROVIDER, + dummyValue: ['dummy1a', 'dummy1b', 'dummy1c'], + }); + + if (!Array.isArray(value)) { + throw new Error(`Provider ${cxapi.AVAILABILITY_ZONE_PROVIDER} expects a list`); + } + + return value; + } + /** * Returns the naming scheme used to allocate logical IDs. By default, uses * the `HashedAddressingScheme` but this method can be overridden to customize @@ -724,10 +724,10 @@ function cfnElements(node: IConstruct, into: CfnElement[] = []): CfnElement[] { // These imports have to be at the end to prevent circular imports import { Arn, ArnComponents } from './arn'; import { CfnElement } from './cfn-element'; +import { Fn } from './cfn-fn'; +import { Aws, ScopedAws } from './cfn-pseudo'; import { CfnResource, TagType } from './cfn-resource'; -import { Fn } from './fn'; import { CfnReference } from './private/cfn-reference'; -import { Aws, ScopedAws } from './pseudo'; import { ITaggable, TagManager } from './tag-manager'; import { Token } from './token'; diff --git a/packages/@aws-cdk/cdk/lib/tag-aspect.ts b/packages/@aws-cdk/cdk/lib/tag-aspect.ts index d2f50ca7cd1f5..b21a8806c571e 100644 --- a/packages/@aws-cdk/cdk/lib/tag-aspect.ts +++ b/packages/@aws-cdk/cdk/lib/tag-aspect.ts @@ -57,7 +57,7 @@ export interface TagProps { /** * The common functionality for Tag and Remove Tag Aspects */ -export abstract class TagBase implements IAspect { +abstract class TagBase implements IAspect { /** * The string key for the tag diff --git a/packages/@aws-cdk/cdk/lib/tag-manager.ts b/packages/@aws-cdk/cdk/lib/tag-manager.ts index ed6a2e6504136..bfbe339aca96f 100644 --- a/packages/@aws-cdk/cdk/lib/tag-manager.ts +++ b/packages/@aws-cdk/cdk/lib/tag-manager.ts @@ -1,5 +1,5 @@ import { TagType } from './cfn-resource'; -import { CfnTag } from './tag'; +import { CfnTag } from './cfn-tag'; interface Tag { key: string; diff --git a/packages/@aws-cdk/cdk/package.json b/packages/@aws-cdk/cdk/package.json index afd66bd76b80b..947a8339dcdb1 100644 --- a/packages/@aws-cdk/cdk/package.json +++ b/packages/@aws-cdk/cdk/package.json @@ -34,13 +34,10 @@ "awslint": { "exclude": [ "construct-ctor:@aws-cdk/cdk.App.", - "construct-ctor:@aws-cdk/cdk.Root.", - "construct-ctor:@aws-cdk/cdk.Stack..params*", - "props-no-any:@aws-cdk/cdk.CfnOutputProps.value", + "props-no-cfn-types:@aws-cdk/cdk.CfnOutputProps.condition", "props-no-any:@aws-cdk/cdk.CfnParameterProps.default", - "props-no-any:@aws-cdk/cdk.CfnResourceProps.properties", - "props-no-cfn-types:@aws-cdk/cdk.CfnOutputProps*", - "props-no-cfn-types:@aws-cdk/cdk.StringListCfnOutputProps*" + "props-no-cfn-types:@aws-cdk/cdk.CfnRuleProps.assertions", + "construct-ctor:@aws-cdk/cdk.Stack..params[1]" ] }, "scripts": { @@ -90,4 +87,4 @@ "node": ">= 8.10.0" }, "stability": "experimental" -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/cdk/test/evaluate-cfn.ts b/packages/@aws-cdk/cdk/test/evaluate-cfn.ts index 0ae333cef60bb..1ce93ae985180 100644 --- a/packages/@aws-cdk/cdk/test/evaluate-cfn.ts +++ b/packages/@aws-cdk/cdk/test/evaluate-cfn.ts @@ -3,7 +3,7 @@ * * Note that this function is not production quality, it exists to support tests. */ -import { isNameOfCloudFormationIntrinsic } from '../lib/cloudformation-lang'; +import { isNameOfCloudFormationIntrinsic } from '../lib/private/cloudformation-lang'; export function evaluateCFN(object: any, context: {[key: string]: string} = {}): any { const intrinsics: any = { diff --git a/packages/@aws-cdk/cdk/test/test.cross-environment-token.ts b/packages/@aws-cdk/cdk/test/test.cross-environment-token.ts index b8e49004ba9be..1c9bf61f7b6ce 100644 --- a/packages/@aws-cdk/cdk/test/test.cross-environment-token.ts +++ b/packages/@aws-cdk/cdk/test/test.cross-environment-token.ts @@ -203,7 +203,7 @@ class MyResource extends Resource { region: '', account: '', resource: 'my-resource', - resourceName: this.physicalName.value, + resourceName: this.physicalName, service: 'myservice', }, }); diff --git a/packages/@aws-cdk/cdk/test/test.include.ts b/packages/@aws-cdk/cdk/test/test.include.ts index f1637c9a2a34d..14743bc3ab006 100644 --- a/packages/@aws-cdk/cdk/test/test.include.ts +++ b/packages/@aws-cdk/cdk/test/test.include.ts @@ -1,12 +1,12 @@ import { Test } from 'nodeunit'; -import { CfnOutput, CfnParameter, CfnResource, Include, Stack } from '../lib'; +import { CfnInclude, CfnOutput, CfnParameter, CfnResource, Stack } from '../lib'; import { toCloudFormation } from './util'; export = { 'the Include construct can be used to embed an existing template as-is into a stack'(test: Test) { const stack = new Stack(); - new Include(stack, 'T1', { template: clone(template) }); + new CfnInclude(stack, 'T1', { template: clone(template) }); test.deepEqual(toCloudFormation(stack), { Parameters: { MyParam: { Type: 'String', Default: 'Hello' } }, @@ -20,9 +20,9 @@ export = { 'included templates can co-exist with elements created programmatically'(test: Test) { const stack = new Stack(); - new Include(stack, 'T1', { template: clone(template) }); + new CfnInclude(stack, 'T1', { template: clone(template) }); new CfnResource(stack, 'MyResource3', { type: 'ResourceType3', properties: { P3: 'Hello' } }); - new CfnOutput(stack, 'MyOutput', { description: 'Out!', disableExport: true, value: 'hey' }); + new CfnOutput(stack, 'MyOutput', { description: 'Out!', value: 'hey' }); new CfnParameter(stack, 'MyParam2', { type: 'Integer' }); test.deepEqual(toCloudFormation(stack), { @@ -42,7 +42,7 @@ export = { 'exception is thrown in construction if an entity from an included template has the same id as a programmatic entity'(test: Test) { const stack = new Stack(); - new Include(stack, 'T1', { template }); + new CfnInclude(stack, 'T1', { template }); new CfnResource(stack, 'MyResource3', { type: 'ResourceType3', properties: { P3: 'Hello' } }); new CfnOutput(stack, 'MyOutput', { description: 'Out!', value: 'in' }); new CfnParameter(stack, 'MyParam', { type: 'Integer' }); // duplicate! diff --git a/packages/@aws-cdk/cdk/test/test.output.ts b/packages/@aws-cdk/cdk/test/test.output.ts index 3d75fd53840cf..165284fdd2a14 100644 --- a/packages/@aws-cdk/cdk/test/test.output.ts +++ b/packages/@aws-cdk/cdk/test/test.output.ts @@ -9,7 +9,7 @@ export = { const ref = res.ref; new CfnOutput(stack, 'MyOutput', { - export: 'ExportName', + exportName: 'ExportName', value: ref, description: 'CfnOutput properties' }); @@ -22,45 +22,6 @@ export = { test.done(); }, - 'disableExport can be used to disable the auto-export behavior'(test: Test) { - const stack = new Stack(); - const output = new CfnOutput(stack, 'MyOutput', { disableExport: true, value: 'boom' }); - - test.equal(output.export, null); - - // cannot specify `export` and `disableExport` at the same time. - test.throws(() => new CfnOutput(stack, 'YourOutput', { - disableExport: true, - export: 'bla', - value: 'boom' - }), /Cannot set `disableExport` and specify an export name/); - - test.done(); - }, - - 'if stack name is undefined, we will only use the logical ID for the export name'(test: Test) { - const stack = new Stack(); - const output = new CfnOutput(stack, 'MyOutput', { value: 'boom' }); - test.deepEqual(stack.resolve(output.makeImportValue()), { 'Fn::ImportValue': 'Stack:MyOutput' }); - test.done(); - }, - - 'makeImportValue can be used to create an Fn::ImportValue from an output'(test: Test) { - const stack = new Stack(undefined, 'MyStack'); - const output = new CfnOutput(stack, 'MyOutput', { value: 'boom' }); - test.deepEqual(stack.resolve(output.makeImportValue()), { 'Fn::ImportValue': 'MyStack:MyOutput' }); - - test.deepEqual(toCloudFormation(stack), { - Outputs: { - MyOutput: { - Value: 'boom', - Export: { Name: 'MyStack:MyOutput' } - } - } - }); - test.done(); - }, - 'No export is created by default'(test: Test) { // GIVEN const stack = new Stack(); diff --git a/packages/@aws-cdk/cdk/test/test.resource.ts b/packages/@aws-cdk/cdk/test/test.resource.ts index 86580aca811a2..7547b3e582240 100644 --- a/packages/@aws-cdk/cdk/test/test.resource.ts +++ b/packages/@aws-cdk/cdk/test/test.resource.ts @@ -1,7 +1,7 @@ import cxapi = require('@aws-cdk/cx-api'); import { Test } from 'nodeunit'; import { App, App as Root, CfnCondition, - CfnResource, Construct, ConstructNode, DeletionPolicy, + CfnDeletionPolicy, CfnResource, Construct, ConstructNode, Fn, RemovalPolicy, Stack } from '../lib'; import { toCloudFormation } from './util'; @@ -215,8 +215,8 @@ export = { beforeAllowTrafficHook: 'lambda1', }, }; - r1.options.deletionPolicy = DeletionPolicy.Retain; - r1.options.updateReplacePolicy = DeletionPolicy.Snapshot; + r1.options.deletionPolicy = CfnDeletionPolicy.Retain; + r1.options.updateReplacePolicy = CfnDeletionPolicy.Snapshot; test.deepEqual(toCloudFormation(stack), { Resources: { @@ -667,7 +667,7 @@ export = { resB.node.addDependency(resA); // THEN - const assembly = app.run(); + const assembly = app.synth(); const templateB = assembly.getStack(stackB.stackName).template; test.deepEqual(templateB, { diff --git a/packages/@aws-cdk/cdk/test/test.stack.ts b/packages/@aws-cdk/cdk/test/test.stack.ts index 7ea682d5d71b7..340ebd3253f3d 100644 --- a/packages/@aws-cdk/cdk/test/test.stack.ts +++ b/packages/@aws-cdk/cdk/test/test.stack.ts @@ -1,5 +1,5 @@ import { Test } from 'nodeunit'; -import { App, CfnCondition, CfnOutput, CfnParameter, CfnResource, Construct, ConstructNode, Include, Lazy, ScopedAws, Stack } from '../lib'; +import { App, CfnCondition, CfnInclude, CfnOutput, CfnParameter, CfnResource, Construct, ConstructNode, Lazy, ScopedAws, Stack } from '../lib'; import { Intrinsic } from '../lib/private/intrinsic'; import { toCloudFormation } from './util'; @@ -120,7 +120,7 @@ export = { Description: 'hello, world' }; - new Include(stack, 'Include', { template }); + new CfnInclude(stack, 'Include', { template }); const output = toCloudFormation(stack); @@ -356,7 +356,7 @@ export = { // { Ref } and { GetAtt } new CfnResource(stack, 'RefToBonjour', { type: 'Other::Resource', properties: { - RefToBonjour: bonjour.refAsString, + RefToBonjour: bonjour.ref, GetAttBonjour: bonjour.getAtt('TheAtt').toString() }}); diff --git a/packages/decdk/lib/declarative-stack.ts b/packages/decdk/lib/declarative-stack.ts index 4f6e1ad06931a..c1ec3a1637131 100644 --- a/packages/decdk/lib/declarative-stack.ts +++ b/packages/decdk/lib/declarative-stack.ts @@ -50,7 +50,7 @@ export class DeclarativeStack extends cdk.Stack { delete template.$schema; // Add an Include construct with what's left of the template - new cdk.Include(this, 'Include', { template }); + new cdk.CfnInclude(this, 'Include', { template }); // replace all "Fn::GetAtt" with tokens that resolve correctly both for // constructs and raw resources. @@ -385,7 +385,7 @@ function deconstructGetAtt(stack: cdk.Stack, id: string, attribute: string) { return cdk.Lazy.stringValue({ produce: () => { const res = stack.node.tryFindChild(id); if (!res) { - const include = stack.node.tryFindChild('Include') as cdk.Include; + const include = stack.node.tryFindChild('Include') as cdk.CfnInclude; if (!include) { throw new Error(`Unexpected - "Include" should be in the stack at this point`); } @@ -411,7 +411,7 @@ function findConstruct(stack: cdk.Stack, id: string) { } function processReferences(stack: cdk.Stack) { - const include = stack.node.findChild('Include') as cdk.Include; + const include = stack.node.findChild('Include') as cdk.CfnInclude; if (!include) { throw new Error('Unexpected'); } diff --git a/tools/awslint/lib/rules/construct.ts b/tools/awslint/lib/rules/construct.ts index 2fa245f3df618..e615c940460ab 100644 --- a/tools/awslint/lib/rules/construct.ts +++ b/tools/awslint/lib/rules/construct.ts @@ -1,7 +1,6 @@ import reflect = require('jsii-reflect'); import { Linter, MethodSignatureParameterExpectation } from '../linter'; import { CoreTypes } from './core-types'; -import { ResourceReflection } from './resource'; export const constructLinter = new Linter(assembly => assembly.classes .filter(t => CoreTypes.isConstructClass(t)) @@ -294,29 +293,3 @@ constructLinter.add({ } } }); - -constructLinter.add({ - code: 'props-physical-name', - message: "Every Resource must have a single physical name construction property, " + - "with a name that is an ending substring of Name", - eval: e => { - if (!e.ctx.propsType) { return; } - if (!e.ctx.hasPropsArgument) { return; } - - // this rule only applies to Resources - if (!CoreTypes.isResourceClass(e.ctx.classType)) { return; } - - const physicalNameProps = e.ctx.propsType.allProperties.filter(p => p.type.toString() === '@aws-cdk/cdk.PhysicalName'); - if (physicalNameProps.length !== 1) { - e.assert(false, `${e.ctx.propsFqn}`); - } else { - const physicalNameProp = physicalNameProps[0]; - - // check the name of the property - const resourceName = new ResourceReflection(e.ctx).cfn.fullname.split('::')[2]; - const capitalizedProp = physicalNameProp.name[0].toUpperCase() + physicalNameProp.name.slice(1); - - e.assert(`${resourceName}Name`.endsWith(capitalizedProp), `${e.ctx.propsFqn}.${physicalNameProp.name}`); - } - }, -}); diff --git a/tools/awslint/lib/rules/core-types.ts b/tools/awslint/lib/rules/core-types.ts index 2f7f9205d3f5e..cd622f477623f 100644 --- a/tools/awslint/lib/rules/core-types.ts +++ b/tools/awslint/lib/rules/core-types.ts @@ -9,7 +9,8 @@ enum CoreTypesFqn { ConstructInterface = "@aws-cdk/cdk.IConstruct", Resource = "@aws-cdk/cdk.Resource", ResourceInterface = "@aws-cdk/cdk.IResource", - ResolvableInterface = "@aws-cdk/cdk.IResolvable" + ResolvableInterface = "@aws-cdk/cdk.IResolvable", + PhysicalName = "@aws-cdk/cdk.PhysicalName" } export class CoreTypes { @@ -112,6 +113,10 @@ export class CoreTypes { return this.sys.findInterface(CoreTypesFqn.ResolvableInterface); } + public get physicalNameClass() { + return this.sys.findClass(CoreTypesFqn.PhysicalName) + } + private readonly sys: TypeSystem; constructor(sys: reflect.TypeSystem) { diff --git a/tools/awslint/lib/rules/resource.ts b/tools/awslint/lib/rules/resource.ts index 2bc887399a870..ddf6b5f5c8c9e 100644 --- a/tools/awslint/lib/rules/resource.ts +++ b/tools/awslint/lib/rules/resource.ts @@ -45,6 +45,7 @@ export class ResourceReflection { public readonly cfn: CfnResourceReflection; public readonly basename: string; // i.e. Bucket public readonly core: CoreTypes; + public readonly physicalNameProp?: reflect.Property; constructor(public readonly construct: ConstructReflection) { this.assembly = construct.classType.assembly; @@ -62,6 +63,17 @@ export class ResourceReflection { this.basename = construct.classType.name; this.fqn = construct.fqn; this.attributes = this.findAttributeProperties(); + this.physicalNameProp = this.findPhysicalNameProp(); + } + + private findPhysicalNameProp() { + if (!this.construct.propsType) { + return undefined; + } + + const resourceName = camelcase(this.cfn.basename); + const physicalNameProp = `${resourceName}Name`; + return this.construct.propsType.allProperties.find(x => x.name === physicalNameProp); } /** @@ -176,6 +188,30 @@ resourceLinter.add({ } }); +resourceLinter.add({ + code: 'props-physical-name', + message: "Every Resource must have a single physical name construction property, " + + "with a name that is an ending substring of Name", + eval: e => { + if (!e.ctx.construct.propsType) { return; } + e.assert(e.ctx.physicalNameProp, e.ctx.construct.propsFqn); + } +}); + +resourceLinter.add({ + code: 'props-physical-name-type', + message: 'The type of the physical name prop should be "PhysicalName" if the name is optional and "string" if it is required', + eval: e => { + if (!e.ctx.physicalNameProp) { return; } + const prop = e.ctx.physicalNameProp; + const expectedType = prop.optional + ? e.ctx.core.physicalNameClass + : 'string'; + + e.assertTypesEqual(e.ctx.sys, prop.type, expectedType, `${e.ctx.construct.propsFqn}.${prop.name}`); + } +}); + function tryResolveCfnResource(resourceClass: reflect.ClassType): CfnResourceReflection | undefined { const sys = resourceClass.system;