Hey peeps, quick question on exporting resource. ...
# general
h
Hey peeps, quick question on exporting resource. I am trying to export CustomResource from one stack to another for the purpose of using its data in the construction of another CustomResource. So; Stack1 has Res1, I would like to export it, but it remains managed in stack 1 Stack2, import Res1 as it is needed to construct Res2 I know i can export/import string, but what i would like is for Res1 to be a "Res1" in Stack2, not a json payload of metadata to keep the code dealing with resource object in a ubiquitous fashion. is there an easy way to that. I find my self having some issue reconstructing the object. Thanks!
m
Check out this page and see if it's what you're looking for https://www.pulumi.com/learn/building-with-pulumi/stack-references/
h
Thank, yes I have, but this only deals with string. Which is pretty trivial to do. What I am looking for more for something like
pulumi.export("myBucket", a_bucket)
and then import that into another stack as a aws.s3.Bucket so I can use the object in the creation of other resource
m
While you can output then entire JSON for an object, you might be better off using strings with getters in your other plan. e.g.
Copy code
const sharedStack = new pulumi.StackReference("my/stack/reference");
const logBucketId = sharedStack.getOutput("logBucketId");

const logBucket = aws.s3.Bucket.get("log-bucket", logBucketId)
h
got it, so there is no "official way" to import a managed Resource. I can appreciate the difficulty of management ownership. I did try to use the
get
feature of CustomResource, by only exporting the minimum info for a remote lookup, but given that one deals in
Output
and the
get
seems to be "right now" I seem to have hit a bit of a wall
to expand on my use case, I wanted to create some code that was somewhat generic to either internal or external (for the stack) usage of a resource in the creation of another
m
Your custom resource definition should probably be in a package that you can install across both stacks, then passing references and reconstructing the resource component may feel more natural.
h
interesting, is there an example of that somewhere i could read, or what part of the doc would lead me to that approach?
m
You'll want to use patterns, tools and best practices for the language ecosystem you're working in.
h
interesting, thank you, I may have to rewrite some stuff after reading, kicking my self for not having found this sooner 😄
m
Hey, it happens, and Pulumi is pretty new, best practices are still emerging.
As an example... there are also "Pulumi packages", but this might be more complex https://www.pulumi.com/blog/resource-methods-for-pulumi-packages/
h
Here's a blog post about the concept at a high-level.
upon closer inspection, I am doing a version of this, but mostly for already constructed Resource to keep import and export as programmatic as I can (no hard-coded resource name or offband knowledge) to use resource from another stack as information.
so I just got it working, what would be the best channel to discuss the pattern in general I am using for this to see if the Experts could poke holes it in 😄?
also Thank you for all the help!