Skip to content

ec2_vpc_nacl - fix issue occurring when updating existing NACL rule #2626

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- ec2_vpc_nacl - Fix issue when trying to update existing Network ACL rule (https://github.com/ansible-collections/amazon.aws/issues/2592).
13 changes: 7 additions & 6 deletions plugins/modules/ec2_vpc_nacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ def rules_changed(
removed_rules = find_added_rules(aws_rules, ansible_rules)

changed = False
# Removed Rules
for rule in removed_rules:
changed = True
if not check_mode:
delete_network_acl_entry(client, network_acl_id=nacl_id, rule_number=rule["RuleNumber"], egress=egress)

# Added Rules
for rule in added_rules:
changed = True
if not check_mode:
Expand All @@ -315,12 +322,6 @@ def rules_changed(
**rule,
)

# Removed Rules
for rule in removed_rules:
changed = True
if not check_mode:
delete_network_acl_entry(client, network_acl_id=nacl_id, rule_number=rule["RuleNumber"], egress=egress)

return changed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,43 @@
- nacl_facts.nacls[0].ingress | length == 2
- nacl_facts.nacls[0].egress | length == 2

# ============================================================

- name: Update egress rule
amazon.aws.ec2_vpc_nacl:
vpc_id: "{{ vpc_id }}"
name: "{{ nacl_name }}"
subnets: "{{ subnet_ids }}"
tags:
Created_by: "Ansible test {{ resource_prefix }}"
ingress:
- [100, "tcp", "allow", "0.0.0.0/0", !!null "", !!null "", 22, 22]
- [200, "tcp", "allow", "0.0.0.0/0", !!null "", !!null "", 80, 80]
egress:
- [100, "tcp", "allow", "192.68.0.0/24", !!null "", !!null "", 22, 22]
- [200, "udp", "allow", "192.68.0.0/24", !!null "", !!null "", 443, 443]
state: "present"
register: nacl

- name: Assert the network acl changed
ansible.builtin.assert:
that:
- nacl.changed
- nacl.nacl_id.startswith('acl-')

- name: Get network ACL facts
amazon.aws.ec2_vpc_nacl_info:
nacl_ids:
- "{{ nacl.nacl_id }}"
register: nacl_facts

- name: Assert the nacl has the correct attributes
ansible.builtin.assert:
that:
- nacl_facts.nacls | length == 1
- nacl_facts.nacls[0].ingress | length == 2
- nacl_facts.nacls[0].egress | length == 2

# ============================================================

- name: Remove the network ACL
Expand Down