https://pulumi.com logo
Title
b

busy-honey-73811

05/10/2021, 12:29 PM
I have a lot of
dangling
Pulumi resources in my (TypeScript) stacks, resources which are created but not used as input to any other resource and which are neither added to any output nor returned from the main inline function (using the automation api). Looking at many Pulumi examples this seems to be a common pattern. Think of something like this:
function createBucket() {
   // Create AWS S3 Bucket but do neither output nor return it. It is also not used 
   // as input to any other resource.
   new Bucket("myBucket", {...});
}
However, rather often I observe that such resources are not created on first stack deployment resp. are delete on later stack updates. It looks like it depends on some “race condition” (timing issue) whether those resources are registered by the Pulumi runtime or not. Usually adding such
dangling
resources as dependency to another resource (using
dependsOn
), or alternatively making it a stack output resp. returning it from the main inline function resolves that (racy) problem. Now I am wondering, is this expected behaviour when using Pulumi with TypeScript/NodeJs or is this a bug in Pulumi?
c

cuddly-father-4905

05/10/2021, 1:16 PM
@dry-football-2639 I had a similar issue the other day - are you creating resources in a non-index file, and then re-exporting them from the index file? e.g. your above code snippet in
buckets.ts
and then
export * from './buckets';
in
index.ts
?
b

busy-honey-73811

05/10/2021, 1:21 PM
@cuddly-father-4905 Yes, that is exactly what I am doing.
c

cuddly-father-4905

05/10/2021, 1:24 PM
@dry-football-2639 in that case, I found that manually importing and exporting modules works far better than just re-exporting them, e.g.
import * as buckets from './buckets';

export {
  buckets
};
It's not as clean as just re-exporting, but it seems to have resolved this issue for me so far
b

busy-honey-73811

05/10/2021, 1:40 PM
@cuddly-father-4905 Do you have any background information on this (any pointer to a GitHub ticket/discussion, documentation, …)?
c

cuddly-father-4905

05/10/2021, 2:01 PM
@dry-football-2639 unfortunately not; I couldn't find anything about it myself, and arrived at this solution just via trial and error
I meant to file a GitHub issue about it but haven't gotten around to it yet
d

dry-football-2639

05/10/2021, 2:02 PM
@cuddly-father-4905 I believe you're tagging the wrong Alex 🙂
🤦‍♂️ 1
c

cuddly-father-4905

05/10/2021, 2:09 PM
Woops, sorry haha CC @busy-honey-73811 ^
b

busy-honey-73811

05/10/2021, 2:10 PM
@cuddly-father-4905 OK, thanks for the hint, I will check whether this might help in my case.
👍 1
w

white-balloon-205

05/11/2021, 3:31 AM
This is for better or worse part of how TypeScript works by default. `import`s which don't use any values from the import get elided and are not emitted as `require`s in the JavaScript code, and therefore don't cause any side effects that loading the module might ensure happen. See for example https://github.com/microsoft/TypeScript/issues/2812. That said - it looks like TypeScript 3.8 added a flag to control this behaviour: https://www.typescriptlang.org/tsconfig/#importsNotUsedAsValues. We should almost certainly set that to
preserve
by default for Pulumi projects since these style of side effects are very common in Pulumi programs.
👍 1
We should almost certainly set that to 
preserve
 by default for Pulumi projects since these style of side effects are very common in Pulumi programs.
Opened https://github.com/pulumi/pulumi/issues/7017 to track this.
b

busy-honey-73811

05/11/2021, 8:28 AM
@white-balloon-205 Thanks for those insights and creating the ticket. I will set
importsNotUsedAsValues
to
preserve
for my TypeScript stacks.