ansible-community / molecule-plugins

Collection on molecule plugins
MIT License
101 stars 67 forks source link

Prevent empty destroy from deleting other EC2 instances #170

Closed Thomas-McKanna closed 11 months ago

Thomas-McKanna commented 1 year ago

This PR seeks to fix the issue described in https://github.com/ansible-community/molecule-plugins/issues/136 and https://github.com/ansible-community/molecule-plugins/issues/121.

Currently, when using the EC2 Molecule plugin, issuing a molecule test command will cause all other EC2 instances in the subnet to be deleted. This is because the "destroy" phase gets run before the "create" phase, plus the fact that when the amazon.aws.ec2_instance Ansible module is called with no instance_id attribute (as is the case or a fresh molecule test command), the operation applies to all EC2 instance.

I've added in a block that checks that the instance_config is not empty before attempting to destroy EC2 instance.