@webiny/pulumi 5.29.0-beta.0
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/LICENSE +21 -0
- package/PulumiAppModule.d.ts +16 -0
- package/PulumiAppModule.js +28 -0
- package/PulumiAppModule.js.map +1 -0
- package/PulumiAppRemoteResource.d.ts +5 -0
- package/PulumiAppRemoteResource.js +5 -0
- package/PulumiAppRemoteResource.js.map +1 -0
- package/PulumiAppResource.d.ts +27 -0
- package/PulumiAppResource.js +5 -0
- package/PulumiAppResource.js.map +1 -0
- package/README.md +138 -0
- package/createPulumiApp.d.ts +2 -0
- package/createPulumiApp.js +210 -0
- package/createPulumiApp.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +70 -0
- package/index.js.map +1 -0
- package/package.json +35 -0
- package/types.d.ts +53 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PulumiApp } from "./types";
|
|
2
|
+
export interface PulumiAppModuleCallback<TModule, TConfig> {
|
|
3
|
+
(this: void, app: PulumiApp, config: TConfig): TModule;
|
|
4
|
+
}
|
|
5
|
+
export interface PulumiAppModuleParams<TModule, TConfig> {
|
|
6
|
+
name: string;
|
|
7
|
+
config: PulumiAppModuleCallback<TModule, TConfig>;
|
|
8
|
+
}
|
|
9
|
+
export declare type PulumiAppModule<T extends PulumiAppModuleDefinition<any, any>> = T extends PulumiAppModuleDefinition<infer V, any> ? V : never;
|
|
10
|
+
export declare class PulumiAppModuleDefinition<TModule, TConfig> {
|
|
11
|
+
readonly symbol: symbol;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly run: PulumiAppModuleCallback<TModule, TConfig>;
|
|
14
|
+
constructor(params: PulumiAppModuleParams<TModule, TConfig>);
|
|
15
|
+
}
|
|
16
|
+
export declare function createAppModule<TModule, TConfig = void>(params: PulumiAppModuleParams<TModule, TConfig>): PulumiAppModuleDefinition<TModule, TConfig>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.PulumiAppModuleDefinition = void 0;
|
|
9
|
+
exports.createAppModule = createAppModule;
|
|
10
|
+
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
|
|
13
|
+
class PulumiAppModuleDefinition {
|
|
14
|
+
constructor(params) {
|
|
15
|
+
(0, _defineProperty2.default)(this, "symbol", Symbol());
|
|
16
|
+
(0, _defineProperty2.default)(this, "name", void 0);
|
|
17
|
+
(0, _defineProperty2.default)(this, "run", void 0);
|
|
18
|
+
this.name = params.name;
|
|
19
|
+
this.run = params.config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.PulumiAppModuleDefinition = PulumiAppModuleDefinition;
|
|
25
|
+
|
|
26
|
+
function createAppModule(params) {
|
|
27
|
+
return new PulumiAppModuleDefinition(params);
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PulumiAppModuleDefinition","constructor","params","Symbol","name","run","config","createAppModule"],"sources":["PulumiAppModule.ts"],"sourcesContent":["import { PulumiApp } from \"./types\";\n\nexport interface PulumiAppModuleCallback<TModule, TConfig> {\n (this: void, app: PulumiApp, config: TConfig): TModule;\n}\n\nexport interface PulumiAppModuleParams<TModule, TConfig> {\n name: string;\n config: PulumiAppModuleCallback<TModule, TConfig>;\n}\n\nexport type PulumiAppModule<T extends PulumiAppModuleDefinition<any, any>> =\n T extends PulumiAppModuleDefinition<infer V, any> ? V : never;\n\nexport class PulumiAppModuleDefinition<TModule, TConfig> {\n public readonly symbol = Symbol();\n public readonly name: string;\n public readonly run: PulumiAppModuleCallback<TModule, TConfig>;\n constructor(params: PulumiAppModuleParams<TModule, TConfig>) {\n this.name = params.name;\n this.run = params.config;\n }\n}\n\nexport function createAppModule<TModule, TConfig = void>(\n params: PulumiAppModuleParams<TModule, TConfig>\n) {\n return new PulumiAppModuleDefinition(params);\n}\n"],"mappings":";;;;;;;;;;;;AAcO,MAAMA,yBAAN,CAAkD;EAIrDC,WAAW,CAACC,MAAD,EAAkD;IAAA,8CAHpCC,MAAM,EAG8B;IAAA;IAAA;IACzD,KAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;IACA,KAAKC,GAAL,GAAWH,MAAM,CAACI,MAAlB;EACH;;AAPoD;;;;AAUlD,SAASC,eAAT,CACHL,MADG,EAEL;EACE,OAAO,IAAIF,yBAAJ,CAA8BE,MAA9B,CAAP;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["PulumiAppRemoteResource.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\nexport interface PulumiAppRemoteResource<T> {\n name: string;\n readonly output: pulumi.Output<pulumi.Unwrap<T>>;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
export interface PulumiAppResourceConstructor<T = any, TArgs = any> {
|
|
3
|
+
new (name: string, args: TArgs, opts?: pulumi.CustomResourceOptions): T;
|
|
4
|
+
}
|
|
5
|
+
export declare type PulumiAppResourceType<T extends PulumiAppResourceConstructor> = T extends PulumiAppResourceConstructor<infer TType> ? TType : never;
|
|
6
|
+
export declare type PulumiAppResourceArgs<T extends PulumiAppResourceConstructor> = T extends PulumiAppResourceConstructor<any, infer TArgs> ? Exclude<TArgs, undefined> : never;
|
|
7
|
+
export interface CreatePulumiAppResourceParams<TConstructor extends PulumiAppResourceConstructor> {
|
|
8
|
+
name: string;
|
|
9
|
+
config: PulumiAppResourceArgs<TConstructor>;
|
|
10
|
+
opts?: pulumi.CustomResourceOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface PulumiAppResourceConfigModifier<T> {
|
|
13
|
+
(value: pulumi.Unwrap<T>): T | void;
|
|
14
|
+
}
|
|
15
|
+
export interface PulumiAppResourceConfigSetter<T> {
|
|
16
|
+
(value: T): void;
|
|
17
|
+
(fcn: PulumiAppResourceConfigModifier<T>): void;
|
|
18
|
+
}
|
|
19
|
+
export declare type PulumiAppResourceConfigProxy<T extends object> = {
|
|
20
|
+
readonly [K in keyof T]-?: PulumiAppResourceConfigSetter<T[K]>;
|
|
21
|
+
};
|
|
22
|
+
export interface PulumiAppResource<T extends PulumiAppResourceConstructor> {
|
|
23
|
+
name: string;
|
|
24
|
+
readonly config: PulumiAppResourceConfigProxy<PulumiAppResourceArgs<T>>;
|
|
25
|
+
readonly opts: pulumi.CustomResourceOptions;
|
|
26
|
+
readonly output: pulumi.Output<pulumi.Unwrap<PulumiAppResourceType<T>>>;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["PulumiAppResource.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\nexport interface PulumiAppResourceConstructor<T = any, TArgs = any> {\n new (name: string, args: TArgs, opts?: pulumi.CustomResourceOptions): T;\n}\n\nexport type PulumiAppResourceType<T extends PulumiAppResourceConstructor> =\n T extends PulumiAppResourceConstructor<infer TType> ? TType : never;\n\nexport type PulumiAppResourceArgs<T extends PulumiAppResourceConstructor> =\n T extends PulumiAppResourceConstructor<any, infer TArgs> ? Exclude<TArgs, undefined> : never;\n\nexport interface CreatePulumiAppResourceParams<TConstructor extends PulumiAppResourceConstructor> {\n name: string;\n config: PulumiAppResourceArgs<TConstructor>;\n opts?: pulumi.CustomResourceOptions;\n}\n\nexport interface PulumiAppResourceConfigModifier<T> {\n (value: pulumi.Unwrap<T>): T | void;\n}\n\nexport interface PulumiAppResourceConfigSetter<T> {\n (value: T): void;\n (fcn: PulumiAppResourceConfigModifier<T>): void;\n}\n\nexport type PulumiAppResourceConfigProxy<T extends object> = {\n readonly [K in keyof T]-?: PulumiAppResourceConfigSetter<T[K]>;\n};\n\nexport interface PulumiAppResource<T extends PulumiAppResourceConstructor> {\n name: string;\n readonly config: PulumiAppResourceConfigProxy<PulumiAppResourceArgs<T>>;\n readonly opts: pulumi.CustomResourceOptions;\n readonly output: pulumi.Output<pulumi.Unwrap<PulumiAppResourceType<T>>>;\n}\n"],"mappings":""}
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# `@webiny/pulumi`
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/pulumi)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/pulumi)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
7
|
+
|
|
8
|
+
A small framework for creating flexible Pulumi programs.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Overview](#overview)
|
|
14
|
+
- [Examples](#examples)
|
|
15
|
+
- [Reference](#reference)
|
|
16
|
+
- [Functions](#functions)
|
|
17
|
+
- [`createPulumiApp`](#createPulumiApp)
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install --save @webiny/pulumi
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or if you prefer yarn:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
yarn add @webiny/pulumi
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
The `@webiny/pulumi` package enables creation of flexible Pulumi apps (programs).
|
|
34
|
+
|
|
35
|
+
More specifically, a Pulumi app not only encapsulates the essential Pulumi program code defined by developers, but also, once defined, provides a way to adjust any defined cloud infrastructure resource configuration and even add new resources into the mix.
|
|
36
|
+
|
|
37
|
+
This is useful when you just want to export a simple constructor function to the user, and not bother them with all the internals. And, as mentioned, in those rare cases when the user actually needs to perform further adjustments, a Pulumi app provides a way to do it.
|
|
38
|
+
|
|
39
|
+
> 💡 **TIP**
|
|
40
|
+
>
|
|
41
|
+
> Pulumi apps are heavily used in real Webiny projects. As mentioned, this is because of their ability to abstract the actual cloud infrastructure code from the user, and, at the same time, provide a way for the user to perform adjustments when needed.
|
|
42
|
+
|
|
43
|
+
The following example shows how a Pulumi app looks in the actual code:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// This is imported in our Pulumi program's entrypoint file (index.ts).
|
|
47
|
+
import createXyzApp from "@webiny/xyz-app";
|
|
48
|
+
|
|
49
|
+
export = async () => {
|
|
50
|
+
const xyzApp = createXyzApp({
|
|
51
|
+
pulumi: app => {
|
|
52
|
+
// Let's imagine the `xyz` Pulumi app deploys an Amazon S3 bucket.
|
|
53
|
+
// Then, we would be able to do something like the following:
|
|
54
|
+
app.resources.bucket.config.acl(aws.s3.CannedAcl.Private);
|
|
55
|
+
app.resources.bucket.config.forceDestroy(true);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return xyzApp.run();
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Examples
|
|
65
|
+
|
|
66
|
+
| Example | Description |
|
|
67
|
+
| --------------------------------- | --------------------------------------------------------------- |
|
|
68
|
+
| [Quick Example](./docs/examples/quickExample.md) | Shows how to create and use a simple Pulumi app. |
|
|
69
|
+
|
|
70
|
+
## Reference
|
|
71
|
+
|
|
72
|
+
### Functions
|
|
73
|
+
|
|
74
|
+
#### `createPulumiApp`
|
|
75
|
+
|
|
76
|
+
<details>
|
|
77
|
+
<summary>Type Declaration</summary>
|
|
78
|
+
<p>
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
export interface CreatePulumiAppParams<TResources extends Record<string, unknown>> {
|
|
82
|
+
name: string;
|
|
83
|
+
path: string;
|
|
84
|
+
config?: Record<string, any>;
|
|
85
|
+
program(app: PulumiApp): TResources | Promise<TResources>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export declare function createPulumiApp<TResources extends Record<string, unknown>>(params: CreatePulumiAppParams<TResources>): PulumiApp<TResources>;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
</p>
|
|
92
|
+
</details>
|
|
93
|
+
|
|
94
|
+
Creates a new Pulumi app.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// Defining the app.
|
|
98
|
+
import * as aws from "@pulumi/aws";
|
|
99
|
+
import { createPulumiApp } from "@webiny/pulumi";
|
|
100
|
+
|
|
101
|
+
export interface CreateMyAppParams {
|
|
102
|
+
pulumi?: (app: ReturnType<typeof createMyApp>) => void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const createMyApp = (projectAppConfig: CreateMyAppParams) => {
|
|
106
|
+
const app = createPulumiApp({
|
|
107
|
+
name: "my-app",
|
|
108
|
+
path: "relative/path/from/cwd",
|
|
109
|
+
program: async app => {
|
|
110
|
+
const bucket = app.addResource(aws.s3.Bucket, {
|
|
111
|
+
name: "my-app",
|
|
112
|
+
config: {
|
|
113
|
+
acl: aws.s3.CannedAcl.PublicRead,
|
|
114
|
+
forceDestroy: false,
|
|
115
|
+
website: {
|
|
116
|
+
indexDocument: "index.html",
|
|
117
|
+
errorDocument: "index.html"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
app.addOutputs({
|
|
123
|
+
appStorage: bucket.output.id
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
bucket
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (projectAppConfig.pulumi) {
|
|
133
|
+
projectAppConfig.pulumi(app);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return app;
|
|
137
|
+
};
|
|
138
|
+
```
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createPulumiApp = createPulumiApp;
|
|
9
|
+
|
|
10
|
+
var _findUp = _interopRequireDefault(require("find-up"));
|
|
11
|
+
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
|
|
14
|
+
var pulumi = _interopRequireWildcard(require("@pulumi/pulumi"));
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
function createPulumiApp(params) {
|
|
21
|
+
let projectRootPath = _findUp.default.sync("webiny.project.ts");
|
|
22
|
+
|
|
23
|
+
if (projectRootPath) {
|
|
24
|
+
projectRootPath = _path.default.dirname(projectRootPath).replace(/\\/g, "/");
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error("Couldn't detect Webiny project.");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const appRelativePath = params.path;
|
|
30
|
+
|
|
31
|
+
const appRootPath = _path.default.join(projectRootPath, appRelativePath);
|
|
32
|
+
|
|
33
|
+
const projectAppWorkspacePath = _path.default.join(projectRootPath, ".webiny", "workspaces", appRelativePath);
|
|
34
|
+
|
|
35
|
+
const app = {
|
|
36
|
+
resourceHandlers: [],
|
|
37
|
+
handlers: [],
|
|
38
|
+
outputs: {},
|
|
39
|
+
modules: new Map(),
|
|
40
|
+
paths: {
|
|
41
|
+
absolute: appRootPath,
|
|
42
|
+
relative: appRelativePath,
|
|
43
|
+
workspace: projectAppWorkspacePath
|
|
44
|
+
},
|
|
45
|
+
resources: {},
|
|
46
|
+
name: params.name,
|
|
47
|
+
program: params.program,
|
|
48
|
+
params: {
|
|
49
|
+
create: params.config || {},
|
|
50
|
+
run: {}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
async run(config) {
|
|
54
|
+
app.params.run = config;
|
|
55
|
+
Object.assign(app.resources, await app.program(app));
|
|
56
|
+
|
|
57
|
+
for (const handler of app.handlers) {
|
|
58
|
+
await handler();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
app.params.run = {};
|
|
62
|
+
return app.outputs;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
onResource(handler) {
|
|
66
|
+
app.resourceHandlers.push(handler);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Adds a resource to pulumi app.
|
|
71
|
+
* It's not running the script immediately, but enqueues the call.
|
|
72
|
+
* This way we are still able to modify the config of the resource.
|
|
73
|
+
* @param resourceConstructor Resource to be added, ie aws.s3.Bucket
|
|
74
|
+
* @param params Parameters to configure the resource
|
|
75
|
+
* @returns Object giving access to both resource outputs and its config.
|
|
76
|
+
*/
|
|
77
|
+
addResource(resourceConstructor, params) {
|
|
78
|
+
const config = params.config ?? {};
|
|
79
|
+
const opts = params.opts ?? {};
|
|
80
|
+
const promise = new Promise(resolve => {
|
|
81
|
+
app.handlers.push(() => {
|
|
82
|
+
app.resourceHandlers.forEach(handler => handler(resourceInstance));
|
|
83
|
+
const resourceInstance = new resourceConstructor(resource.name, config, opts);
|
|
84
|
+
resolve(resourceInstance);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
const resource = {
|
|
88
|
+
name: params.name,
|
|
89
|
+
config: createPulumiAppResourceConfigProxy(config),
|
|
90
|
+
opts,
|
|
91
|
+
output: pulumi.output(promise)
|
|
92
|
+
};
|
|
93
|
+
return resource;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
addRemoteResource(name, getter) {
|
|
97
|
+
const promise = getter();
|
|
98
|
+
const resource = {
|
|
99
|
+
name,
|
|
100
|
+
output: pulumi.output(promise)
|
|
101
|
+
};
|
|
102
|
+
return resource;
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Registers output value within pulumi app.
|
|
107
|
+
* @param name Name of the output value
|
|
108
|
+
* @param output Value of the output
|
|
109
|
+
*/
|
|
110
|
+
addOutput(name, output) {
|
|
111
|
+
app.outputs[name] = output;
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Registers one or more output values.
|
|
116
|
+
* @param outputs Dictionary containing output values.
|
|
117
|
+
*/
|
|
118
|
+
addOutputs(outputs) {
|
|
119
|
+
Object.assign(app.outputs, outputs);
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Registers an app module within app.
|
|
124
|
+
* Allows to decompose application into smaller pieces.
|
|
125
|
+
* Added module can be then retrieved with `getModule`.
|
|
126
|
+
* @param module
|
|
127
|
+
* @param config
|
|
128
|
+
*/
|
|
129
|
+
addModule(module, config) {
|
|
130
|
+
if (app.modules.has(module.symbol)) {
|
|
131
|
+
throw new Error(`Module "${module.name}" is already present in the "${app.name}" application.`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const createdModule = module.run(app, config);
|
|
135
|
+
app.modules.set(module.symbol, createdModule);
|
|
136
|
+
return createdModule;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Returns a module by its definition
|
|
141
|
+
* @param def
|
|
142
|
+
* @param opts
|
|
143
|
+
*/
|
|
144
|
+
getModule(def, opts) {
|
|
145
|
+
const module = app.modules.get(def.symbol);
|
|
146
|
+
|
|
147
|
+
if (!module) {
|
|
148
|
+
if (opts !== null && opts !== void 0 && opts.optional) {
|
|
149
|
+
return null;
|
|
150
|
+
} else {
|
|
151
|
+
throw new Error(`Module "${def.name}" not found in "${app.name}" app`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return module;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Schedules a handler to be executed when running pulumi script.
|
|
160
|
+
* Anything, that is returned from handler will be wrapped in pulumi.Output
|
|
161
|
+
* so it can be used in other places.
|
|
162
|
+
* @param handler Handler to be executed.
|
|
163
|
+
* @returns Result of the handler wrapped with pulumi.Output
|
|
164
|
+
*/
|
|
165
|
+
addHandler(handler) {
|
|
166
|
+
const promise = new Promise(resolve => {
|
|
167
|
+
app.handlers.push(async () => {
|
|
168
|
+
resolve(await handler());
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
return pulumi.output(promise);
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
getParam(param) {
|
|
175
|
+
if (typeof param === "function") {
|
|
176
|
+
return param(app);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return param;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
};
|
|
183
|
+
return app;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function createPulumiAppResourceConfigProxy(obj) {
|
|
187
|
+
return new Proxy(obj, {
|
|
188
|
+
get(target, p) {
|
|
189
|
+
const key = p;
|
|
190
|
+
|
|
191
|
+
const setter = value => {
|
|
192
|
+
if (typeof value === "function") {
|
|
193
|
+
const modifier = value;
|
|
194
|
+
const currentValue = target[key]; // Wrap a current config with a function.
|
|
195
|
+
|
|
196
|
+
const newValue = pulumi.output(currentValue).apply(v => {
|
|
197
|
+
const newValue = modifier(v);
|
|
198
|
+
return pulumi.output(newValue);
|
|
199
|
+
});
|
|
200
|
+
target[key] = newValue;
|
|
201
|
+
} else {
|
|
202
|
+
target[key] = value;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
return setter;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
});
|
|
210
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPulumiApp","params","projectRootPath","findUp","sync","path","dirname","replace","Error","appRelativePath","appRootPath","join","projectAppWorkspacePath","app","resourceHandlers","handlers","outputs","modules","Map","paths","absolute","relative","workspace","resources","name","program","create","config","run","Object","assign","handler","onResource","push","addResource","resourceConstructor","opts","promise","Promise","resolve","forEach","resourceInstance","resource","createPulumiAppResourceConfigProxy","output","pulumi","addRemoteResource","getter","addOutput","addOutputs","addModule","module","has","symbol","createdModule","set","getModule","def","get","optional","addHandler","getParam","param","obj","Proxy","target","p","key","setter","value","modifier","currentValue","newValue","apply","v"],"sources":["createPulumiApp.ts"],"sourcesContent":["import findUp from \"find-up\";\nimport path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport { PulumiAppModuleDefinition } from \"./PulumiAppModule\";\nimport {\n PulumiAppResourceArgs,\n PulumiAppResourceConstructor,\n PulumiAppResourceType,\n PulumiAppResource,\n CreatePulumiAppResourceParams,\n PulumiAppResourceConfigSetter,\n PulumiAppResourceConfigModifier,\n PulumiAppResourceConfigProxy\n} from \"./PulumiAppResource\";\nimport {\n CreatePulumiAppParams,\n PulumiApp,\n PulumiAppParam,\n PulumiAppParamCallback,\n ResourceHandler\n} from \"~/types\";\nimport { PulumiAppRemoteResource } from \"~/PulumiAppRemoteResource\";\n\nexport function createPulumiApp<TResources extends Record<string, unknown>>(\n params: CreatePulumiAppParams<TResources>\n): PulumiApp<TResources> {\n let projectRootPath = findUp.sync(\"webiny.project.ts\");\n if (projectRootPath) {\n projectRootPath = path.dirname(projectRootPath).replace(/\\\\/g, \"/\");\n } else {\n throw new Error(\"Couldn't detect Webiny project.\");\n }\n\n const appRelativePath = params.path;\n const appRootPath = path.join(projectRootPath, appRelativePath);\n\n const projectAppWorkspacePath = path.join(\n projectRootPath,\n \".webiny\",\n \"workspaces\",\n appRelativePath\n );\n\n const app: PulumiApp<TResources> = {\n resourceHandlers: [],\n handlers: [],\n outputs: {},\n modules: new Map<symbol, unknown>(),\n paths: {\n absolute: appRootPath,\n relative: appRelativePath,\n workspace: projectAppWorkspacePath\n },\n\n resources: {} as TResources,\n name: params.name,\n program: params.program,\n params: {\n create: params.config || {},\n run: {}\n },\n\n async run(config) {\n app.params.run = config;\n\n Object.assign(app.resources, await app.program(app));\n\n for (const handler of app.handlers) {\n await handler();\n }\n\n app.params.run = {};\n\n return app.outputs;\n },\n\n onResource(handler: ResourceHandler) {\n app.resourceHandlers.push(handler);\n },\n\n /**\n * Adds a resource to pulumi app.\n * It's not running the script immediately, but enqueues the call.\n * This way we are still able to modify the config of the resource.\n * @param resourceConstructor Resource to be added, ie aws.s3.Bucket\n * @param params Parameters to configure the resource\n * @returns Object giving access to both resource outputs and its config.\n */\n addResource<T extends PulumiAppResourceConstructor>(\n resourceConstructor: T,\n params: CreatePulumiAppResourceParams<T>\n ) {\n const config = params.config ?? ({} as PulumiAppResourceArgs<T>);\n const opts = params.opts ?? {};\n\n const promise = new Promise<PulumiAppResourceType<T>>(resolve => {\n app.handlers.push(() => {\n app.resourceHandlers.forEach(handler => handler(resourceInstance));\n const resourceInstance = new resourceConstructor(resource.name, config, opts);\n resolve(resourceInstance);\n });\n });\n\n const resource: PulumiAppResource<T> = {\n name: params.name,\n config: createPulumiAppResourceConfigProxy(config),\n opts,\n output: pulumi.output(promise)\n };\n\n return resource;\n },\n\n addRemoteResource<T>(name: string, getter: () => Promise<T>) {\n const promise = getter();\n\n const resource: PulumiAppRemoteResource<T> = {\n name,\n output: pulumi.output(promise)\n };\n\n return resource;\n },\n\n /**\n * Registers output value within pulumi app.\n * @param name Name of the output value\n * @param output Value of the output\n */\n addOutput<T>(name: string, output: T) {\n app.outputs[name] = output;\n },\n\n /**\n * Registers one or more output values.\n * @param outputs Dictionary containing output values.\n */\n addOutputs(outputs: Record<string, unknown>) {\n Object.assign(app.outputs, outputs);\n },\n\n /**\n * Registers an app module within app.\n * Allows to decompose application into smaller pieces.\n * Added module can be then retrieved with `getModule`.\n * @param module\n * @param config\n */\n addModule<TModule, TConfig>(\n module: PulumiAppModuleDefinition<TModule, TConfig>,\n config?: TConfig\n ) {\n if (app.modules.has(module.symbol)) {\n throw new Error(\n `Module \"${module.name}\" is already present in the \"${app.name}\" application.`\n );\n }\n\n const createdModule = module.run(app, config as TConfig);\n app.modules.set(module.symbol, createdModule);\n\n return createdModule;\n },\n\n /**\n * Returns a module by its definition\n * @param def\n * @param opts\n */\n getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts?: { optional: boolean }\n ) {\n const module = app.modules.get(def.symbol);\n\n if (!module) {\n if (opts?.optional) {\n return null;\n } else {\n throw new Error(`Module \"${def.name}\" not found in \"${app.name}\" app`);\n }\n }\n\n return module;\n },\n\n /**\n * Schedules a handler to be executed when running pulumi script.\n * Anything, that is returned from handler will be wrapped in pulumi.Output\n * so it can be used in other places.\n * @param handler Handler to be executed.\n * @returns Result of the handler wrapped with pulumi.Output\n */\n addHandler<T>(handler: () => Promise<T> | T) {\n const promise = new Promise<T>(resolve => {\n app.handlers.push(async () => {\n resolve(await handler());\n });\n });\n\n return pulumi.output(promise);\n },\n\n getParam<T>(param: PulumiAppParam<T>) {\n if (typeof param === \"function\") {\n return (param as PulumiAppParamCallback<T>)(app);\n }\n\n return param;\n }\n };\n\n return app;\n}\n\nfunction createPulumiAppResourceConfigProxy<T extends object>(obj: T) {\n return new Proxy(obj, {\n get(target, p: string) {\n type V = T[keyof T];\n const key = p as keyof T;\n const setter: PulumiAppResourceConfigSetter<V> = (\n value: V | PulumiAppResourceConfigModifier<V>\n ) => {\n if (typeof value === \"function\") {\n const modifier = value as PulumiAppResourceConfigModifier<V>;\n const currentValue = target[key];\n // Wrap a current config with a function.\n const newValue = pulumi.output(currentValue).apply(v => {\n const newValue = modifier(v);\n return pulumi.output(newValue);\n });\n\n target[key] = newValue as unknown as V;\n } else {\n target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Q,GAAGF,QAAQ,CAACI,CAAD,CAAzB;YACA,OAAO7B,MAAM,CAACD,MAAP,CAAc4B,QAAd,CAAP;UACH,CAHgB,CAAjB;UAKAP,MAAM,CAACE,GAAD,CAAN,GAAcK,QAAd;QACH,CAVD,MAUO;UACHP,MAAM,CAACE,GAAD,CAAN,GAAcE,KAAd;QACH;MACJ,CAhBD;;MAkBA,OAAOD,MAAP;IACH;;EAvBiB,CAAf,CAAP;AAyBH"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _createPulumiApp = require("./createPulumiApp");
|
|
8
|
+
|
|
9
|
+
Object.keys(_createPulumiApp).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _createPulumiApp[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _createPulumiApp[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _PulumiAppModule = require("./PulumiAppModule");
|
|
21
|
+
|
|
22
|
+
Object.keys(_PulumiAppModule).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _PulumiAppModule[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _PulumiAppModule[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _PulumiAppResource = require("./PulumiAppResource");
|
|
34
|
+
|
|
35
|
+
Object.keys(_PulumiAppResource).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _PulumiAppResource[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _PulumiAppResource[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _PulumiAppRemoteResource = require("./PulumiAppRemoteResource");
|
|
47
|
+
|
|
48
|
+
Object.keys(_PulumiAppRemoteResource).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _PulumiAppRemoteResource[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _PulumiAppRemoteResource[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
var _types = require("./types");
|
|
60
|
+
|
|
61
|
+
Object.keys(_types).forEach(function (key) {
|
|
62
|
+
if (key === "default" || key === "__esModule") return;
|
|
63
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
64
|
+
Object.defineProperty(exports, key, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _types[key];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./createPulumiApp\";\nexport * from \"./PulumiAppModule\";\nexport * from \"./PulumiAppResource\";\nexport * from \"./PulumiAppRemoteResource\";\nexport * from \"./types\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/pulumi",
|
|
3
|
+
"version": "5.29.0-beta.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "A simple Node.js Pulumi SDK.",
|
|
10
|
+
"author": "Webiny Ltd",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"directory": "dist"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@pulumi/pulumi": "^3.34.0",
|
|
18
|
+
"find-up": "5.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@babel/cli": "^7.16.0",
|
|
22
|
+
"@babel/core": "^7.16.0",
|
|
23
|
+
"@types/lodash": "^4.14.178",
|
|
24
|
+
"@types/node": "^10.0.0",
|
|
25
|
+
"@webiny/cli": "^5.29.0-beta.0",
|
|
26
|
+
"@webiny/project-utils": "^5.29.0-beta.0",
|
|
27
|
+
"rimraf": "^3.0.2",
|
|
28
|
+
"typescript": "4.5.5"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "yarn webiny run build",
|
|
32
|
+
"watch": "yarn webiny run watch"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "e221dc575942c512548be142e20c5bd1231edcda"
|
|
35
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
import { PulumiAppModuleDefinition } from "./PulumiAppModule";
|
|
3
|
+
import { PulumiAppResourceConstructor, PulumiAppResource, CreatePulumiAppResourceParams } from "./PulumiAppResource";
|
|
4
|
+
import { PulumiAppRemoteResource } from "./PulumiAppRemoteResource";
|
|
5
|
+
export interface ResourceHandler {
|
|
6
|
+
(resource: PulumiAppResource<PulumiAppResourceConstructor>): void;
|
|
7
|
+
}
|
|
8
|
+
export declare type PulumiAppParamCallback<T> = (app: PulumiApp) => T;
|
|
9
|
+
export declare type PulumiAppParam<T> = T | PulumiAppParamCallback<T>;
|
|
10
|
+
export declare type PulumiProgram<TResources = Record<string, any>> = (app: PulumiApp) => TResources | Promise<TResources>;
|
|
11
|
+
export declare type CreateConfig = Record<string, any>;
|
|
12
|
+
export declare type RunConfig = Record<string, any>;
|
|
13
|
+
export interface CreatePulumiAppParams<TResources extends Record<string, unknown>> {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
config?: CreateConfig;
|
|
17
|
+
program(app: PulumiApp): TResources | Promise<TResources>;
|
|
18
|
+
}
|
|
19
|
+
export interface PulumiApp<TResources = Record<string, unknown>> {
|
|
20
|
+
resourceHandlers: ResourceHandler[];
|
|
21
|
+
handlers: (() => void | Promise<void>)[];
|
|
22
|
+
outputs: Record<string, any>;
|
|
23
|
+
modules: Map<symbol, unknown>;
|
|
24
|
+
paths: {
|
|
25
|
+
absolute: string;
|
|
26
|
+
relative: string;
|
|
27
|
+
workspace: string;
|
|
28
|
+
};
|
|
29
|
+
name: string;
|
|
30
|
+
program: PulumiProgram<TResources>;
|
|
31
|
+
resources: TResources;
|
|
32
|
+
params: {
|
|
33
|
+
create: CreateConfig;
|
|
34
|
+
run: RunConfig;
|
|
35
|
+
};
|
|
36
|
+
run(params: RunConfig): Record<string, any>;
|
|
37
|
+
onResource(handler: ResourceHandler): void;
|
|
38
|
+
addResource<T extends PulumiAppResourceConstructor>(resourceConstructor: T, params: CreatePulumiAppResourceParams<T>): PulumiAppResource<T>;
|
|
39
|
+
addRemoteResource<T>(name: string, getter: () => Promise<T>): PulumiAppRemoteResource<T>;
|
|
40
|
+
addOutput<T>(name: string, output: T): void;
|
|
41
|
+
addOutputs(outputs: Record<string, unknown>): void;
|
|
42
|
+
addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;
|
|
43
|
+
addModule<TModule, TConfig>(def: PulumiAppModuleDefinition<TModule, TConfig>, config: TConfig): TModule;
|
|
44
|
+
getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;
|
|
45
|
+
getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
|
|
46
|
+
optional: false;
|
|
47
|
+
}): TModule;
|
|
48
|
+
getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
|
|
49
|
+
optional: true;
|
|
50
|
+
}): TModule | null;
|
|
51
|
+
addHandler<T>(handler: () => Promise<T> | T): pulumi.Output<pulumi.Unwrap<T>>;
|
|
52
|
+
getParam<T>(param: T | ((app: PulumiApp) => T)): T;
|
|
53
|
+
}
|
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport { PulumiAppModuleDefinition } from \"./PulumiAppModule\";\nimport {\n PulumiAppResourceConstructor,\n PulumiAppResource,\n CreatePulumiAppResourceParams\n} from \"./PulumiAppResource\";\nimport { PulumiAppRemoteResource } from \"~/PulumiAppRemoteResource\";\n\nexport interface ResourceHandler {\n (resource: PulumiAppResource<PulumiAppResourceConstructor>): void;\n}\n\nexport type PulumiAppParamCallback<T> = (app: PulumiApp) => T;\nexport type PulumiAppParam<T> = T | PulumiAppParamCallback<T>;\n\nexport type PulumiProgram<TResources = Record<string, any>> = (\n app: PulumiApp\n) => TResources | Promise<TResources>;\n\nexport type CreateConfig = Record<string, any>;\nexport type RunConfig = Record<string, any>;\n\nexport interface CreatePulumiAppParams<TResources extends Record<string, unknown>> {\n name: string;\n path: string;\n config?: CreateConfig;\n program(app: PulumiApp): TResources | Promise<TResources>;\n}\n\nexport interface PulumiApp<TResources = Record<string, unknown>> {\n resourceHandlers: ResourceHandler[];\n handlers: (() => void | Promise<void>)[];\n outputs: Record<string, any>;\n modules: Map<symbol, unknown>;\n\n paths: { absolute: string; relative: string; workspace: string };\n name: string;\n program: PulumiProgram<TResources>;\n resources: TResources;\n params: {\n create: CreateConfig;\n run: RunConfig;\n };\n\n run(params: RunConfig): Record<string, any>;\n\n onResource(handler: ResourceHandler): void;\n\n addResource<T extends PulumiAppResourceConstructor>(\n resourceConstructor: T,\n params: CreatePulumiAppResourceParams<T>\n ): PulumiAppResource<T>;\n\n addRemoteResource<T>(name: string, getter: () => Promise<T>): PulumiAppRemoteResource<T>;\n\n addOutput<T>(name: string, output: T): void;\n addOutputs(outputs: Record<string, unknown>): void;\n\n addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;\n addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config: TConfig\n ): TModule;\n\n getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;\n getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: false }\n ): TModule;\n getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: true }\n ): TModule | null;\n\n addHandler<T>(handler: () => Promise<T> | T): pulumi.Output<pulumi.Unwrap<T>>;\n\n getParam<T>(param: T | ((app: PulumiApp) => T)): T;\n}\n"],"mappings":""}
|