From 4d6d5ca1945b339f3615a23c70052ff4d5a5784c Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Tue, 8 Jan 2019 10:12:56 +0200 Subject: [PATCH] feat: no more generated attribute types in CFN layer (L1) (#1489) Now that we can represent attributes as native strings and string lists, this covers the majority of resource attributes in CloudFormation. This change: * String attributes are represented as `string` (like before). * String list attribute are now represented as `string[]`. * Any other attribute types are represented as `cdk.Token`. Attributes that are represented as Tokens as of this change: * amazonmq has a bunch of `Integer` attributes (will be solved by #1455) * iot1click has a bunch of `Boolean` attributes * cloudformation has a JSON attribute * That's all. A few improvements to cfn2ts: * Auto-detect cfn2ts scope from package.json so it is more self-contained and doesn't rely on cdk-build-tools to run. * Added a "cfn2ts" npm script to all modules so it is now possible to regenerate all L1 via "lerna run cfn2ts". * Removed the premature optimization for avoiding code regeneration (it saved about 0.5ms). Fixes #1406 BREAKING CHANGE: any `CfnXxx` resource attributes that represented a list of strings are now typed as `string[]`s (via #1144). Attributes that represent strings, are still typed as `string` (#712) and all other attribute types are represented as `cdk.Token`. --- CONTRIBUTING.md | 16 ++++ packages/@aws-cdk/alexa-ask/package.json | 3 +- packages/@aws-cdk/aws-amazonmq/package.json | 3 +- packages/@aws-cdk/aws-apigateway/package.json | 3 +- .../aws-applicationautoscaling/package.json | 3 +- packages/@aws-cdk/aws-appstream/package.json | 3 +- packages/@aws-cdk/aws-appsync/package.json | 3 +- packages/@aws-cdk/aws-athena/package.json | 3 +- .../aws-autoscaling/lib/auto-scaling-group.ts | 2 +- .../@aws-cdk/aws-autoscaling/package.json | 3 +- .../aws-autoscalingplans/package.json | 3 +- packages/@aws-cdk/aws-batch/package.json | 3 +- packages/@aws-cdk/aws-budgets/package.json | 3 +- .../aws-certificatemanager/package.json | 3 +- packages/@aws-cdk/aws-cloud9/package.json | 3 +- .../@aws-cdk/aws-cloudformation/package.json | 3 +- packages/@aws-cdk/aws-cloudfront/package.json | 3 +- packages/@aws-cdk/aws-cloudtrail/package.json | 3 +- .../@aws-cdk/aws-cloudwatch/lib/dashboard.ts | 4 +- packages/@aws-cdk/aws-cloudwatch/package.json | 3 +- packages/@aws-cdk/aws-codebuild/package.json | 3 +- packages/@aws-cdk/aws-codecommit/package.json | 3 +- packages/@aws-cdk/aws-codedeploy/package.json | 3 +- .../lib/github-source-action.ts | 2 +- .../@aws-cdk/aws-codepipeline/package.json | 3 +- packages/@aws-cdk/aws-cognito/package.json | 3 +- packages/@aws-cdk/aws-config/package.json | 3 +- .../@aws-cdk/aws-datapipeline/package.json | 3 +- packages/@aws-cdk/aws-dax/package.json | 3 +- .../aws-directoryservice/package.json | 3 +- packages/@aws-cdk/aws-dlm/package.json | 3 +- packages/@aws-cdk/aws-dms/package.json | 3 +- packages/@aws-cdk/aws-dynamodb/package.json | 3 +- packages/@aws-cdk/aws-ec2/package.json | 3 +- packages/@aws-cdk/aws-ecr/package.json | 3 +- .../aws-ecs/lib/base/task-definition.ts | 2 +- packages/@aws-cdk/aws-ecs/package.json | 3 +- packages/@aws-cdk/aws-efs/package.json | 3 +- packages/@aws-cdk/aws-eks/package.json | 3 +- .../@aws-cdk/aws-elasticache/package.json | 3 +- .../aws-elasticbeanstalk/package.json | 3 +- .../aws-elasticloadbalancing/package.json | 3 +- .../lib/shared/base-target-group.ts | 2 +- .../aws-elasticloadbalancingv2/package.json | 3 +- .../@aws-cdk/aws-elasticsearch/package.json | 3 +- packages/@aws-cdk/aws-emr/package.json | 3 +- packages/@aws-cdk/aws-events/lib/rule.ts | 2 +- packages/@aws-cdk/aws-events/package.json | 3 +- packages/@aws-cdk/aws-gamelift/package.json | 3 +- packages/@aws-cdk/aws-glue/package.json | 3 +- packages/@aws-cdk/aws-guardduty/package.json | 3 +- packages/@aws-cdk/aws-iam/lib/policy.ts | 2 +- packages/@aws-cdk/aws-iam/package.json | 3 +- packages/@aws-cdk/aws-inspector/package.json | 3 +- packages/@aws-cdk/aws-iot/package.json | 3 +- packages/@aws-cdk/aws-iot1click/package.json | 3 +- .../@aws-cdk/aws-iotanalytics/package.json | 3 +- packages/@aws-cdk/aws-kinesis/package.json | 3 +- .../aws-kinesisanalytics/package.json | 3 +- .../@aws-cdk/aws-kinesisfirehose/package.json | 3 +- packages/@aws-cdk/aws-kms/package.json | 3 +- packages/@aws-cdk/aws-lambda/package.json | 3 +- .../aws-logs/lib/cross-account-destination.ts | 8 +- packages/@aws-cdk/aws-logs/package.json | 3 +- packages/@aws-cdk/aws-neptune/package.json | 3 +- packages/@aws-cdk/aws-opsworks/package.json | 3 +- packages/@aws-cdk/aws-rds/package.json | 3 +- packages/@aws-cdk/aws-redshift/package.json | 3 +- .../@aws-cdk/aws-route53/lib/hosted-zone.ts | 4 +- packages/@aws-cdk/aws-route53/package.json | 3 +- .../@aws-cdk/aws-route53resolver/package.json | 3 +- packages/@aws-cdk/aws-s3/package.json | 3 +- packages/@aws-cdk/aws-sagemaker/package.json | 3 +- packages/@aws-cdk/aws-sdb/package.json | 3 +- .../@aws-cdk/aws-secretsmanager/package.json | 3 +- packages/@aws-cdk/aws-serverless/package.json | 3 +- .../@aws-cdk/aws-servicecatalog/package.json | 3 +- .../aws-servicediscovery/package.json | 3 +- packages/@aws-cdk/aws-ses/package.json | 3 +- packages/@aws-cdk/aws-sns/package.json | 7 +- packages/@aws-cdk/aws-sqs/package.json | 3 +- packages/@aws-cdk/aws-ssm/package.json | 3 +- .../@aws-cdk/aws-stepfunctions/package.json | 3 +- packages/@aws-cdk/aws-waf/package.json | 3 +- .../@aws-cdk/aws-wafregional/package.json | 3 +- packages/@aws-cdk/aws-workspaces/package.json | 3 +- .../lib/cloudformation/cloudformation-json.ts | 4 +- .../build-tools/create-missing-libraries.ts | 3 +- tools/cfn2ts/bin/cfn2ts.ts | 43 +++++++--- tools/cfn2ts/lib/codegen.ts | 80 +++++++++---------- tools/cfn2ts/lib/genspec.ts | 33 +++----- tools/cfn2ts/lib/index.ts | 12 +-- tools/cfn2ts/package.json | 2 - tools/pkglint/lib/rules.ts | 28 +++++++ 94 files changed, 297 insertions(+), 184 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ccd508dab5efd..32c99305535d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -156,6 +156,22 @@ Here are a few useful commands: evaluate only the rule specified [awslint README](./tools/awslint/README.md) for details on include/exclude rule patterns. +### cfn2ts + +This tool is used to generate our low-level CloudFormation resources +(L1/`CfnFoo`). It is executed as part of the build step of all modules in the +AWS Construct Library. + +The tool consults the `cdk-build.cloudformation` key in `package.json` to +determine which CloudFormation namespace this library represents (e.g. +`AWS::EC2` is the namespace for `aws-ec2`). We maintain strict 1:1 relationship +between those. + +Each module also has an npm script called `cfn2ts`: + +* `npm run cfn2ts`: generates L1 for a specific module +* `lerna run cfn2ts`: generates L1 for the entire repo + ## Development Workflows ### Full clean build diff --git a/packages/@aws-cdk/alexa-ask/package.json b/packages/@aws-cdk/alexa-ask/package.json index 1b7912a0799e0..8e21ad042116c 100644 --- a/packages/@aws-cdk/alexa-ask/package.json +++ b/packages/@aws-cdk/alexa-ask/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "Alexa::ASK" diff --git a/packages/@aws-cdk/aws-amazonmq/package.json b/packages/@aws-cdk/aws-amazonmq/package.json index aab237179c15b..c20cd401983b4 100644 --- a/packages/@aws-cdk/aws-amazonmq/package.json +++ b/packages/@aws-cdk/aws-amazonmq/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::AmazonMQ" diff --git a/packages/@aws-cdk/aws-apigateway/package.json b/packages/@aws-cdk/aws-apigateway/package.json index e3492e31d6eb4..39fae0265b375 100644 --- a/packages/@aws-cdk/aws-apigateway/package.json +++ b/packages/@aws-cdk/aws-apigateway/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ApiGateway" diff --git a/packages/@aws-cdk/aws-applicationautoscaling/package.json b/packages/@aws-cdk/aws-applicationautoscaling/package.json index 610eeef609f98..f690a2245335c 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/package.json +++ b/packages/@aws-cdk/aws-applicationautoscaling/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ApplicationAutoScaling" diff --git a/packages/@aws-cdk/aws-appstream/package.json b/packages/@aws-cdk/aws-appstream/package.json index 284f90a5c0b93..f71a67696af46 100644 --- a/packages/@aws-cdk/aws-appstream/package.json +++ b/packages/@aws-cdk/aws-appstream/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::AppStream" diff --git a/packages/@aws-cdk/aws-appsync/package.json b/packages/@aws-cdk/aws-appsync/package.json index 8616917b69ee2..ab26e698c3ac2 100644 --- a/packages/@aws-cdk/aws-appsync/package.json +++ b/packages/@aws-cdk/aws-appsync/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::AppSync" diff --git a/packages/@aws-cdk/aws-athena/package.json b/packages/@aws-cdk/aws-athena/package.json index a098df2cd14b5..058af8e62615d 100644 --- a/packages/@aws-cdk/aws-athena/package.json +++ b/packages/@aws-cdk/aws-athena/package.json @@ -38,7 +38,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "keywords": [ "aws", 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 19f50f187bfed..dbd85436c8000 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts @@ -222,7 +222,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup // use delayed evaluation const machineImage = props.machineImage.getImage(this); - const userDataToken = new cdk.Token(() => cdk.Fn.base64((machineImage.os.createUserData(this.userDataLines)))); + const userDataToken = new cdk.Token(() => cdk.Fn.base64((machineImage.os.createUserData(this.userDataLines)))).toString(); const securityGroupsToken = new cdk.Token(() => this.securityGroups.map(sg => sg.securityGroupId)); const launchConfig = new CfnLaunchConfiguration(this, 'LaunchConfig', { diff --git a/packages/@aws-cdk/aws-autoscaling/package.json b/packages/@aws-cdk/aws-autoscaling/package.json index 15d817bf5d798..150c55ca71b21 100644 --- a/packages/@aws-cdk/aws-autoscaling/package.json +++ b/packages/@aws-cdk/aws-autoscaling/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::AutoScaling" diff --git a/packages/@aws-cdk/aws-autoscalingplans/package.json b/packages/@aws-cdk/aws-autoscalingplans/package.json index ee7cc4713ee65..82157d269f814 100644 --- a/packages/@aws-cdk/aws-autoscalingplans/package.json +++ b/packages/@aws-cdk/aws-autoscalingplans/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::AutoScalingPlans" diff --git a/packages/@aws-cdk/aws-batch/package.json b/packages/@aws-cdk/aws-batch/package.json index fce8f30ba8c47..5be1d6f708639 100644 --- a/packages/@aws-cdk/aws-batch/package.json +++ b/packages/@aws-cdk/aws-batch/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Batch" diff --git a/packages/@aws-cdk/aws-budgets/package.json b/packages/@aws-cdk/aws-budgets/package.json index 5d959d0188452..60b311c296f95 100644 --- a/packages/@aws-cdk/aws-budgets/package.json +++ b/packages/@aws-cdk/aws-budgets/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Budgets" diff --git a/packages/@aws-cdk/aws-certificatemanager/package.json b/packages/@aws-cdk/aws-certificatemanager/package.json index 6b1e6d57d051e..fb1510f5e0faf 100644 --- a/packages/@aws-cdk/aws-certificatemanager/package.json +++ b/packages/@aws-cdk/aws-certificatemanager/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CertificateManager" diff --git a/packages/@aws-cdk/aws-cloud9/package.json b/packages/@aws-cdk/aws-cloud9/package.json index d995030c736b0..d8a06127d18b5 100644 --- a/packages/@aws-cdk/aws-cloud9/package.json +++ b/packages/@aws-cdk/aws-cloud9/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Cloud9" diff --git a/packages/@aws-cdk/aws-cloudformation/package.json b/packages/@aws-cdk/aws-cloudformation/package.json index 0c584f7137903..f46629dded605 100644 --- a/packages/@aws-cdk/aws-cloudformation/package.json +++ b/packages/@aws-cdk/aws-cloudformation/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CloudFormation" diff --git a/packages/@aws-cdk/aws-cloudfront/package.json b/packages/@aws-cdk/aws-cloudfront/package.json index 26c0fdc8fcf48..26daa24473798 100644 --- a/packages/@aws-cdk/aws-cloudfront/package.json +++ b/packages/@aws-cdk/aws-cloudfront/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CloudFront" diff --git a/packages/@aws-cdk/aws-cloudtrail/package.json b/packages/@aws-cdk/aws-cloudtrail/package.json index b8e075bbab1cb..ccd9d9a82a571 100644 --- a/packages/@aws-cdk/aws-cloudtrail/package.json +++ b/packages/@aws-cdk/aws-cloudtrail/package.json @@ -34,7 +34,8 @@ "test": "cdk-test", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CloudTrail" diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts b/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts index 0f08dde461215..db5681eb0d693 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts @@ -26,7 +26,7 @@ export class Dashboard extends Construct { // This is a bug in CloudFormation, but we don't want CDK users to have a bad // experience. We'll generate a name here if you did not supply one. // See: https://github.com/awslabs/aws-cdk/issues/213 - const dashboardName = (props && props.dashboardName) || new Token(() => this.generateDashboardName()); + const dashboardName = (props && props.dashboardName) || new Token(() => this.generateDashboardName()).toString(); this.dashboard = new CfnDashboard(this, 'Resource', { dashboardName, @@ -34,7 +34,7 @@ export class Dashboard extends Construct { const column = new Column(...this.rows); column.position(0, 0); return CloudFormationJSON.stringify({ widgets: column.toJson() }); - }) + }).toString() }); } diff --git a/packages/@aws-cdk/aws-cloudwatch/package.json b/packages/@aws-cdk/aws-cloudwatch/package.json index c4ef501d64a47..ca25ce23a2617 100644 --- a/packages/@aws-cdk/aws-cloudwatch/package.json +++ b/packages/@aws-cdk/aws-cloudwatch/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CloudWatch" diff --git a/packages/@aws-cdk/aws-codebuild/package.json b/packages/@aws-cdk/aws-codebuild/package.json index 356862d08abea..f213ffbcaba4e 100644 --- a/packages/@aws-cdk/aws-codebuild/package.json +++ b/packages/@aws-cdk/aws-codebuild/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CodeBuild" diff --git a/packages/@aws-cdk/aws-codecommit/package.json b/packages/@aws-cdk/aws-codecommit/package.json index 98d1de35f1f78..883b713a992d1 100644 --- a/packages/@aws-cdk/aws-codecommit/package.json +++ b/packages/@aws-cdk/aws-codecommit/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CodeCommit" diff --git a/packages/@aws-cdk/aws-codedeploy/package.json b/packages/@aws-cdk/aws-codedeploy/package.json index f28057db5731b..a1e13dfe32870 100644 --- a/packages/@aws-cdk/aws-codedeploy/package.json +++ b/packages/@aws-cdk/aws-codedeploy/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CodeDeploy" diff --git a/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts b/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts index 652b13e6bbcfa..c70c2d048ddf7 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts @@ -76,7 +76,7 @@ export class GitHubSourceAction extends actions.SourceAction { new CfnWebhook(this, 'WebhookResource', { authentication: 'GITHUB_HMAC', authenticationConfiguration: { - secretToken: props.oauthToken, + secretToken: props.oauthToken.toString(), }, filters: [ { diff --git a/packages/@aws-cdk/aws-codepipeline/package.json b/packages/@aws-cdk/aws-codepipeline/package.json index f0249b590a9a0..da21b7b2a47f9 100644 --- a/packages/@aws-cdk/aws-codepipeline/package.json +++ b/packages/@aws-cdk/aws-codepipeline/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::CodePipeline" diff --git a/packages/@aws-cdk/aws-cognito/package.json b/packages/@aws-cdk/aws-cognito/package.json index e285692352c86..979c38fc27ce9 100644 --- a/packages/@aws-cdk/aws-cognito/package.json +++ b/packages/@aws-cdk/aws-cognito/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Cognito" diff --git a/packages/@aws-cdk/aws-config/package.json b/packages/@aws-cdk/aws-config/package.json index 69fee10b973ab..1775ca854460e 100644 --- a/packages/@aws-cdk/aws-config/package.json +++ b/packages/@aws-cdk/aws-config/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Config" diff --git a/packages/@aws-cdk/aws-datapipeline/package.json b/packages/@aws-cdk/aws-datapipeline/package.json index 90f0516eb8394..deb4f55c98157 100644 --- a/packages/@aws-cdk/aws-datapipeline/package.json +++ b/packages/@aws-cdk/aws-datapipeline/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::DataPipeline" diff --git a/packages/@aws-cdk/aws-dax/package.json b/packages/@aws-cdk/aws-dax/package.json index f01c994a94040..d690a5c9559ed 100644 --- a/packages/@aws-cdk/aws-dax/package.json +++ b/packages/@aws-cdk/aws-dax/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::DAX" diff --git a/packages/@aws-cdk/aws-directoryservice/package.json b/packages/@aws-cdk/aws-directoryservice/package.json index 6937576ef8aba..1d981f8fc580c 100644 --- a/packages/@aws-cdk/aws-directoryservice/package.json +++ b/packages/@aws-cdk/aws-directoryservice/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::DirectoryService" diff --git a/packages/@aws-cdk/aws-dlm/package.json b/packages/@aws-cdk/aws-dlm/package.json index d453dc09e29d9..2877c717d2042 100644 --- a/packages/@aws-cdk/aws-dlm/package.json +++ b/packages/@aws-cdk/aws-dlm/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::DLM" diff --git a/packages/@aws-cdk/aws-dms/package.json b/packages/@aws-cdk/aws-dms/package.json index cb87037905226..d8ce0f19bb1c2 100644 --- a/packages/@aws-cdk/aws-dms/package.json +++ b/packages/@aws-cdk/aws-dms/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::DMS" diff --git a/packages/@aws-cdk/aws-dynamodb/package.json b/packages/@aws-cdk/aws-dynamodb/package.json index 1398aeabfb9b1..67841c31b993b 100644 --- a/packages/@aws-cdk/aws-dynamodb/package.json +++ b/packages/@aws-cdk/aws-dynamodb/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::DynamoDB" diff --git a/packages/@aws-cdk/aws-ec2/package.json b/packages/@aws-cdk/aws-ec2/package.json index ab5f3163e6a30..8eaa365420d01 100644 --- a/packages/@aws-cdk/aws-ec2/package.json +++ b/packages/@aws-cdk/aws-ec2/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::EC2" diff --git a/packages/@aws-cdk/aws-ecr/package.json b/packages/@aws-cdk/aws-ecr/package.json index 66ecea755a6e6..159abfd955aa1 100644 --- a/packages/@aws-cdk/aws-ecr/package.json +++ b/packages/@aws-cdk/aws-ecr/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ECR" 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 f1a96595e6640..4c197604b76d2 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts @@ -188,7 +188,7 @@ export class TaskDefinition extends cdk.Construct { const taskDef = new CfnTaskDefinition(this, 'Resource', { containerDefinitions: new cdk.Token(() => this.containers.map(x => x.renderContainerDefinition())), volumes: new cdk.Token(() => this.volumes), - executionRoleArn: new cdk.Token(() => this.executionRole && this.executionRole.roleArn), + executionRoleArn: new cdk.Token(() => this.executionRole && this.executionRole.roleArn).toString(), family: this.family, taskRoleArn: this.taskRole.roleArn, requiresCompatibilities: [ diff --git a/packages/@aws-cdk/aws-ecs/package.json b/packages/@aws-cdk/aws-ecs/package.json index cb5e391e19407..60bce0cc371e9 100644 --- a/packages/@aws-cdk/aws-ecs/package.json +++ b/packages/@aws-cdk/aws-ecs/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ECS" diff --git a/packages/@aws-cdk/aws-efs/package.json b/packages/@aws-cdk/aws-efs/package.json index 0e1e0503cfbc1..9d12ec8076954 100644 --- a/packages/@aws-cdk/aws-efs/package.json +++ b/packages/@aws-cdk/aws-efs/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::EFS" diff --git a/packages/@aws-cdk/aws-eks/package.json b/packages/@aws-cdk/aws-eks/package.json index 60b99e7ba34a5..aab9e7338c98a 100644 --- a/packages/@aws-cdk/aws-eks/package.json +++ b/packages/@aws-cdk/aws-eks/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::EKS" diff --git a/packages/@aws-cdk/aws-elasticache/package.json b/packages/@aws-cdk/aws-elasticache/package.json index db71b6ceea00e..023a59d44c40b 100644 --- a/packages/@aws-cdk/aws-elasticache/package.json +++ b/packages/@aws-cdk/aws-elasticache/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ElastiCache" diff --git a/packages/@aws-cdk/aws-elasticbeanstalk/package.json b/packages/@aws-cdk/aws-elasticbeanstalk/package.json index 8485af3458425..0f0e2b2b9a9a8 100644 --- a/packages/@aws-cdk/aws-elasticbeanstalk/package.json +++ b/packages/@aws-cdk/aws-elasticbeanstalk/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ElasticBeanstalk" diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/package.json b/packages/@aws-cdk/aws-elasticloadbalancing/package.json index 3db81523cd10c..4a2165b4711c8 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/package.json +++ b/packages/@aws-cdk/aws-elasticloadbalancing/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ElasticLoadBalancing" 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 32cd72a8ad4a3..2b71ef19d39d1 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 ...additionalProps }); - this.targetGroupLoadBalancerArns = this.resource.targetGroupLoadBalancerArns.toList(); + this.targetGroupLoadBalancerArns = this.resource.targetGroupLoadBalancerArns; this.targetGroupArn = this.resource.ref; this.targetGroupFullName = this.resource.targetGroupFullName; this.loadBalancerArns = this.resource.targetGroupLoadBalancerArns.toString(); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json index f0c32b4097d58..4f6a863de2591 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ElasticLoadBalancingV2" diff --git a/packages/@aws-cdk/aws-elasticsearch/package.json b/packages/@aws-cdk/aws-elasticsearch/package.json index 17362517d46b4..295ad5307bf55 100644 --- a/packages/@aws-cdk/aws-elasticsearch/package.json +++ b/packages/@aws-cdk/aws-elasticsearch/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Elasticsearch" diff --git a/packages/@aws-cdk/aws-emr/package.json b/packages/@aws-cdk/aws-emr/package.json index 26d0f0d760ddc..2d875fb9c94c0 100644 --- a/packages/@aws-cdk/aws-emr/package.json +++ b/packages/@aws-cdk/aws-emr/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::EMR" diff --git a/packages/@aws-cdk/aws-events/lib/rule.ts b/packages/@aws-cdk/aws-events/lib/rule.ts index b04ab872c860c..e7ff424d4f582 100644 --- a/packages/@aws-cdk/aws-events/lib/rule.ts +++ b/packages/@aws-cdk/aws-events/lib/rule.ts @@ -84,7 +84,7 @@ export class EventRule extends Construct implements IEventRule { name: props.ruleName, description: props.description, state: props.enabled == null ? 'ENABLED' : (props.enabled ? 'ENABLED' : 'DISABLED'), - scheduleExpression: new Token(() => this.scheduleExpression), + scheduleExpression: new Token(() => this.scheduleExpression).toString(), eventPattern: new Token(() => this.renderEventPattern()), targets: new Token(() => this.renderTargets()) }); diff --git a/packages/@aws-cdk/aws-events/package.json b/packages/@aws-cdk/aws-events/package.json index c090901545031..71975a760bf74 100644 --- a/packages/@aws-cdk/aws-events/package.json +++ b/packages/@aws-cdk/aws-events/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Events" diff --git a/packages/@aws-cdk/aws-gamelift/package.json b/packages/@aws-cdk/aws-gamelift/package.json index 63c5e341eb8f8..3a83fe6f5b696 100644 --- a/packages/@aws-cdk/aws-gamelift/package.json +++ b/packages/@aws-cdk/aws-gamelift/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::GameLift" diff --git a/packages/@aws-cdk/aws-glue/package.json b/packages/@aws-cdk/aws-glue/package.json index a7aab0cc26e8a..462f0b2e306b1 100644 --- a/packages/@aws-cdk/aws-glue/package.json +++ b/packages/@aws-cdk/aws-glue/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Glue" diff --git a/packages/@aws-cdk/aws-guardduty/package.json b/packages/@aws-cdk/aws-guardduty/package.json index 86dc0a10afadc..a419b5705abe5 100644 --- a/packages/@aws-cdk/aws-guardduty/package.json +++ b/packages/@aws-cdk/aws-guardduty/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::GuardDuty" diff --git a/packages/@aws-cdk/aws-iam/lib/policy.ts b/packages/@aws-cdk/aws-iam/lib/policy.ts index 334d80205116c..d3a5104a02b9e 100644 --- a/packages/@aws-cdk/aws-iam/lib/policy.ts +++ b/packages/@aws-cdk/aws-iam/lib/policy.ts @@ -108,7 +108,7 @@ export class Policy extends Construct implements IDependable { const resource = new CfnPolicy(this, 'Resource', { policyDocument: this.document, - policyName: new Token(() => this.policyName), + policyName: new Token(() => this.policyName).toString(), roles: undefinedIfEmpty(() => this.roles.map(r => r.roleName)), users: undefinedIfEmpty(() => this.users.map(u => u.userName)), groups: undefinedIfEmpty(() => this.groups.map(g => g.groupName)), diff --git a/packages/@aws-cdk/aws-iam/package.json b/packages/@aws-cdk/aws-iam/package.json index 57e6a9f2d37c1..cdf21c2c535aa 100644 --- a/packages/@aws-cdk/aws-iam/package.json +++ b/packages/@aws-cdk/aws-iam/package.json @@ -35,7 +35,8 @@ "pkglint": "pkglint -f", "integ": "cdk-integ", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::IAM" diff --git a/packages/@aws-cdk/aws-inspector/package.json b/packages/@aws-cdk/aws-inspector/package.json index 503088c8c3234..7d450e411bf10 100644 --- a/packages/@aws-cdk/aws-inspector/package.json +++ b/packages/@aws-cdk/aws-inspector/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Inspector" diff --git a/packages/@aws-cdk/aws-iot/package.json b/packages/@aws-cdk/aws-iot/package.json index 991d3b4ba04c6..25b37469ae0a6 100644 --- a/packages/@aws-cdk/aws-iot/package.json +++ b/packages/@aws-cdk/aws-iot/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::IoT" diff --git a/packages/@aws-cdk/aws-iot1click/package.json b/packages/@aws-cdk/aws-iot1click/package.json index 6a15d49470199..3f7f740aa8048 100644 --- a/packages/@aws-cdk/aws-iot1click/package.json +++ b/packages/@aws-cdk/aws-iot1click/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::IoT1Click" diff --git a/packages/@aws-cdk/aws-iotanalytics/package.json b/packages/@aws-cdk/aws-iotanalytics/package.json index 1386cdd8c906d..1aabc33751b1a 100644 --- a/packages/@aws-cdk/aws-iotanalytics/package.json +++ b/packages/@aws-cdk/aws-iotanalytics/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::IoTAnalytics" diff --git a/packages/@aws-cdk/aws-kinesis/package.json b/packages/@aws-cdk/aws-kinesis/package.json index 1737d2f2a329e..26950e04ef58b 100644 --- a/packages/@aws-cdk/aws-kinesis/package.json +++ b/packages/@aws-cdk/aws-kinesis/package.json @@ -34,7 +34,8 @@ "test": "cdk-test", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Kinesis" diff --git a/packages/@aws-cdk/aws-kinesisanalytics/package.json b/packages/@aws-cdk/aws-kinesisanalytics/package.json index b4b6596a43fc7..5e718912ed775 100644 --- a/packages/@aws-cdk/aws-kinesisanalytics/package.json +++ b/packages/@aws-cdk/aws-kinesisanalytics/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::KinesisAnalytics" diff --git a/packages/@aws-cdk/aws-kinesisfirehose/package.json b/packages/@aws-cdk/aws-kinesisfirehose/package.json index 42f9780408cf9..49f9d1bd7a7b4 100644 --- a/packages/@aws-cdk/aws-kinesisfirehose/package.json +++ b/packages/@aws-cdk/aws-kinesisfirehose/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::KinesisFirehose" diff --git a/packages/@aws-cdk/aws-kms/package.json b/packages/@aws-cdk/aws-kms/package.json index 8acfbfc402353..5bb1db708aef6 100644 --- a/packages/@aws-cdk/aws-kms/package.json +++ b/packages/@aws-cdk/aws-kms/package.json @@ -35,7 +35,8 @@ "pkglint": "pkglint -f", "integ": "cdk-integ", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::KMS" diff --git a/packages/@aws-cdk/aws-lambda/package.json b/packages/@aws-cdk/aws-lambda/package.json index 74b6542f1bd15..9fe6ca8269269 100644 --- a/packages/@aws-cdk/aws-lambda/package.json +++ b/packages/@aws-cdk/aws-lambda/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Lambda" 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 881f6e0769da0..4507f01808926 100644 --- a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts +++ b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts @@ -60,12 +60,12 @@ export class CrossAccountDestination extends cdk.Construct implements ILogSubscr super(scope, id); // In the underlying model, the name is not optional, but we make it so anyway. - const destinationName = props.destinationName || new cdk.Token(() => this.generateUniqueName()); + const destinationName = props.destinationName || new cdk.Token(() => this.generateUniqueName()).toString(); this.resource = new CfnDestination(this, 'Resource', { destinationName, // Must be stringified policy - destinationPolicy: new cdk.Token(() => this.stringifiedPolicyDocument()), + destinationPolicy: this.lazyStringifiedPolicyDocument(), roleArn: props.role.roleArn, targetArn: props.targetArn }); @@ -94,7 +94,7 @@ export class CrossAccountDestination extends cdk.Construct implements ILogSubscr /** * Return a stringified JSON version of the PolicyDocument */ - private stringifiedPolicyDocument() { - return this.policyDocument.isEmpty ? '' : cdk.CloudFormationJSON.stringify(cdk.resolve(this.policyDocument)); + private lazyStringifiedPolicyDocument() { + return new cdk.Token(() => this.policyDocument.isEmpty ? '' : cdk.CloudFormationJSON.stringify(cdk.resolve(this.policyDocument))).toString(); } } diff --git a/packages/@aws-cdk/aws-logs/package.json b/packages/@aws-cdk/aws-logs/package.json index 12527c729505d..ec39dae695238 100644 --- a/packages/@aws-cdk/aws-logs/package.json +++ b/packages/@aws-cdk/aws-logs/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Logs" diff --git a/packages/@aws-cdk/aws-neptune/package.json b/packages/@aws-cdk/aws-neptune/package.json index e1e13650e9dd6..152ceea611204 100644 --- a/packages/@aws-cdk/aws-neptune/package.json +++ b/packages/@aws-cdk/aws-neptune/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Neptune" diff --git a/packages/@aws-cdk/aws-opsworks/package.json b/packages/@aws-cdk/aws-opsworks/package.json index 5d363912958ab..44e6d84bd2da2 100644 --- a/packages/@aws-cdk/aws-opsworks/package.json +++ b/packages/@aws-cdk/aws-opsworks/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::OpsWorks" diff --git a/packages/@aws-cdk/aws-rds/package.json b/packages/@aws-cdk/aws-rds/package.json index 049f3c1953472..bea6fa88d8706 100644 --- a/packages/@aws-cdk/aws-rds/package.json +++ b/packages/@aws-cdk/aws-rds/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::RDS" diff --git a/packages/@aws-cdk/aws-redshift/package.json b/packages/@aws-cdk/aws-redshift/package.json index 6920fbd937764..16dba5bb6257d 100644 --- a/packages/@aws-cdk/aws-redshift/package.json +++ b/packages/@aws-cdk/aws-redshift/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Redshift" diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts index fb05148c2b7e9..944296916741b 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts @@ -71,7 +71,7 @@ export class HostedZone extends cdk.Construct implements IHostedZone { }); this.hostedZoneId = hostedZone.ref; - this.hostedZoneNameServers = hostedZone.hostedZoneNameServers.toList(); + this.hostedZoneNameServers = hostedZone.hostedZoneNameServers; this.zoneName = props.zoneName; for (const vpc of props.vpcs || []) { @@ -92,7 +92,7 @@ export class HostedZone extends cdk.Construct implements IHostedZone { * @param vpc the other VPC to add. */ public addVpc(vpc: ec2.IVpcNetwork) { - this.vpcs.push({ vpcId: vpc.vpcId, vpcRegion: new cdk.AwsRegion() }); + this.vpcs.push({ vpcId: vpc.vpcId, vpcRegion: new cdk.AwsRegion().toString() }); } } diff --git a/packages/@aws-cdk/aws-route53/package.json b/packages/@aws-cdk/aws-route53/package.json index ff4a7c64b0d4d..66d76529cdc21 100644 --- a/packages/@aws-cdk/aws-route53/package.json +++ b/packages/@aws-cdk/aws-route53/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Route53" diff --git a/packages/@aws-cdk/aws-route53resolver/package.json b/packages/@aws-cdk/aws-route53resolver/package.json index 5875e15290d93..acf403a3dc11c 100644 --- a/packages/@aws-cdk/aws-route53resolver/package.json +++ b/packages/@aws-cdk/aws-route53resolver/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Route53Resolver" diff --git a/packages/@aws-cdk/aws-s3/package.json b/packages/@aws-cdk/aws-s3/package.json index 523508b3e7009..3db164dec96f7 100644 --- a/packages/@aws-cdk/aws-s3/package.json +++ b/packages/@aws-cdk/aws-s3/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::S3" diff --git a/packages/@aws-cdk/aws-sagemaker/package.json b/packages/@aws-cdk/aws-sagemaker/package.json index 32e6ad4bb3fbf..d104f19ffa884 100644 --- a/packages/@aws-cdk/aws-sagemaker/package.json +++ b/packages/@aws-cdk/aws-sagemaker/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SageMaker" diff --git a/packages/@aws-cdk/aws-sdb/package.json b/packages/@aws-cdk/aws-sdb/package.json index a7d5f9e1567a9..77d0063483f82 100644 --- a/packages/@aws-cdk/aws-sdb/package.json +++ b/packages/@aws-cdk/aws-sdb/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SDB" diff --git a/packages/@aws-cdk/aws-secretsmanager/package.json b/packages/@aws-cdk/aws-secretsmanager/package.json index f682086ddbe90..1559be54f2c5c 100644 --- a/packages/@aws-cdk/aws-secretsmanager/package.json +++ b/packages/@aws-cdk/aws-secretsmanager/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SecretsManager" diff --git a/packages/@aws-cdk/aws-serverless/package.json b/packages/@aws-cdk/aws-serverless/package.json index 018cb4139c9da..068151dae302c 100644 --- a/packages/@aws-cdk/aws-serverless/package.json +++ b/packages/@aws-cdk/aws-serverless/package.json @@ -36,7 +36,8 @@ "pkglint": "pkglint -f", "test": "cdk-test", "watch": "cdk-watch", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::Serverless" diff --git a/packages/@aws-cdk/aws-servicecatalog/package.json b/packages/@aws-cdk/aws-servicecatalog/package.json index f86e47e1d438f..dcd34cceb3775 100644 --- a/packages/@aws-cdk/aws-servicecatalog/package.json +++ b/packages/@aws-cdk/aws-servicecatalog/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ServiceCatalog" diff --git a/packages/@aws-cdk/aws-servicediscovery/package.json b/packages/@aws-cdk/aws-servicediscovery/package.json index cadbbf6f2d99e..a7f2065b6c4d4 100644 --- a/packages/@aws-cdk/aws-servicediscovery/package.json +++ b/packages/@aws-cdk/aws-servicediscovery/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::ServiceDiscovery" diff --git a/packages/@aws-cdk/aws-ses/package.json b/packages/@aws-cdk/aws-ses/package.json index d01b5b192087a..353632658dcfa 100644 --- a/packages/@aws-cdk/aws-ses/package.json +++ b/packages/@aws-cdk/aws-ses/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SES" diff --git a/packages/@aws-cdk/aws-sns/package.json b/packages/@aws-cdk/aws-sns/package.json index d557def1ace01..017df9cbd6099 100644 --- a/packages/@aws-cdk/aws-sns/package.json +++ b/packages/@aws-cdk/aws-sns/package.json @@ -22,7 +22,9 @@ }, "sphinx": {} }, - "excludeTypescript": ["examples"] + "excludeTypescript": [ + "examples" + ] }, "repository": { "type": "git", @@ -36,7 +38,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SNS" diff --git a/packages/@aws-cdk/aws-sqs/package.json b/packages/@aws-cdk/aws-sqs/package.json index 4cd5ed45af113..cb164daf33105 100644 --- a/packages/@aws-cdk/aws-sqs/package.json +++ b/packages/@aws-cdk/aws-sqs/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SQS" diff --git a/packages/@aws-cdk/aws-ssm/package.json b/packages/@aws-cdk/aws-ssm/package.json index bba7ae006a162..ac3683dc56aaf 100644 --- a/packages/@aws-cdk/aws-ssm/package.json +++ b/packages/@aws-cdk/aws-ssm/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::SSM" diff --git a/packages/@aws-cdk/aws-stepfunctions/package.json b/packages/@aws-cdk/aws-stepfunctions/package.json index 1c15ec1089cdc..43b09c9950160 100644 --- a/packages/@aws-cdk/aws-stepfunctions/package.json +++ b/packages/@aws-cdk/aws-stepfunctions/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::StepFunctions" diff --git a/packages/@aws-cdk/aws-waf/package.json b/packages/@aws-cdk/aws-waf/package.json index 40efdd860d07e..dbce884c0e1cd 100644 --- a/packages/@aws-cdk/aws-waf/package.json +++ b/packages/@aws-cdk/aws-waf/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::WAF" diff --git a/packages/@aws-cdk/aws-wafregional/package.json b/packages/@aws-cdk/aws-wafregional/package.json index 7b0e85664a697..84fafc0824c26 100644 --- a/packages/@aws-cdk/aws-wafregional/package.json +++ b/packages/@aws-cdk/aws-wafregional/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::WAFRegional" diff --git a/packages/@aws-cdk/aws-workspaces/package.json b/packages/@aws-cdk/aws-workspaces/package.json index a0c9b3abbe82a..789220ab51f19 100644 --- a/packages/@aws-cdk/aws-workspaces/package.json +++ b/packages/@aws-cdk/aws-workspaces/package.json @@ -35,7 +35,8 @@ "integ": "cdk-integ", "pkglint": "pkglint -f", "package": "cdk-package", - "awslint": "cdk-awslint" + "awslint": "cdk-awslint", + "cfn2ts": "cfn2ts" }, "cdk-build": { "cloudformation": "AWS::WorkSpaces" diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/cloudformation-json.ts b/packages/@aws-cdk/cdk/lib/cloudformation/cloudformation-json.ts index 6075f5650352a..670a974a1b224 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/cloudformation-json.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/cloudformation-json.ts @@ -15,7 +15,7 @@ export class CloudFormationJSON { * All Tokens substituted in this way must return strings, or the evaluation * in CloudFormation will fail. */ - public static stringify(obj: any): Token { + public static stringify(obj: any): string { return new Token(() => { // Resolve inner value first so that if they evaluate to literals, we // maintain the type (and discard 'undefined's). @@ -31,7 +31,7 @@ export class CloudFormationJSON { // We can just directly return this value, since resolve() will be called // on our return value anyway. return JSON.stringify(deepReplaceIntrinsics(resolved)); - }); + }).toString(); /** * Recurse into a structure, replace all intrinsics with IntrinsicTokens. diff --git a/packages/@aws-cdk/cfnspec/build-tools/create-missing-libraries.ts b/packages/@aws-cdk/cfnspec/build-tools/create-missing-libraries.ts index 5d33a4a404369..b71a21fe00ae6 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/create-missing-libraries.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/create-missing-libraries.ts @@ -107,7 +107,8 @@ async function main() { package: "cdk-package", pkglint: "pkglint -f", test: "cdk-test", - watch: "cdk-watch" + watch: "cdk-watch", + cfn2ts: "cfn2ts" }, 'cdk-build': { cloudformation: namespace diff --git a/tools/cfn2ts/bin/cfn2ts.ts b/tools/cfn2ts/bin/cfn2ts.ts index 36502e2a72549..c38e67b3aa75d 100755 --- a/tools/cfn2ts/bin/cfn2ts.ts +++ b/tools/cfn2ts/bin/cfn2ts.ts @@ -1,20 +1,43 @@ #!/usr/bin/env node -import 'source-map-support/register'; - +import fs = require('fs-extra'); import yargs = require('yargs'); import generate from '../lib'; -// tslint:disable-next-line:no-unused-expression -const argv = - yargs.usage('Usage: cfn2ts') - .option('scope', { type: 'string', desc: 'Scope to generate TypeScript for (e.g: AWS::IAM)', required: true }) +// tslint:disable:no-console +// tslint:disable:max-line-length + +async function main() { + const argv = yargs.usage('Usage: cfn2ts') + .option('scope', { type: 'string', desc: 'Scope to generate TypeScript for (e.g: AWS::IAM)' }) .option('out', { type: 'string', desc: 'Path to the directory where the TypeScript files should be written', default: 'lib' }) - .option('force', { type: 'boolean', desc: 'Generate the spec even if it appears up-to-date', default: false }) + .epilog('if --scope is not defined, cfn2ts will try to obtain the scope from the local package.json under the "cdk-build.cloudformation" key.') .argv; -generate(argv.scope, argv.out, argv.force).catch(err => { - // tslint:disable:no-console + if (!argv.scope) { + argv.scope = await tryAutoDetectScope(); + } + + if (!argv.scope) { + throw new Error(`--scope is not provided and cannot be auto-detected from package.json (under "cdk-build.cloudformation")`); + } + + await generate(argv.scope, argv.out); +} + +main().catch(err => { console.error(err); - // tslint:enable:no-console process.exit(1); }); + +async function tryAutoDetectScope() { + if (!await fs.pathExists('./package.json')) { + return undefined; + } + + const pkg = await fs.readJSON('./package.json'); + if (!pkg['cdk-build']) { + return undefined; + } + + return pkg['cdk-build'].cloudformation; +} diff --git a/tools/cfn2ts/lib/codegen.ts b/tools/cfn2ts/lib/codegen.ts index 63a65507d666c..03e0a33f52ff6 100644 --- a/tools/cfn2ts/lib/codegen.ts +++ b/tools/cfn2ts/lib/codegen.ts @@ -74,7 +74,7 @@ export default class CodeGenerator { const legacyResourceName = genspec.CodeName.forLegacyResource(cfnName); this.code.line(); - const attributeTypes = this.emitResourceType(resourceName, resourceType); + this.emitResourceType(resourceName, resourceType); this.emitPropertyTypes(name, resourceName); // emit the "cloudformation.XxxResource" classes for backwards compatibility @@ -84,10 +84,6 @@ export default class CodeGenerator { this.emitResourceType(legacyResourceName, resourceType, resourceName); this.emitPropertyTypes(name, legacyResourceName); this.code.closeBlock(); - - for (const attributeType of attributeTypes) { - this.emitAttributeType(attributeType); - } } } @@ -177,7 +173,7 @@ export default class CodeGenerator { } } - private emitResourceType(resourceName: genspec.CodeName, spec: schema.ResourceType, deprecated?: genspec.CodeName) { + private emitResourceType(resourceName: genspec.CodeName, spec: schema.ResourceType, deprecated?: genspec.CodeName): void { this.beginNamespace(resourceName); // @@ -215,7 +211,6 @@ export default class CodeGenerator { // Attributes // - const attributeTypes = new Array(); const attributes = new Array(); if (spec.Attributes) { @@ -227,10 +222,9 @@ export default class CodeGenerator { this.docLink(undefined, `@cloudformation_attribute ${attributeName}`); const attr = genspec.attributeDefinition(resourceName, attributeName, attributeSpec); - this.code.line(`public readonly ${attr.propertyName}: ${attr.attributeType.typeName.className};`); + this.code.line(`public readonly ${attr.propertyName}: ${attr.attributeType};`); attributes.push(attr); - attributeTypes.push(attr.attributeType); } } @@ -242,9 +236,8 @@ export default class CodeGenerator { // If there's already an attribute with the same name, ref is not needed if (!attributes.some(a => a.propertyName === refAttribute.propertyName)) { - this.code.line(`public readonly ${refAttribute.propertyName}: ${refAttribute.attributeType.typeName.className};`); + this.code.line(`public readonly ${refAttribute.propertyName}: ${refAttribute.attributeType};`); attributes.push(refAttribute); - attributeTypes.push(refAttribute.attributeType); } } @@ -286,14 +279,12 @@ export default class CodeGenerator { // initialize all attribute properties for (const at of attributes) { - if (at.attributeType.isPrimitive) { - if (at.attributeType.typeName.className === 'string') { - this.code.line(`this.${at.propertyName} = ${at.constructorArguments}.toString();`); - } else { - throw new Error(`Unsupported primitive attribute type ${at.attributeType.typeName.className}`); - } - } else { - this.code.line(`this.${at.propertyName} = new ${at.attributeType.typeName.className}(${at.constructorArguments});`); + if (at.attributeType === 'string') { + this.code.line(`this.${at.propertyName} = ${at.constructorArguments}.toString();`); + } else if (at.attributeType === 'string[]') { + this.code.line(`this.${at.propertyName} = ${at.constructorArguments}.toList();`); + } else if (at.attributeType === genspec.TOKEN_NAME.fqn) { + this.code.line(`this.${at.propertyName} = ${at.constructorArguments};`); } } @@ -315,8 +306,6 @@ export default class CodeGenerator { this.closeClass(resourceName); this.endNamespace(resourceName); - - return attributeTypes; } /** @@ -486,26 +475,6 @@ export default class CodeGenerator { this.code.closeBlock(); } - /** - * Attribute types are classes that represent resource attributes (e.g. QueueArnAttribute). - */ - private emitAttributeType(attr: genspec.AttributeTypeDeclaration) { - if (!attr.baseClassName) { - return; // primitive, no attribute type generated - } - - this.code.line(); - this.openClass(attr.typeName, attr.docLink, attr.baseClassName.fqn); - // Add a private member that will make the class structurally - // different in TypeScript, which prevents assigning returning - // incorrectly-typed Tokens. Those will cause ClassCastExceptions - // in strictly-typed languages. - this.code.line('// @ts-ignore: private but unused on purpose.'); - this.code.line(`private readonly thisIsA${attr.typeName.className} = true;`); - - this.closeClass(attr.typeName); - } - private emitProperty(context: genspec.CodeName, propName: string, spec: schema.Property, additionalDocs: string): string { const question = spec.Required ? '' : '?'; const javascriptPropertyName = genspec.cloudFormationToScriptName(propName); @@ -596,8 +565,14 @@ export default class CodeGenerator { alternatives.push(this.renderTypeUnion(resourceContext, types)); } - // Always - alternatives.push(genspec.TOKEN_NAME.fqn); + // Only if this property is not of a "tokenizable type" (string, string[], + // number in the future) we add a type union for `cdk.Token`. We rather + // everything to be tokenizable because there are languages that do not + // support union types (i.e. Java, .NET), so we lose type safety if we have + // a union. + if (!tokenizableType(alternatives)) { + alternatives.push(genspec.TOKEN_NAME.fqn); + } return alternatives.join(' | '); } @@ -649,3 +624,22 @@ function mapperNames(types: genspec.CodeName[]): string { function quoteCode(code: string): string { return '``' + code + '``'; } + +function tokenizableType(alternatives: string[]) { + if (alternatives.length > 1) { + return false; + } + + const type = alternatives[0]; + if (type === 'string') { + return true; + } + + if (type === 'string[]') { + return true; + } + + // TODO: number + + return false; +} \ No newline at end of file diff --git a/tools/cfn2ts/lib/genspec.ts b/tools/cfn2ts/lib/genspec.ts index e63444f3b7db3..5ea5fed035ba3 100644 --- a/tools/cfn2ts/lib/genspec.ts +++ b/tools/cfn2ts/lib/genspec.ts @@ -102,22 +102,6 @@ export class CodeName { } } -/** - * Class declaration - */ -export class AttributeTypeDeclaration { - constructor( - readonly typeName: CodeName, - readonly baseClassName?: CodeName, - readonly docLink?: string - ) { - } - - public get isPrimitive() { - return !this.baseClassName; - } -} - export const TAG_NAME = new CodeName('', CORE_NAMESPACE, 'Tag'); export const TOKEN_NAME = new CodeName('', CORE_NAMESPACE, 'Token'); @@ -127,7 +111,7 @@ export const TOKEN_NAME = new CodeName('', CORE_NAMESPACE, 'Token'); export class Attribute { constructor( readonly propertyName: string, - readonly attributeType: AttributeTypeDeclaration, + readonly attributeType: string, readonly constructorArguments: string) { } } @@ -192,13 +176,15 @@ export function attributeDefinition(resourceName: CodeName, attributeName: strin const descriptiveName = descriptiveAttributeName(resourceName, attributeName); // "BucketArn" const propertyName = cloudFormationToScriptName(descriptiveName); // "bucketArn" - let attrType; + let attrType: string; if ('PrimitiveType' in spec && spec.PrimitiveType === 'String') { - attrType = new AttributeTypeDeclaration(CodeName.forPrimitive('string')); + attrType = 'string'; + } else if ('Type' in spec && 'PrimitiveItemType' in spec && spec.Type === 'List' && spec.PrimitiveItemType === 'String') { + attrType = 'string[]'; } else { - // Not in a namespace, base the name on the descriptive name - const typeName = new CodeName(resourceName.packageName, '', descriptiveName); // "BucketArn" - attrType = new AttributeTypeDeclaration(typeName, TOKEN_NAME, undefined); + // tslint:disable-next-line:no-console + console.error(`WARNING: Unable to represent attribute type ${JSON.stringify(spec)} as a native type`); + attrType = TOKEN_NAME.fqn; } const constructorArguments = `this.getAtt('${attributeName}')`; @@ -213,8 +199,7 @@ export function refAttributeDefinition(resourceName: CodeName, refKind: string): const constructorArguments = 'this.ref'; - const refType = new AttributeTypeDeclaration(CodeName.forPrimitive('string')); - return new Attribute(propertyName, refType, constructorArguments); + return new Attribute(propertyName, 'string', constructorArguments); } /** diff --git a/tools/cfn2ts/lib/index.ts b/tools/cfn2ts/lib/index.ts index d06c845b6ec6f..3d38b29efc662 100644 --- a/tools/cfn2ts/lib/index.ts +++ b/tools/cfn2ts/lib/index.ts @@ -1,11 +1,9 @@ import cfnSpec = require('@aws-cdk/cfnspec'); -import colors = require('colors/safe'); import fs = require('fs-extra'); -import path = require('path'); import CodeGenerator from './codegen'; import { packageName } from './genspec'; -export default async function(scope: string, outPath: string, force: boolean) { +export default async function(scope: string, outPath: string) { if (outPath !== '.') { await fs.mkdirp(outPath); } const spec = cfnSpec.filteredSpecification(s => s.startsWith(`${scope}::`)); @@ -15,15 +13,7 @@ export default async function(scope: string, outPath: string, force: boolean) { const name = packageName(scope); const generator = new CodeGenerator(name, spec); - - if (!force && await generator.upToDate(outPath)) { - // tslint:disable-next-line:no-console - console.log('Generated code already up-to-date: %s', colors.green(path.join(outPath, generator.outputFile))); - return; - } generator.emitCode(); - // tslint:disable-next-line:no-console - console.log('Generated code: %s', colors.green(path.join(outPath, generator.outputFile))); await generator.save(outPath); } diff --git a/tools/cfn2ts/package.json b/tools/cfn2ts/package.json index 57958466d3a7a..a2d02d096b2b3 100644 --- a/tools/cfn2ts/package.json +++ b/tools/cfn2ts/package.json @@ -32,10 +32,8 @@ "dependencies": { "@aws-cdk/cfnspec": "^0.21.0", "codemaker": "^0.6.4", - "colors": "^1.2.1", "fast-json-patch": "^2.0.6", "fs-extra": "^7.0.0", - "source-map-support": "^0.5.6", "yargs": "^9.0.1" }, "devDependencies": { diff --git a/tools/pkglint/lib/rules.ts b/tools/pkglint/lib/rules.ts index 4e6a6649fe5de..c0cc3775933e9 100644 --- a/tools/pkglint/lib/rules.ts +++ b/tools/pkglint/lib/rules.ts @@ -680,10 +680,30 @@ export class AwsLint extends ValidationRule { return; } + if (!isAWS(pkg)) { + return; + } + expectJSON(this.name, pkg, 'scripts.awslint', 'cdk-awslint'); } } +export class Cfn2Ts extends ValidationRule { + public name = 'cfn2ts'; + + public validate(pkg: PackageJson) { + if (!isJSII(pkg)) { + return; + } + + if (!isAWS(pkg)) { + return; + } + + expectJSON(this.name, pkg, 'scripts.cfn2ts', 'cfn2ts'); + } +} + /** * Determine whether this is a JSII package * @@ -693,6 +713,14 @@ function isJSII(pkg: PackageJson): boolean { return pkg.json.jsii; } +/** + * Indicates that this is an "AWS" package (i.e. that it it has a cloudformation source) + * @param pkg + */ +function isAWS(pkg: PackageJson): boolean { + return pkg.json['cdk-build'] && pkg.json['cdk-build'].cloudformation; +} + /** * Determine whether the package has tests *