amazon.aws icon indicating copy to clipboard operation
amazon.aws copied to clipboard

ec2_instance InvalidParameterCombination when calling ModifyInstanceAttribute

Open jillr opened this issue 3 years ago • 8 comments

SUMMARY

We're starting to see CI failures for tests that use ec2_instance when creating new instances: "msg": "Could not apply change {'InstanceId': 'i-0c72055e2fe442009', 'Groups': []} to new instance.: An error occurred (InvalidParameterCombination) when calling the ModifyInstanceAttribute operation: No attributes specified.",

For example, https://app.shippable.com/github/ansible-collections/community.aws/runs/1144/23/console

Appears to be a failure with https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/ec2_instance.py#L1174 not returning any groups.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ec2_instance.py

ANSIBLE VERSION

2.9, 2.10, devel

OS / ENVIRONMENT

shippable

jillr avatar Dec 10 '20 22:12 jillr

Leaving some notes here as I'll be away for several days. Replicating CI using the ec2_eip tests:

At https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/ec2_instance.py#L1171 id_filters looks like: [{'Name': 'vpc-id', 'Values': ['vpc-371b0555']}, {'Name': 'group-id', 'Values': ['sg-06ed7d30d22e0a670']}]

The problem here is that this vpc-id is the default VPC for us-east-1 in CI and sg-06ed7d30d22e0a670 (in this example) belongs to the test VPC, vpc-077adc0ebabb1f33b. So describe_security_groups() with that filter quite reasonably doesn't return anything in found_groups at https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/ec2_instance.py#L1370.

Which makes expected_groups None, which is a mismatch to instance_groups at 1378, sending an empty group list via changes_to_apply to modify_instance_attribute() at https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/ec2_instance.py#L1669

However if I run a simple playbook against a personal account using my actual default VPC, same failure An error occurred (InvalidParameterCombination) when calling the ModifyInstanceAttribute operation: No attributes specified. So, that all may be irrelevant/secondary to the actual problem but I have not debugged this as thoroughly yet. The ec2_eip tests haven't changed in 4 months so it feels like something might have changed in the way the filtered describe_security_groups() query is returning data perhaps? I wasn't able to find any references to api changes though.

jillr avatar Dec 11 '20 00:12 jillr

This feels a lot like the instability we were seeing in https://github.com/ansible-collections/amazon.aws/pull/180 where filtered searches were (are) randomly returning empty results - I switched over to running the describe based on ID and it returned much more consistently.

tremble avatar Dec 11 '20 06:12 tremble

@tremble My concern is if this was a default behaviour that worked previously and is now resulting in new behaviour for Ansible users, I didn't find any obvious change notices on the AWS side but that's not shocking.

jillr avatar Dec 14 '20 16:12 jillr

@briantist I believe we've come to the conclusion that the fix here is to always be explicit and provide a vpc_subnet_id whenever you're not launching in the default VPC for the region. I believe from what you said on IRC you were just wanting to proactively track this issue, have you seen any issues that would not be solved by doing that?

jillr avatar Dec 14 '20 21:12 jillr

Thanks @jillr , I think we're already always setting vpc_subnet_id in our use of ec2_instance 😅 Good to hear that it's (seemingly) not a fully breaking upstream change. Thank you for following up!

briantist avatar Dec 14 '20 23:12 briantist

For anyone else who might come across this, from my debugging what I've been seeing is that some of the time filter based searches are returning an empty list when they shouldn't (or at least when historically they didn't). The account we use for CI often hits the API Rate Limits, so it's also possible that this is coming into play "somehow", either client side, or possibly on the Amazon side.

I've been working around this by relying less on filter based searches where possible (ec2_eni used to make a lot of gratuitous filter based searches). If I keep seeing this get worse I'll likely try to put together a reproducer that we can throw at Amazon.

tremble avatar Dec 15 '20 08:12 tremble

cc @Shaps @s-hertel @wimnat click here for bot help

ansibullbot avatar Jan 13 '21 00:01 ansibullbot

cc @ryansb click here for bot help

ansibullbot avatar Aug 18 '21 10:08 ansibullbot