Skip to content

Commit

Permalink
fix: update deps and correctly map resource/property names (#129)
Browse files Browse the repository at this point in the history
This PR does a couple of different things. I was originally going to try
and split it into multiple PRs, but there were too many dependencies
between the changes

1. switches the test runner from `mocha` to `jest` to align with our
other node based projects (like `awsx`).
2. Added some tests for
[cfn-resource-mappings](https://github.com/pulumi/pulumi-cdk/blob/main/src/cfn-resource-mappings.ts)
and
[aws-resource-mappings](https://github.com/pulumi/pulumi-cdk/blob/main/src/aws-resource-mappings.ts)
3. Update dependencies to newest versions
- Also moved `@pulumi/*` and `aws-cdk` dependencies from `dependencies`
to `peerDependencies` which allows users to determine which versions
they want to install.
3a. As part of the dependency updates had to fix some of the mappings
- Update `iam.Role` mapping to correctly map the `Policies` property.
- Update `s3objectlambda.AccessPoint` to correctly map
`contentTransformation` properties.
    - Update `autoscaling.Group` properties correctly
    - Update `ec2.Route` properties (remove `instanceId` prop)
4. Implement a TypeScript version of the
[naming](https://github.com/pulumi/pulumi-aws-native/blob/master/provider/pkg/naming/naming.go)
package from `aws-native` so that we will more reliably map
resource/property names between CFN and pulumi.

**Note on peerDependencies**
peerDependencies allow us to specify a minimum required version that
works with our library and then the user can decide which version to
install. I think as we (or the community) develops more component
libraries it might be more important to use peerDependencies. When there
are multiple libraries that all depend on some core library and they all
specify the core library as a `dependency` then there will be multiple
versions of that core library installed. Sometimes this can cause
incompatibility between libraries. The article below goes into some more
detail.


[dev.to/aws-builders/correctly-defining-dependencies-in-l3-cdk-constructs-45p](https://dev.to/aws-builders/correctly-defining-dependencies-in-l3-cdk-constructs-45p)
  • Loading branch information
corymhall authored Jun 11, 2024
1 parent 9718073 commit d14001d
Show file tree
Hide file tree
Showing 28 changed files with 5,152 additions and 1,357 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'prettier',
],
rules: {
// disabling this since it is used everywhere in this repo
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "warn"
}
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ dist

# IntelliJ
.idea/

test-reports/
lib/
11 changes: 6 additions & 5 deletions examples/alb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ import * as aws from '@pulumi/aws';
import { Construct } from 'constructs';

class AlbStack extends pulumicdk.Stack {

url: pulumi.Output<string>;

constructor(id: string, options?: pulumicdk.StackOptions) {
super(id, options);
// necessary for local testing
const t = this as any;

const vpc = new ec2.Vpc(this, 'VPC');
const vpc = new ec2.Vpc(t, 'VPC');

const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
const asg = new autoscaling.AutoScalingGroup(t, 'ASG', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage(),
});

const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', {
const lb = new elbv2.ApplicationLoadBalancer(t, 'LB', {
vpc,
internetFacing: true,
});
Expand Down
2 changes: 1 addition & 1 deletion examples/alb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
2 changes: 1 addition & 1 deletion examples/api-websocket-lambda-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
2 changes: 1 addition & 1 deletion examples/apprunner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/awsx": "^0.32.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111",
Expand Down
2 changes: 1 addition & 1 deletion examples/appsvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.16.0",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
2 changes: 1 addition & 1 deletion examples/cron-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/awsx": "^0.32.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
2 changes: 1 addition & 1 deletion examples/ec2-instance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
2 changes: 1 addition & 1 deletion examples/ecscluster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.16.1",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
2 changes: 1 addition & 1 deletion examples/fargate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^4.6.0",
"@pulumi/aws-native": "^0.70.0",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
Expand Down
97 changes: 75 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,91 @@
},
"devDependencies": {
"@aws-cdk/aws-apprunner-alpha": "2.20.0-alpha.0",
"@types/archiver": "^5.3.1",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.0",
"@types/node": "^14.17.0",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"chai": "^4.3.6",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"mocha": "^9.2.2",
"@pulumi/aws": "^6.32.0",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/docker": "^4.5.0",
"@pulumi/pulumi": "^3.117.0",
"@types/archiver": "^6.0.2",
"@types/jest": "^29.5.2",
"@types/node": "^20.12.13",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111",
"eslint": "^8",
"eslint-config-prettier": "^9.1.0",
"jest": "^29.5.0",
"jest-junit": "^15",
"prettier": "^2.6.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
"ts-jest": "^29.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
},
"peerDependencies": {
"@pulumi/aws": "^6.32.0",
"@pulumi/aws-native": "^0.108.0",
"@pulumi/docker": "^4.5.0",
"@pulumi/pulumi": "^3.117.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
},
"dependencies": {
"@types/glob": "^8.1.0",
"archiver": "^7.0.1"
},
"scripts": {
"build": "tsc && cp package.json README.md LICENSE lib/ && sed -i.bak -e \"s/\\${VERSION}/$(pulumictl get version --language javascript)/g\" lib/package.json && rm lib/package.json.bak",
"lint": "./node_modules/.bin/eslint src --ext .js,.jsx,.ts,.tsx",
"lint": "./node_modules/.bin/eslint --ext .js,.jsx,.ts,.tsx --fix --no-error-on-unmatched-pattern src",
"format": "./node_modules/.bin/prettier --write \"src/**/*.ts\" \"examples/**/*.ts\"",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'tests/**/*.ts'",
"test": "jest --passWithNoTests --updateSnapshot",
"test-examples": "cd lib && yarn link && cd .. && cd examples && go test -timeout 2h -v .",
"test-examples-gotestfmt": "cd lib && yarn link && cd .. && cd examples && set -euo pipefail && go test -json -v -count=1 -cover -timeout 2h -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt"
},
"files": [
"*"
],
"dependencies": {
"@pulumi/aws": "^5.5.0",
"@pulumi/aws-native": "^0.18.0",
"@pulumi/docker": "^3.2.0",
"@pulumi/pulumi": "^3.28.0",
"archiver": "^5.3.1",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
"jest": {
"transform": {
"^.+\\.ts$": [
"ts-jest",
{
"isolatedModules": true,
"tsconfig": "tsconfig.json"
}
]
},
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.ts?(x)",
"<rootDir>/(tests|src)/**/*(*.)@(spec|test).ts?(x)"
],
"clearMocks": true,
"collectCoverage": true,
"coverageReporters": [
"json",
"lcov",
"clover",
"cobertura",
"text"
],
"coverageDirectory": "coverage",
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"watchPathIgnorePatterns": [
"/node_modules/"
],
"reporters": [
"default",
[
"jest-junit",
{
"outputDirectory": "test-reports"
}
]
],
"preset": "ts-jest"
}
}
Loading

0 comments on commit d14001d

Please sign in to comment.