https://pulumi.com logo
r

red-football-97286

11/04/2021, 8:49 AM
I'm building an EC2 which creates a network interface and attaches to the instance as a primary eni. I've set the 
deleteOnTermination
 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? (
protect
prevents deletion of the whole stack).
b

brave-planet-10645

11/04/2021, 9:07 AM
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
r

red-football-97286

11/04/2021, 9:12 AM
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......
b

brave-planet-10645

11/04/2021, 9:21 AM
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
deviceIndex
to be
0
?
Will that make it the primary?
r

red-football-97286

11/04/2021, 9:23 AM
I have, can you see the code I uploaded?
Yes it will, it works fine when building...just the remove part!
b

brave-planet-10645

11/04/2021, 9:46 AM
What's your use case here? Why do you need to keep the network interface around?
r

red-football-97286

11/04/2021, 9:47 AM
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.
b

brave-planet-10645

11/04/2021, 9:54 AM
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
r

red-football-97286

11/04/2021, 9:56 AM
OK, thanks Piers.
Won't it affect the EC2 from being deleted?
b

brave-planet-10645

11/04/2021, 10:05 AM
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?
r

red-football-97286

11/04/2021, 10:10 AM
Yes...
b

brave-planet-10645

11/04/2021, 10:23 AM
I don't know, but since you can create a network interface resource without an ec2 instance I suspect that it'll be possible
b

billowy-army-68599

11/04/2021, 2:06 PM
just following up here, you're defining the ENI in code too?
r

red-football-97286

11/04/2021, 2:08 PM
I was, not now.
👍 1
10 Views