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: Fixed Application Segment Drift with domain_names attribute #55

Merged
merged 4 commits into from
Feb 2, 2025
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Zscaler Private Access (ZPA) Ansible Collection Changelog

## 1.4.3 (February, 1 2025)

### Notes

- Python Versions: **v3.9, v3.10, v3.11**

### Bug Fixes

- [PR #55](https://github.com/zscaler/zpacloud-ansible/pull/55) Fixed drift issues with the attribute `domain_names` within the resources: `zpa_application_segment`, `zpa_application_segment_pra`, and `zpa_application_segment_inspection`.

## 1.4.2 (November, 4 2024)

### Notes
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
html_title = "Ansible Collections Documentation"

# The full version, including alpha/beta/rc tags
release = "1.4.2"
release = "1.4.3"

# Disable the Copyright footer for Read the docs at the bottom of the page
# by setting property html_show_copyright = False
Expand Down
14 changes: 14 additions & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ Releases
Zscaler Private Access (ZPA) Ansible Collection Changelog
---------------------------------------------------------

Version 1.4.3
==============

1.4.3 (February, 1 2025)
---------------------------

### Notes

- Python Versions: **v3.9, v3.10, v3.11**

### Bug Fixes

* (`#55 <https://github.com/zscaler/zpacloud-ansible/pull/55>`_) Fixed drift issues with the attribute `domain_names` within the resources: `zpa_application_segment`, `zpa_application_segment_pra`, and `zpa_application_segment_inspection`.

Version 1.4.2
==============

Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace: zscaler
name: zpacloud

# The version of the collection. Must be compatible with semantic versioning
version: 1.4.2
version: 1.4.3

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
41 changes: 31 additions & 10 deletions plugins/modules/zpa_application_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,33 @@ def core(module):

fields_to_exclude = ["id"]
differences_detected = False
for key, value in desired_app.items():
if key not in fields_to_exclude and current_app.get(key) != value:
differences_detected = True
# module.warn(
# f"Difference detected in {key}. Current: {current_app.get(key)}, Desired: {value}"
# )

for key, desired_value in desired_app.items():
if key in fields_to_exclude:
continue

current_value = current_app.get(key)

if key == "domain_names":
# Compare them as sorted lists to ignore order differences
if sorted(current_value or []) != sorted(desired_value or []):
differences_detected = True
module.warn(
f"Difference detected in domain_names. "
f"Current (sorted): {sorted(current_value or [])}, "
f"Desired (sorted): {sorted(desired_value or [])}"
)
else:
# Normal comparison for everything else
if current_value != desired_value:
differences_detected = True
module.warn(
f"Difference detected in {key}. "
f"Current: {current_value}, Desired: {desired_value}"
)
# module.warn(
# f"Difference detected in {key}. Current: {current_app.get(key)}, Desired: {desired_value}"
# )

if module.check_mode:
# If in check mode, report changes and exit
Expand All @@ -374,7 +395,7 @@ def core(module):
existing_app.update(app)
existing_app["id"] = id

# module.warn(f"Final payload being sent to SDK: {app}")
module.warn(f"Final payload being sent to SDK: {app}")
if state == "present":
if existing_app is not None:
if differences_detected:
Expand Down Expand Up @@ -419,7 +440,7 @@ def core(module):
),
)
)
# module.warn("Payload Update for SDK: {}".format(existing_app))
module.warn("Payload Update for SDK: {}".format(existing_app))
existing_app = client.app_segments.update_segment(
**existing_app
).to_dict()
Expand All @@ -428,7 +449,7 @@ def core(module):
"""No Changes Needed"""
module.exit_json(changed=False, data=existing_app)
else:
# module.warn("Creating app segment as no existing app segment was found")
module.warn("Creating app segment as no existing app segment was found")
"""Create"""
app = deleteNone(
dict(
Expand Down Expand Up @@ -459,7 +480,7 @@ def core(module):
udp_port_ranges=convert_ports_list(app.get("udp_port_range", None)),
)
)
# module.warn("Payload for SDK: {}".format(app))
module.warn("Payload for SDK: {}".format(app))
app = client.app_segments.add_segment(**app)
module.exit_json(changed=True, data=app)
elif (
Expand Down
34 changes: 27 additions & 7 deletions plugins/modules/zpa_application_segment_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,33 @@ def core(module):

fields_to_exclude = ["id"]
differences_detected = False
for key, value in desired_app.items():
if key not in fields_to_exclude and current_app.get(key) != value:
differences_detected = True
break
# module.warn(
# f"Difference detected in {key}. Current: {current_app.get(key)}, Desired: {value}"
# )

for key, desired_value in desired_app.items():
if key in fields_to_exclude:
continue

current_value = current_app.get(key)

if key == "domain_names":
# Compare them as sorted lists to ignore order differences
if sorted(current_value or []) != sorted(desired_value or []):
differences_detected = True
module.warn(
f"Difference detected in domain_names. "
f"Current (sorted): {sorted(current_value or [])}, "
f"Desired (sorted): {sorted(desired_value or [])}"
)
else:
# Normal comparison for everything else
if current_value != desired_value:
differences_detected = True
module.warn(
f"Difference detected in {key}. "
f"Current: {current_value}, Desired: {desired_value}"
)
# module.warn(
# f"Difference detected in {key}. Current: {current_app.get(key)}, Desired: {desired_value}"
# )

if module.check_mode:
# If in check mode, report changes and exit
Expand Down
34 changes: 27 additions & 7 deletions plugins/modules/zpa_application_segment_pra.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,33 @@ def core(module):

fields_to_exclude = ["id"]
differences_detected = False
for key, value in desired_app.items():
if key not in fields_to_exclude and current_app.get(key) != value:
differences_detected = True
break
# module.warn(
# f"Difference detected in {key}. Current: {current_app.get(key)}, Desired: {value}"
# )

for key, desired_value in desired_app.items():
if key in fields_to_exclude:
continue

current_value = current_app.get(key)

if key == "domain_names":
# Compare them as sorted lists to ignore order differences
if sorted(current_value or []) != sorted(desired_value or []):
differences_detected = True
module.warn(
f"Difference detected in domain_names. "
f"Current (sorted): {sorted(current_value or [])}, "
f"Desired (sorted): {sorted(desired_value or [])}"
)
else:
# Normal comparison for everything else
if current_value != desired_value:
differences_detected = True
module.warn(
f"Difference detected in {key}. "
f"Current: {current_value}, Desired: {desired_value}"
)
# module.warn(
# f"Difference detected in {key}. Current: {current_app.get(key)}, Desired: {desired_value}"
# )

if module.check_mode:
# If in check mode, report changes and exit
Expand Down
Loading