https://pulumi.com logo
#general
Title
# general
p

polite-sandwich-68547

06/19/2023, 11:46 AM
is it possible to import an existing aws-loggroup into a new stack state so it won't be recreated or error out that it already exists? I want to import only the state not generate any code
a

acceptable-intern-25844

06/19/2023, 11:49 AM
p

polite-sandwich-68547

06/19/2023, 11:50 AM
both stacks are using the same code, hence importing the loggroup resource from another stack won't be compatible when I deploy the previous stacks
their resources have different names the only thing they share is the loggroup
by referencing means I have to create a new pulumi projects that creates just the loggroup then reference it
a

acceptable-intern-25844

06/19/2023, 11:52 AM
then it seems you’re looking for “get functions” https://www.pulumi.com/docs/concepts/resources/get/
p

polite-sandwich-68547

06/19/2023, 11:58 AM
still won't work as both stacks share the same code, e.g.: stack1 is creating the resource stack2 is also creating the same resource what I need is to import the state of the resource created by stack1 so stack2 will not attempt to recreate it and just use it as it's already created
a

acceptable-intern-25844

06/19/2023, 12:07 PM
You could create the stack1, then put into stack2's config the AWS resource URN (or whatever is needed for the reference) and in the code you put condition: if there is the reference in the config - use the resource by reference with the Get Function, otherwise create a new resource. Though it doesn't feel like idiomatic approach to me, it could be a workaround if you don't have too many stacks to remember to pass the reference everywhere needed
p

polite-sandwich-68547

06/19/2023, 12:15 PM
yes, that would work, though I found a different solution
I used
pulumi import
to import the resourse that uses exactly the same code, and now as it finds the resource and there's no change to it, kept it as is
now both stacks share the same code + resource
a

acceptable-intern-25844

06/19/2023, 12:19 PM
cool, thanks for sharing
p

polite-sandwich-68547

06/19/2023, 12:21 PM
anytime buddy
4 Views