what's the best way to have 'pulumi destroy' avoid...
# general
l
what's the best way to have 'pulumi destroy' avoid destroying specific resources? e.g. i'd like to keep the aws cloudwatch log groups & streams created by the stack around subsequent to stack destruction. is 'pulumi delete' the recommended way to achieve this?
m
The
retainOnDelete
resource option may be what you’re looking for: https://www.pulumi.com/docs/intro/concepts/resources/options/retainondelete/
l
@miniature-musician-31262 bingo! thank you. this is cleaner than pulumi state delete.
m
Nice — you bet!
l
Another approach is to separate resources that you want to create or delete at different times into different projects. If you want to retain the log resources, they could be put in a different project.
This has the advantage that you can have separate log resources for different iterations of each stack of the main project, if you want. For main project "app", stack "staging", you might have log project "app-log", stacks "staging-1", "staging-2", etc. With retainOnDelete, when you run
pulumi up
again, you'll get naming conflicts (unless you delete the log resources or change their names in code).
l
@little-cartoon-10569 why would naming conflicts occur? pulumi up appends a randomly generated 32-bit integer suffix that it appends to resource names during creation, so i wouldn't expect a naming conflict to occur.
l
Because it's the same resource in Pulumi state, so it'll be creating the same resource in AWS or wherever. But the resource still exists there, Pulumi has just forgotten about it.
It'll try to create the resource with the same random suffix. (It's not a 32bit integer, it's a 6-character alphanum)
l
e.g. i have /aws/lambda/somelambda-func-789f7af now so if i regenerate the stack i would expect /aws/lambda/somelambda-func-<newRandomSuffix> to be created instead
ok 24-bit integer then
l
6 chaaracter alphanum != any kind of integer 🙂
It might use a new string, true. I haven't tested this. I've assumed that the suffix wouldn't be regenerated because it's the same instance of the resource.
But maybe it's not.
l
in all of my resources i am seeing a 7 character hexadecimal string which is a representation of a 28-bit integer.
l
Ah yes. I was being too programmery.
const x : number = "789f7af"
won't ever work :)