EC2 detach_network_interface should return error when removing the primary network interface
yairsappir opened this issue · comments
sappir commented
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
rafcio19 commented
@bblommers I can take a look