I'm building an EC2 which creates a network interf...
# general
I'm building an EC2 which creates a network interface and attaches to the instance as a primary eni. I've set the 
 to false (as I want to keep the eni on deletion of the ec2. To do with an app license). But running 
pulumi destroy
 removes the eni. If I terminate through the console, the eni remains. Is there a way I can remove everything apart from the eni? (
prevents deletion of the whole stack).
You'll probably need to create the ENI separately and attach it to the instance https://www.pulumi.com/registry/packages/aws/api-docs/ec2/networkinterface/
Otherwise it'll be the EC2 instance that controls the lifecycle of the ENI
I've done this within a component resource. Create the eni and attach it to the EC2 instance.
But still removes it.
It needs to be the primary as well.
The component resource......
The destroy command tells AWS to remove everything as well, so if you're running destroy AWS is going to remove the ENI. My advise is to work out a way to be able to terminate the instance. This is good general "cloud" advise anyway where an EC2 instance might have to move hosts at any time and therefore it might be deleted
Can you set the
to be
Will that make it the primary?
I have, can you see the code I uploaded?
Yes it will, it works fine when building...just the remove part!
What's your use case here? Why do you need to keep the network interface around?
It is todo with licensing an application. It requires the mac address to be licensed. If we can keep the eni then it can be reattached to a new instance in the event of a problem.
Would making the EC2 instance a child to the ENI make a difference?
Copy code
// Whether or not to delete the network interface on instance termination. Defaults to `false`. Currently, the only valid value is `false`, as this is only supported when creating new network interfaces when launching an instance.
This is the problem, only works on creation.
If you're running destroy, Pulumi doesn't just terminate what's there, it deletes. If this is something you need to stick around, you'll need it in a new project/stack, one that doesn't get destroyed
OK, thanks Piers.
Won't it affect the EC2 from being deleted?
Not sure I understand. Do you mean if you have the interface resource in a different stack but attach it to an EC2 interface and try to run destroy it'll fail?
I don't know, but since you can create a network interface resource without an ec2 instance I suspect that it'll be possible
just following up here, you're defining the ENI in code too?
I was, not now.
👍 1