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

ec2_vpc_vpn.py: Facilitate VPN TunnelOptions #35210

Merged
merged 5 commits into from Feb 7, 2018
Merged

ec2_vpc_vpn.py: Facilitate VPN TunnelOptions #35210

merged 5 commits into from Feb 7, 2018

Conversation

subcon42
Copy link
Contributor

SUMMARY

AWS (and Boto3) supports VPN TunnelOption keys to be specified for VPNs. Specifically (at least at the moment), the options for 'TunnelInsideCidr' (str) and 'PreSharedKey' (str) are particularly noteworthy. One or both may be specified within a 'dict' object (max 2 dicts). AWS defaults shall apply in absence of said parameters.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
  • ec2_vpc_vpn (.py)
ANSIBLE VERSION
devel
2.4
TESTING

This change was tested during a recent Ansible playbook run (unfortunately console output was not preserved). The VPN tunnels came online after a typical amount of time, and all specified TunnelOptions were present as expected.

ADDITIONAL INFORMATION

At the time of this writing, the Boto3 documentation covers this topic:

SUMMARY

AWS (and Boto3) supports VPN TunnelOption keys to be specified for VPNs.  Specifically (at least at the moment), the options for 'TunnelInsideCidr' (str) and 'PreSharedKey' (str) are particularly noteworthy.  One or both may be specified within a 'dict' object (max 2 dicts).  AWS defaults shall apply in absence of said parameters.  

ISSUE TYPE

  *  Feature Pull Request

COMPONENT NAME

  * ec2_vpc_vpn.py

ANSIBLE VERSION

  * devel
  * 2.4

ADDITIONAL INFORMATION

At the time of this writing, the Boto3 documentation on this topic can be referenced at:

  * http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.create_vpn_connection

USAGE EXAMPLES

Note this feature requires so-called anonymous dict objects be referenced as shown.

An example playbook excerpt for specifying PreSharedKeys for both VPN tunnels:

- name: TunnelOptions include 'PreSharedKey' only
  ec2_vpc_vpn:
    state: present
    filters:
      vpn: vpn-XXXXXXXX
    static_only: true
    tunnel_options:
      -
        PreSharedKey: 'abc123xyz789'
      -
        PreSharedKey: 'abc123xyz789'

Same as above, except for 'TunnelInsideCidr' only:

- name: TunnelOptions include 'TunnelInsideCidr' only
  ec2_vpc_vpn:
    state: present
    filters:
      vpn: vpn-XXXXXXXX
    static_only: true
    tunnel_options:
      -
        TunnelInsideCidr: '169.254.100.1/30'
      -
        TunnelInsideCidr: '169.254.100.5/30'

Both available 'TunnelOptions':

- name: All currently available TunnelOptions
  ec2_vpc_vpn:
    state: present
    filters:
      vpn: vpn-XXXXXXXX
    static_only: true
    tunnel_options:
      -
        TunnelInsideCidr: '169.254.100.1/30'
        PreSharedKey: 'abc123xyz789'
      -
        TunnelInsideCidr: '169.254.100.5/30'
        PreSharedKey: 'abc123xyz789'
@ansibot
Copy link
Contributor

ansibot commented Jan 23, 2018

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 aws cloud community_review In order to be merged, this PR must follow the community review workflow. feature_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. labels Jan 23, 2018
@ansibot
Copy link
Contributor

ansibot commented Jan 23, 2018

The test ansible-test sanity --test pep8 [?] failed with the following errors:

lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:441:16: E201 whitespace after '{'
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:441:48: E202 whitespace before '}'
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:444:7: E111 indentation is not a multiple of four
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:445:7: E111 indentation is not a multiple of four
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:446:59: W291 trailing whitespace
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:449:11: E111 indentation is not a multiple of four
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:451:7: E111 indentation is not a multiple of four
lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:712:44: E231 missing whitespace after ','

The test ansible-test sanity --test pylint [?] failed with the following error:

lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:446:0: trailing-whitespace Trailing whitespace

The test ansible-test sanity --test validate-modules [?] failed with the following error:

lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:0:0: E309 version_added for new option (tunnel_options) should be 2.5. Currently 0.0

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Jan 23, 2018
Fixed apparent indentation/format errors ...
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Jan 23, 2018
@ansibot
Copy link
Contributor

ansibot commented Jan 23, 2018

The test ansible-test sanity --test validate-modules [?] failed with the following error:

lib/ansible/modules/cloud/amazon/ec2_vpc_vpn.py:0:0: E309 version_added for new option (tunnel_options) should be 2.5. Currently 0.0

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Jan 23, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 23, 2018
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Jan 23, 2018
@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label Jan 24, 2018

options = {'StaticRoutesOnly': static_only}

if isinstance(tunnel_options, list) and 0 < len(tunnel_options) <= 2:
Copy link
Contributor

Choose a reason for hiding this comment

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

tunnel_options will never not be a list here since it's defaulting to an empty list and has type='list' in the arg spec so you could simplify this a bit to:if tunnel_options and len(tunnel_options) <=2:

However, would it be better not to silently ignore if you list more than 2? The error that would be returned by boto is probably enough in terms of validation for this option (though I haven't tested it, and that should be checked). If it isn't caught and handled properly, botocore.exceptions.BotoCoreError handling may need to be added to the call in addition to the botocore.exceptions.ClientError (the difference being that BotoCoreError has no .response attribute).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding your first point on 'simplification', I agree and will massage the code accordingly.

Regarding the list size, my original thinking was that if someone is doing something funky (e.g: sending more dicts than Boto3/AWS are capable of handling), we should just ignore it. I could see throwing a harmless warning, advising the executor that only up to 2 pairs of options are supported. I am, however, open to throwing a fatal exception as you indicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong preference. LGTM!

if not isinstance(m, dict):
raise TypeError("non-dict list member")
t_opt.append(m)
if len(t_opt) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

This can just be if t_opt: since an empty list is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll update this line (452).

Some list-specific cleanup per s-hertel's suggestions.
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Feb 6, 2018
@ryansb ryansb merged commit 920eaaf into ansible:devel Feb 7, 2018
@ryansb ryansb removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Feb 7, 2018
@subcon42 subcon42 deleted the patch-1 branch February 8, 2018 03:54
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 5, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 aws cloud community_review In order to be merged, this PR must follow the community review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants