def destroy_ec2(connection, region, instance_id, log=False):
data = get_ec2_info(connection=connection,<EOL>instance_id=instance_id,<EOL>region=region)<EOL>instance = connection.terminate_instances(instance_ids=[data['<STR_LIT:id>']])[<NUM_LIT:0>]<EOL>if log:<EOL><INDENT>log_yellow('<STR_LIT>')<EOL><DEDENT>while instance.state != "<STR_LIT>":<EOL><INDENT>if log:<EOL><INDENT>log_yellow("<STR_LIT>" % instance.state)<EOL><DEDENT>sleep(<NUM_LIT:10>)<EOL>instance.update()<EOL><DEDENT>volume_id = data['<STR_LIT>']<EOL>if volume_id:<EOL><INDENT>destroy_ebs_volume(connection, region, volume_id)<EOL><DEDENT>
terminates the instance