Skip to content

Commit

Permalink
feat: get folders by uid and parent_uid if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemental committed Jun 26, 2024
1 parent 0d19c64 commit 2150a4e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugins/modules/grafana_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,31 @@ def main():
)
state = module.params["state"]
title = module.params["name"]
parent_uid = module.params["parent_uid"]
uid = module.params["uid"]
module.params["url"] = base.clean_url(module.params["url"])

grafana_iface = GrafanaFolderInterface(module)

changed = False
if state == "present":

if uid and parent_uid:
folder = grafana_iface.get_folder(title, uid, parent_uid)
elif uid:
folder = grafana_iface.get_folder(title, uid)
elif parent_uid:
folder = grafana_iface.get_folder(title, parent_uid=parent_uid)
else:
folder = grafana_iface.get_folder(title)

if state == "present":
if folder is None:
grafana_iface.create_folder(title)
folder = grafana_iface.get_folder(title)
changed = True
folder = grafana_iface.get_folder(title)
module.exit_json(changed=changed, folder=folder)
elif state == "absent":
folder = grafana_iface.get_folder(title)
if folder is None:
module.exit_json(changed=False, message="No folder found")
result = grafana_iface.delete_folder(folder.get("uid"))
Expand Down

0 comments on commit 2150a4e

Please sign in to comment.