Open mwiczynski-cartera opened 12 months ago
If you fork the repo and push a small PR with the update that would be the fastest way to see this improvement moved into the resource pack.
I think this is a great suggestion! This would indeed make a great PR.
When an ec2 instance is terminated it can still appear in results/response for describing ec2 instances.
Describe the problem
When an ec2 instance is terminated it can still appear in results/response for describing ec2 instances. Eventually AWS removes it. A terminated instance passes the
it { should exist }
. This is not correct. it can also lead to problems when you have more than one instance with same name. One is terminated and other is non-terminated state(running, stopped, etc). Theaws_ec2_instance(name: 'foo')
resource will fail because more than once instance matching name is returned. Theaws_ec2_instances
resource does not allow filter by instance state. The resources should filter out terminated instances by default or give ability to do so. Not sure if anyone would ever want them to be included given how transient the terminated state is.Possible Solution
I suggest filtering out terminated by default. I suppose could also add instance state as column in FilterTable?
Change fetch_data https://github.com/inspec/inspec-aws/blob/a23887fa38bd5ae277a4c93d5e6c1b8ba3db4a2b/libraries/aws_ec2_instances.rb#L30 to filter out terminated.
This might not be ideal but I like idea of filtering out terminated instance here https://github.com/inspec/inspec-aws/blob/a23887fa38bd5ae277a4c93d5e6c1b8ba3db4a2b/libraries/aws_ec2_instance.rb#L19