Skip to content

Commit

Permalink
Merge pull request #2630 from hashicorp/fix-license-resource-collision
Browse files Browse the repository at this point in the history
fix(provider-generator): fix resources named 'license' causing collisions with LICENSE file on case-insensitive filesystems for Go packages
  • Loading branch information
mutahhir authored Apr 18, 2023
2 parents 49454d8 + 4aaf5f2 commit bc04e38
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1902,10 +1902,98 @@ export * as objectResource from './object-resource';
export * as functionResource from './function-resource';
export * as staticResource from './static-resource';
export * as providerResource from './provider-resource';
export * as licenseResource from './license-resource';
"
`;
exports[`incompatible resource names: license-resource 1`] = `
"// https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/license
// generated from terraform resource schema
import { Construct } from 'constructs';
import * as cdktf from 'cdktf';
// Configuration
export interface LicenseResourceConfig extends cdktf.TerraformMetaArguments {
/**
* Docs at Terraform Registry: {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/license#dummy LicenseResource#dummy}
*/
readonly dummy?: string;
}
/**
* Represents a {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/license test_license}
*/
export class LicenseResource extends cdktf.TerraformResource {
// =================
// STATIC PROPERTIES
// =================
public static readonly tfResourceType = "test_license";
// ===========
// INITIALIZER
// ===========
/**
* Create a new {@link https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/license test_license} Resource
*
* @param scope The scope in which to define this construct
* @param id The scoped construct ID. Must be unique amongst siblings in the same scope
* @param options LicenseResourceConfig = {}
*/
public constructor(scope: Construct, id: string, config: LicenseResourceConfig = {}) {
super(scope, id, {
terraformResourceType: 'test_license',
terraformGeneratorMetadata: {
providerName: 'test'
},
provider: config.provider,
dependsOn: config.dependsOn,
count: config.count,
lifecycle: config.lifecycle,
provisioners: config.provisioners,
connection: config.connection,
forEach: config.forEach
});
this._dummy = config.dummy;
}
// ==========
// ATTRIBUTES
// ==========
// dummy - computed: false, optional: true, required: false
private _dummy?: string;
public get dummy() {
return this.getStringAttribute('dummy');
}
public set dummy(value: string) {
this._dummy = value;
}
public resetDummy() {
this._dummy = undefined;
}
// Temporarily expose input value. Use with caution.
public get dummyInput() {
return this._dummy;
}
// =========
// SYNTHESIS
// =========
protected synthesizeAttributes(): { [name: string]: any } {
return {
dummy: cdktf.stringToTerraform(this._dummy),
};
}
}
"
`;
exports[`incompatible resource names: object-resource 1`] = `
"// https://registry.terraform.io/providers/hashicorp/test/latest/docs/resources/object
// generated from terraform resource schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
}
},
"block_types": {}
},
"test_license": {
"version": 1,
"block": {
"attributes": {
"dummy": {
"type": "string",
"optional": true
}
}
},
"block_types": {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ test("incompatible resource names", async () => {
[
"function-resource",
"index.ts",
"license-resource",
"object-resource",
"provider-resource",
"static-resource",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ const RESERVED_KEYWORDS_FOR_NAMESPACES = [
"await",
];

const COLLIDING_NAMESPACE_NAMES = [
// e.g. hashicorp/consul – collides with the LICENSE file on case-insensitive filesystems in the Go package (#2627)
"license",
];

const isReservedClassOrNamespaceName = (className: string): boolean => {
return [
"string",
"object",
"function",
...RESERVED_KEYWORDS_FOR_NAMESPACES,
...COLLIDING_NAMESPACE_NAMES,
].includes(className.toLowerCase());
};

Expand Down

0 comments on commit bc04e38

Please sign in to comment.