Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eip association when both instance id and private ip address are passed #328

Merged
merged 3 commits into from Dec 15, 2020

Conversation

Phoosha
Copy link
Contributor

@Phoosha Phoosha commented Dec 10, 2020

I assume there has recently been a change to the AWS API introducing case sensitivity to the PrivateIpAddress parameter of AssociateAddress. The ec2_eip module uses this parameter in two branches (instance id vs interface id) and only in the instance branch it uses PrivateIPAddress (note how it's P and not p).

This PR also adds a variant of an existing test case to cover the branch that triggered this failure.

Example

- name: Associate an Elastic IP with instance
  ec2_eip:
    device_id: "{{ ec2.instance_ids[0] }}"
    private_ip_address: "{{ ec2.private_ip_address }}"
    state: present

This has worked for me for a long time. But when running it today I got this error:

The full traceback is:                                                                                                
Traceback (most recent call last):                    
  File "/tmp/ansible_ec2_eip_payload_drz_g_cz/ansible_ec2_eip_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_eip.py", line 249, in associate_ip_and_device
  File "/tmp/ansible_ec2_eip_payload_drz_g_cz/ansible_ec2_eip_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/core.py", line 289, in deciding_wrapper
    return unwrapped(*args, **kwargs)                                                                                 
  File "/usr/lib/python3.9/site-packages/botocore/client.py", line 357, in _api_call                                   
    return self._make_api_call(operation_name, kwargs)                                                                
  File "/usr/lib/python3.9/site-packages/botocore/client.py", line 648, in _make_api_call
    request_dict = self._convert_to_request_dict(                                                                     
  File "/usr/lib/python3.9/site-packages/botocore/client.py", line 696, in _convert_to_request_dict                   
    request_dict = self._serializer.serialize_to_request(
  File "/usr/lib/python3.9/site-packages/botocore/validate.py", line 297, in serialize_to_request                      
    raise ParamValidationError(report=report.generate_report())                                                        
botocore.exceptions.ParamValidationError: Parameter validation failed:                                                 
Unknown parameter in input: "PrivateIPAddress", must be one of: AllocationId, InstanceId, PublicIp, AllowReassociation, DryRun, NetworkInterfaceId, PrivateIpAddress

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, the change itself looks good, thanks for updating the test cases too.

Please add a changelog fragment: https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to

@tremble
Copy link
Contributor

tremble commented Dec 10, 2020

Hmm it looks like the changes are failing:

https://app.shippable.com/github/ansible-collections/community.aws/runs/1139/24/tests

Traceback (most recent call last):
  File "/tmp/ansible_ec2_instance_payload_rIlC6j/ansible_ec2_instance_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_instance.py", line 1669, in ensure_present
  File "/tmp/ansible_ec2_instance_payload_rIlC6j/ansible_ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/cloud.py", line 153, in retry_func
    raise e
ClientError: An error occurred (InvalidParameterCombination) when calling the ModifyInstanceAttribute operation: No attributes specified.

@Phoosha
Copy link
Contributor Author

Phoosha commented Dec 10, 2020

Hmm it looks like the changes are failing:

https://app.shippable.com/github/ansible-collections/community.aws/runs/1139/24/tests

Traceback (most recent call last):
  File "/tmp/ansible_ec2_instance_payload_rIlC6j/ansible_ec2_instance_payload.zip/ansible_collections/community/aws/plugins/modules/ec2_instance.py", line 1669, in ensure_present
  File "/tmp/ansible_ec2_instance_payload_rIlC6j/ansible_ec2_instance_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/cloud.py", line 153, in retry_func
    raise e
ClientError: An error occurred (InvalidParameterCombination) when calling the ModifyInstanceAttribute operation: No attributes specified.

It seems to me those failures are unrelated. Line 62 is very early in the file where everything is setup for the actual tests. If you haven't seen this before, maybe there has been other changes to AWS APIs. Maybe the ec2_instance module needs a fix too or needs to be differently invoked from the tests...

I'll look into the changelog fragment. 👍

@tremble
Copy link
Contributor

tremble commented Dec 10, 2020

Hi @Phoosha yeah, I'm seeing lots of CI failures related to the Instance APIs, I suspect this is an issue on the AWS side which got combined with a large number of tests going through at the same time.

@tremble
Copy link
Contributor

tremble commented Dec 14, 2020

The CI issue appears to be related to how ec2_instance finds instances by name, I'm attempting to get it working again. Once we can run this test suite successfully we should be good to merge this change.

@tremble tremble merged commit 4d1aa98 into ansible-collections:main Dec 15, 2020
@tremble
Copy link
Contributor

tremble commented Dec 15, 2020

Thank you for your contribution, unfortunately the CI issues we saw from ec2_instance meant we didn't get this merged before 1.3.0, but it shouldn't be too long before the next release.

@Phoosha Phoosha deleted the eip-case-sensitivity branch December 18, 2020 16:00
@Phoosha
Copy link
Contributor Author

Phoosha commented Dec 18, 2020

Thanks for keeping me in the loop, Mark. I appreciate it 👍

alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
…passed (ansible-collections#328)

* Fix ec2_eip with both instance_id and private_ip_address
* Add changelog fragment for the ec2_eip fix
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
…passed (ansible-collections#328)

* Fix ec2_eip with both instance_id and private_ip_address
* Add changelog fragment for the ec2_eip fix
danielcotton pushed a commit to danielcotton/community.aws that referenced this pull request Nov 23, 2021
…passed (ansible-collections#328)

* Fix ec2_eip with both instance_id and private_ip_address
* Add changelog fragment for the ec2_eip fix
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
abikouo pushed a commit to abikouo/community.aws that referenced this pull request Oct 24, 2023
…_contrib_script_compatible_ec2_tag_keys (ansible-collections#858)

Add version_added: 1.5.0 for exclude_filters, include_filters and use_contrib_script_compatible_ec2_tag_keys

SUMMARY

Add version_added: 1.5.0 for exclude_filters, include_filters and use_contrib_script_compatible_ec2_tag_keys
include_filters and exclude_filters have been added ansible-collections#328 and released with amazon.aws 1.5.0
use_contrib_script_compatible_ec2_tag_keys has been added ansible-collections#331 and released with  amazon.aws 1.5.0
Let's update the aws_ec2 inventory plugin documentation with this information.
This should be a step towards closing this one ansible-collections#676 and ansible-collections#675
aws_ec2 documentation will be enriched with exhaustive examples in an upcoming PR.

ISSUE TYPE


Docs Pull Request

COMPONENT NAME

aws_ec2
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
abikouo pushed a commit to abikouo/community.aws that referenced this pull request Oct 24, 2023
…passed (ansible-collections#328)

* Fix ec2_eip with both instance_id and private_ip_address
* Add changelog fragment for the ec2_eip fix

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@4d1aa98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants