https://pulumi.com logo
o

orange-airport-64592

08/02/2023, 6:58 AM
Hi, Is there a way just to print the code of the existing resource but not really import them? That likes the --dry-run option.
c

cuddly-computer-18851

08/02/2023, 7:38 AM
Yes - sorry I don't have an environment setup to test this but if I recall its like
pulumi import ... --generate-code --skip-preview --out /dev/stdout
e

echoing-dinner-19531

08/02/2023, 3:30 PM
A "hack" to do this is to just make a new dummy stack to import into then rm it afterwards. We do have an issue tracking this: https://github.com/pulumi/pulumi/issues/8836
o

orange-airport-64592

08/03/2023, 2:46 AM
@echoing-dinner-19531 yeah, I think this is a really import feature because sometimes writing code is harder than using the console to create a resource, We can generate basic code in this way. To be honest, this was inspired by
kubectl create deploy xxx --dry-run -o yaml
I don’t think it would be too difficult to implement this feature on a current basis. Are you willing to accept open-source contributions? I want to try if possible🤣
@echoing-dinner-19531 I knew this “hack” way, but this is not my purpose
e

echoing-dinner-19531

08/03/2023, 6:32 AM
We're open to contributions, I think the internal code makes this trickier than first expected. I think the easiest way to do this would to just do the hack but internally (and a little better). Basically if --generate-only is set then make a filestate backend pointing to a temp folder and a stack in it called "import" then run the rest of the import logic as usual. But if you have a look and see another clean way to do this, then by all means submit a PR I'll take a look.