getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.

Home Page:http://docs.getmoto.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EC2 detach_network_interface should return error when removing the primary network interface

yairsappir opened this issue · comments

Hi,

It seems that when calling detach_network_interface on the primary network interface (at index 0), AWS throws this error:
botocore.exceptions.ClientError: An error occurred (OperationNotPermitted) when calling the DetachNetworkInterface operation: The network interface at device index 0 and networkCard index 0 cannot be detached.

However, moto does allow it which results in an exception being thrown when calling describe_instances afterwards:

    @property
    def private_ip(self) -> Optional[str]:
>       return self.nics[0].private_ip_address
E       KeyError: 0

..\..\..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\moto\ec2\models\instances.py:240: KeyError

@bblommers I can take a look