@terraforge/terraform 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/cli/build-package.ts +31 -9
- package/dist/index.d.ts +7 -2
- package/dist/index.js +52 -42
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,6 +3,59 @@
|
|
|
3
3
|
|
|
4
4
|
This package is used to build Terraform bridge packages that can be used with @terraforge/core.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
It works in 3 steps:
|
|
7
|
+
|
|
8
|
+
1. It provides a build script that generates the typescript typings for your Terraform bridge package.
|
|
9
|
+
|
|
10
|
+
2. It provides a proxy api that can we used to interact with Terraform resources.
|
|
11
|
+
|
|
12
|
+
3. It will install the Terraform provider that you specify in your bridge package.
|
|
13
|
+
|
|
14
|
+
### Terraform Plugin installation location
|
|
7
15
|
|
|
8
16
|
The default installation location is `~/.terraforge/plugins`.
|
|
17
|
+
|
|
18
|
+
## Usage Guide
|
|
19
|
+
|
|
20
|
+
### Step 1. Create a package.json
|
|
21
|
+
Create a package.json for the bridge package you want to create.
|
|
22
|
+
In the `package.json` file, you will need to specify the provider details that your package is for.
|
|
23
|
+
Example:
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"name": "@terraforge/aws",
|
|
27
|
+
"version": "1.0.0",
|
|
28
|
+
"provider": { // These are the terraform provider details that your package is for.
|
|
29
|
+
"org": "hashicorp",
|
|
30
|
+
"type": "aws",
|
|
31
|
+
"version": "1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"type": "module",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"module": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"import": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "bun ../terraform/cli/build-package",
|
|
47
|
+
"prepublishOnly": "bun run build"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@terraforge/terraform": "workspace:*",
|
|
51
|
+
"@terraforge/core": "workspace:*"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Step 2. Publish your package
|
|
57
|
+
You can now publish your package to npm or any other package registry.
|
|
58
|
+
The prepublish script will build the package files inside the `dist` directory before publishing.
|
|
59
|
+
|
|
60
|
+
### Step 3. There is no step 3
|
|
61
|
+
Sit back and relax, your package is now published and ready to be used.
|
package/cli/build-package.ts
CHANGED
|
@@ -65,18 +65,39 @@ console.log('')
|
|
|
65
65
|
console.log('Loading provider plugin...')
|
|
66
66
|
|
|
67
67
|
const plugin = await load()
|
|
68
|
+
|
|
69
|
+
console.log('Provider plugin loaded.')
|
|
70
|
+
|
|
68
71
|
const schema = plugin.schema()
|
|
69
|
-
const types = generateTypes(
|
|
70
|
-
{
|
|
71
|
-
[type]: schema.provider,
|
|
72
|
-
},
|
|
73
|
-
schema.resources,
|
|
74
|
-
schema.dataSources
|
|
75
|
-
)
|
|
76
72
|
|
|
77
73
|
await plugin.stop()
|
|
78
74
|
|
|
79
|
-
|
|
75
|
+
// const installTypes = generateInstallHelperFunctions(type)
|
|
76
|
+
// await Bun.write(`./dist/install.d.ts`, installTypes)
|
|
77
|
+
|
|
78
|
+
// const providerTypes = generateProviderFactoryTypes(type, schema.provider)
|
|
79
|
+
// await Bun.write(`./dist/provider.d.ts`, providerTypes)
|
|
80
|
+
|
|
81
|
+
// const resourceTypes = generateResourceTypes(schema.resources)
|
|
82
|
+
// await Bun.write(`./dist/resources.d.ts`, resourceTypes)
|
|
83
|
+
|
|
84
|
+
// const dataSourceTypes = generateResourceTypes(schema.dataSources)
|
|
85
|
+
// await Bun.write(`./dist/data-sources.d.ts`, dataSourceTypes)
|
|
86
|
+
|
|
87
|
+
// await Bun.write(
|
|
88
|
+
// `./dist/index.d.ts`,
|
|
89
|
+
// `
|
|
90
|
+
// /// <reference path="./install.d.ts" />
|
|
91
|
+
// /// <reference path="./provider.d.ts" />
|
|
92
|
+
// /// <reference path="./resources.d.ts" />
|
|
93
|
+
// /// <reference path="./data-sources.d.ts" />
|
|
94
|
+
|
|
95
|
+
// export { aws }
|
|
96
|
+
// `
|
|
97
|
+
// )
|
|
98
|
+
|
|
99
|
+
await Bun.write(`./dist/index.d.ts`, generateTypes(type, schema.provider, schema.resources, schema.dataSources))
|
|
100
|
+
|
|
80
101
|
await Bun.write(
|
|
81
102
|
`./dist/index.js`,
|
|
82
103
|
`
|
|
@@ -89,5 +110,6 @@ export const ${type} = createTerraformProxy({
|
|
|
89
110
|
`
|
|
90
111
|
)
|
|
91
112
|
|
|
92
|
-
console.log('
|
|
113
|
+
console.log('')
|
|
114
|
+
console.log('Package done building.')
|
|
93
115
|
process.exit(0)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider, State as State$1, GetProps, CreateProps, UpdateProps, DeleteProps, GetDataProps } from '@terraforge/core';
|
|
1
|
+
import { Provider, State as State$1, GetProps, CreateProps, UpdateProps, DeleteProps, PlanProps, GetDataProps } from '@terraforge/core';
|
|
2
2
|
|
|
3
3
|
type Property = {
|
|
4
4
|
description?: string;
|
|
@@ -20,7 +20,7 @@ type Property = {
|
|
|
20
20
|
type: 'unknown';
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
declare const generateTypes: (
|
|
23
|
+
declare const generateTypes: (namespace: string, provider: Property, resources: Record<string, Property>, dataSources: Record<string, Property>) => string;
|
|
24
24
|
|
|
25
25
|
type State = Record<string, unknown>;
|
|
26
26
|
type Plugin = Readonly<{
|
|
@@ -66,6 +66,11 @@ declare class TerraformProvider implements Provider {
|
|
|
66
66
|
state: State;
|
|
67
67
|
}>;
|
|
68
68
|
deleteResource({ type, state }: DeleteProps): Promise<void>;
|
|
69
|
+
planResourceChange({ type, priorState, proposedState }: PlanProps): Promise<{
|
|
70
|
+
version: number;
|
|
71
|
+
requiresReplacement: boolean;
|
|
72
|
+
state: State;
|
|
73
|
+
}>;
|
|
69
74
|
getData({ type, state }: GetDataProps): Promise<{
|
|
70
75
|
state: State;
|
|
71
76
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -3,56 +3,57 @@ import { camelCase, pascalCase } from "change-case";
|
|
|
3
3
|
var tab = (indent) => {
|
|
4
4
|
return " ".repeat(indent);
|
|
5
5
|
};
|
|
6
|
-
var generateTypes = (
|
|
6
|
+
var generateTypes = (namespace, provider, resources, dataSources) => {
|
|
7
7
|
return [
|
|
8
8
|
generateImport("c", "@terraforge/core"),
|
|
9
9
|
generateImport("t", "@terraforge/terraform"),
|
|
10
10
|
"type _Record<T> = Record<string, T>",
|
|
11
|
-
generateInstallHelperFunctions(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}),
|
|
16
|
-
generateNamespace(resources, (name, prop, indent) => {
|
|
17
|
-
const typeName = pascalCase(name);
|
|
18
|
-
return [
|
|
19
|
-
// `${tab(indent)}export type ${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
20
|
-
// `${tab(indent)}export type ${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
21
|
-
// `${tab(indent)}export declare const ${typeName}: ResourceClass<${typeName}Input, ${typeName}Output>`,
|
|
22
|
-
`${tab(indent)}export type ${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
23
|
-
`${tab(indent)}export type ${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
24
|
-
`${tab(indent)}export class ${typeName} {`,
|
|
25
|
-
`${tab(indent + 1)}constructor(parent: c.Group, id: string, props: ${typeName}Input, config?:c.ResourceConfig)`,
|
|
26
|
-
// `${tab(indent + 1)}readonly $: c.ResourceMeta<${typeName}Input, ${typeName}Output>`,
|
|
27
|
-
generateClassProperties(prop, indent + 1),
|
|
28
|
-
`${tab(indent)}}`
|
|
29
|
-
].join("\n\n");
|
|
30
|
-
}),
|
|
31
|
-
generateNamespace(dataSources, (name, prop, indent) => {
|
|
32
|
-
const typeName = pascalCase(name);
|
|
33
|
-
return [
|
|
34
|
-
`${tab(indent)}export type Get${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
35
|
-
`${tab(indent)}export type Get${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
36
|
-
`${tab(indent)}export const get${typeName}:c.DataSourceFunction<Get${typeName}Input, Get${typeName}Output>`
|
|
37
|
-
].join("\n\n");
|
|
38
|
-
})
|
|
11
|
+
generateInstallHelperFunctions(namespace),
|
|
12
|
+
generateProviderFactoryTypes(namespace, provider),
|
|
13
|
+
generateResourceTypes(resources),
|
|
14
|
+
generateDataSourceTypes(dataSources)
|
|
39
15
|
].join("\n\n");
|
|
40
16
|
};
|
|
41
|
-
var
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
var generateInstallHelperFunctions = (resources) => {
|
|
45
|
-
return generateNamespace(resources, (name, _prop, indent) => {
|
|
46
|
-
const typeName = name.toLowerCase();
|
|
17
|
+
var generateResourceTypes = (resources) => {
|
|
18
|
+
return generateNamespace(resources, (name, prop, indent) => {
|
|
19
|
+
const typeName = pascalCase(name);
|
|
47
20
|
return [
|
|
48
|
-
`${tab(indent)}export
|
|
49
|
-
`${tab(indent
|
|
50
|
-
`${tab(indent
|
|
51
|
-
`${tab(indent + 1)}
|
|
21
|
+
`${tab(indent)}export type ${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
22
|
+
`${tab(indent)}export type ${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
23
|
+
`${tab(indent)}export class ${typeName} {`,
|
|
24
|
+
`${tab(indent + 1)}constructor(parent: c.Group, id: string, props: ${typeName}Input, config?:c.ResourceConfig)`,
|
|
25
|
+
generateClassProperties(prop, indent + 1),
|
|
52
26
|
`${tab(indent)}}`
|
|
53
|
-
].join("\n");
|
|
27
|
+
].join("\n\n");
|
|
54
28
|
});
|
|
55
29
|
};
|
|
30
|
+
var generateDataSourceTypes = (dataSources) => {
|
|
31
|
+
return generateNamespace(dataSources, (name, prop, indent) => {
|
|
32
|
+
const typeName = pascalCase(name);
|
|
33
|
+
return [
|
|
34
|
+
`${tab(indent)}export type Get${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
35
|
+
`${tab(indent)}export type Get${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
36
|
+
`${tab(indent)}export const get${typeName}:c.DataSourceFunction<Get${typeName}Input, Get${typeName}Output>`
|
|
37
|
+
].join("\n\n");
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var generateProviderFactoryTypes = (namespace, provider) => {
|
|
41
|
+
const typeName = namespace.toLowerCase();
|
|
42
|
+
return `export declare function ${typeName}(props: ${generatePropertyInputConst(provider, 0)}, config?: t.TerraformProviderConfig): t.TerraformProvider`;
|
|
43
|
+
};
|
|
44
|
+
var generateImport = (name, from) => {
|
|
45
|
+
return `import * as ${name} from '${from}'`;
|
|
46
|
+
};
|
|
47
|
+
var generateInstallHelperFunctions = (namespace) => {
|
|
48
|
+
const typeName = namespace.toLowerCase();
|
|
49
|
+
return [
|
|
50
|
+
`export declare namespace ${typeName} {`,
|
|
51
|
+
`${tab(1)}export function install(props?: t.InstallProps): Promise<void>`,
|
|
52
|
+
`${tab(1)}export function uninstall(props?: t.InstallProps): Promise<void>`,
|
|
53
|
+
`${tab(1)}export function isInstalled(props?: t.InstallProps): Promise<boolean>`,
|
|
54
|
+
`}`
|
|
55
|
+
].join("\n");
|
|
56
|
+
};
|
|
56
57
|
var generatePropertyInputConst = (prop, indent) => {
|
|
57
58
|
return generateValue(prop, {
|
|
58
59
|
depth: 0,
|
|
@@ -284,6 +285,15 @@ var TerraformProvider = class {
|
|
|
284
285
|
throw error;
|
|
285
286
|
}
|
|
286
287
|
}
|
|
288
|
+
async planResourceChange({ type, priorState, proposedState }) {
|
|
289
|
+
const plugin = await this.configure();
|
|
290
|
+
const result = await plugin.planResourceChange(type, priorState, proposedState);
|
|
291
|
+
return {
|
|
292
|
+
version: 0,
|
|
293
|
+
requiresReplacement: result.requiresReplace.length > 0,
|
|
294
|
+
state: result.plannedState
|
|
295
|
+
};
|
|
296
|
+
}
|
|
287
297
|
async getData({ type, state }) {
|
|
288
298
|
const plugin = await this.configure();
|
|
289
299
|
const data = await plugin.readDataSource(type, state);
|
|
@@ -1944,8 +1954,8 @@ var createTerraformProxy = (props) => {
|
|
|
1944
1954
|
async uninstall(installProps) {
|
|
1945
1955
|
await deletePlugin({ ...props.provider, ...installProps });
|
|
1946
1956
|
},
|
|
1947
|
-
|
|
1948
|
-
return
|
|
1957
|
+
isInstalled(installProps) {
|
|
1958
|
+
return isPluginInstalled({ ...props.provider, ...installProps });
|
|
1949
1959
|
},
|
|
1950
1960
|
resource: (ns, parent, id, input, config) => {
|
|
1951
1961
|
const type = snakeCase2([props.namespace, ...ns].join("_"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terraforge/terraform",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsup src/index.ts --format esm --dts --clean --out-dir ./dist",
|
|
25
|
-
"prepublishOnly": "bun run build",
|
|
25
|
+
"prepublishOnly": "if bun run test; then bun run build; else exit; fi",
|
|
26
26
|
"test": "bun test"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|