Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: throw a better error message for unsupported CCAPI resources #311

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions integration/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,18 @@ func TestKinesis(t *testing.T) {

integration.ProgramTest(t, &test)
}

func TestUnsupportedError(t *testing.T) {
var output bytes.Buffer

test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "unsupported-error"),
Stderr: &output,
SkipPreview: true,
ExpectFailure: true,
})

integration.ProgramTest(t, &test)
assert.Contains(t, output.String(), "Resource type 'AWS::ServiceCatalog::Portfolio' is not supported by AWS Cloud Control.")
}
3 changes: 3 additions & 0 deletions integration/unsupported-error/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: pulumi-aws-unsupported
runtime: nodejs
description: unsupported error integration test
20 changes: 20 additions & 0 deletions integration/unsupported-error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as pulumi from '@pulumi/pulumi';
import * as pulumicdk from '@pulumi/cdk';
import * as servicecatalog from 'aws-cdk-lib/aws-servicecatalog';

const config = new pulumi.Config();
const prefix = config.get('prefix') ?? pulumi.getStack();
class UnsupportedErrorStack extends pulumicdk.Stack {
constructor(app: pulumicdk.App, id: string, options?: pulumicdk.StackOptions) {
super(app, id, options);
new servicecatalog.Portfolio(this, 'Portfolio', {
displayName: 'test',
providerName: 'test',
description: 'test',
});
}
}

new pulumicdk.App('app', (scope: pulumicdk.App) => {
new UnsupportedErrorStack(scope, `${prefix}-unsupported`);
});
15 changes: 15 additions & 0 deletions integration/unsupported-error/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "pulumi-aws-cdk",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/aws": "6.66.0",
"@pulumi/aws-native": "1.18.0",
"@pulumi/cdk": "1.4.0",
"@pulumi/pulumi": "3.144.1",
"aws-cdk-lib": "2.149.0",
"constructs": "10.3.0",
"esbuild": "^0.24.0"
}
}
18 changes: 18 additions & 0 deletions integration/unsupported-error/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2019",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./*.ts"
]
}
3,111 changes: 3,111 additions & 0 deletions integration/unsupported-error/yarn.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/cfn-resource-mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import * as pulumi from '@pulumi/pulumi';
import { getAttributesFromResource } from './types';
import { CdkAdapterError, getAttributesFromResource } from './types';
import * as aws from '@pulumi/aws-native';
import { ResourceMapping, normalize } from './interop';
import { debug } from '@pulumi/pulumi/log';
Expand Down Expand Up @@ -122,6 +122,13 @@ export function mapToCfnResource(
const mName = moduleName(typeName).toLowerCase();
const pType = pulumiTypeName(typeName);
const awsModule = aws as any;
if (!awsModule[mName] || !awsModule[mName][pType]) {
throw new CdkAdapterError(
`Resource type '${typeName}' is not supported by AWS Cloud Control. ` +
'To map this resource to an AWS Provider resource, see the documentation ' +
'here: https://github.com/pulumi/pulumi-cdk#mapping-aws-resources',
);
}

return new awsModule[mName][pType](logicalId, props, options);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/cfn-resource-mappings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,26 @@ describe('Cfn Resource Mappings', () => {
{},
);
});

test('throws an error if module not supported', () => {
// GIVEN
const cfnType = 'AWS::Not::Supported';
const logicalId = 'my-resource';
const cfnProps = {};
// WHEN
expect(() => mapToCfnResource(logicalId, cfnType, cfnProps, {})).toThrow(
/Resource type 'AWS::Not::Supported' is not supported by AWS Cloud Control./,
);
});

test('throws an error if resource not supported', () => {
// GIVEN
const cfnType = 'AWS::S3::NotSupported';
const logicalId = 'my-resource';
const cfnProps = {};
// WHEN
expect(() => mapToCfnResource(logicalId, cfnType, cfnProps, {})).toThrow(
/Resource type 'AWS::S3::NotSupported' is not supported by AWS Cloud Control./,
);
});
});
Loading