diff --git a/plugins/module_utils/nat_port_forward.py b/plugins/module_utils/nat_port_forward.py index 41649ad8..a20200d2 100644 --- a/plugins/module_utils/nat_port_forward.py +++ b/plugins/module_utils/nat_port_forward.py @@ -123,8 +123,12 @@ def _parse_target_address(self, obj): else: self.module.fail_json(msg='"%s" is not a valid redirect target IP address or host alias.' % (param)) - if ports is None and self.params['protocol'] in ["tcp", "udp", "tcp/udp"]: - self.module.fail_json(msg='Must specify a target port with protocol "{0}".'.format(self.params['protocol'])) + if ports is None: + if self.params['protocol'] in ["tcp", "udp", "tcp/udp"]: + self.module.fail_json(msg='Must specify a target port with protocol "{0}".'.format(self.params['protocol'])) + else: + # pfSense seems to always add an empty local-port element + obj['local-port'] = '' if ports is not None: if self.params['protocol'] not in ["tcp", "udp", "tcp/udp"]: diff --git a/tests/unit/plugins/modules/test_pfsense_nat_port_forward.py b/tests/unit/plugins/modules/test_pfsense_nat_port_forward.py index 5173d1b1..9d2e6858 100644 --- a/tests/unit/plugins/modules/test_pfsense_nat_port_forward.py +++ b/tests/unit/plugins/modules/test_pfsense_nat_port_forward.py @@ -54,6 +54,7 @@ def check_target_elt(self, obj, target_elt, target_idx=-1): self.check_value_equal(target_elt, 'interface', self.unalias_interface(obj['interface'])) self.check_param_equal(obj, target_elt, 'ipprotocol', 'inet') self.check_param_equal(obj, target_elt, 'protocol', 'tcp') + self.check_param_equal_or_present(obj, target_elt, 'local-port') self.check_rule_idx(obj, target_idx) if 'associated_rule' not in obj: