little-cartoon-10569
05/11/2020, 10:44 PM@pulumi/pulumi
), I'm calling a function exported from my own module in a different project (brought in using "references": [{ "path": "../mypath/project"}] in my tsconfig.json). That function calls pulumi.runtime.registerStackTransformation()
. That call produces this error:
Error: The root stack resource was referenced before it was initialized.
at Object.registerStackTransformation (/app/pulumi/node_modules/@pulumi/pulumi/runtime/stack.js:211:15)
at Object.registerAutoTags (/app/pulumi/autotag/autotag.ts:246:20)
at Object.<anonymous> (/app/pulumi_stacks/vpc_poc/index.ts:25:11)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Module.m._compile (/app/pulumi_stacks/vpc_poc/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Object.require.extensions.<computed> [as .ts] (/app/pulumi_stacks/vpc_poc/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
The code is good: when I lift it out of my project/module and put it directly into index.ts it works fine. I'm guessing that this is a scoping issue.
Question: how do I call Pulumi code from projects/modules that are outside my application's project? Should I be passing "pulumi" or "pulumi.runtime" from my main module into my referenced project?gentle-diamond-70147
05/12/2020, 1:51 AMlittle-cartoon-10569
05/12/2020, 2:36 AM"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMap": true,
"strict": true,
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
The module in the library just exports a function, registerAutoTags
The app project's tsconfig includes this:
"references": [
{
"path": "../pulumi"
}
And the app's index.ts has this:
import { registerAutoTags } from "../../pulumi/autotag/autotag";
// Automatically inject tags.
registerAutoTags({
"user:Project": pulumi.getProject(),
"user:Stack": pulumi.getStack(),
"Env": "Sandbox",
});
gentle-diamond-70147
05/12/2020, 8:09 PMpulumi up
little-cartoon-10569
05/12/2020, 8:55 PMpulumi preview
. I didn't know there was another way to run it...gentle-diamond-70147
05/12/2020, 9:25 PMlittle-cartoon-10569
05/12/2020, 9:26 PMgentle-diamond-70147
05/12/2020, 9:28 PMregisterAutoTags()
called before all Pulumi resource creations?little-cartoon-10569
05/12/2020, 9:33 PMregisterAutoTags
function. That works. This reminds me of the issue I had a few days ago where I was using awsx v0.18 with pulumi v2: the lack of peerDependencies in awsx cause a different but similar error.npm install
, just in case. pulumi preview
is still failing with the same error.