From 41596d36689fbd9e9f3ab94bffe08425fc3892c4 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:19:36 +0100 Subject: [PATCH] fix: orgId by name if defined to compare diff --- plugins/modules/grafana_datasource.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index be631836..ffc8d952 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -559,9 +559,9 @@ def compare_datasources(new, current, compareSecureData=True): return dict(before=current, after=new) -def get_datasource_payload(data): +def get_datasource_payload(data, org_id): payload = { - "orgId": data["org_id"], + "orgId": org_id, "name": data["name"], "uid": data["uid"], "type": data["ds_type"], @@ -921,9 +921,14 @@ def main(): grafana_iface = GrafanaInterface(module) ds = grafana_iface.datasource_by_name(name) + org_id = ( + grafana_iface.organization_by_name(module.params["org_name"]) + if module.params["org_name"] + else module.params["org_id"] + ) if state == "present": - payload = get_datasource_payload(module.params) + payload = get_datasource_payload(module.params, org_id) if ds is None: grafana_iface.create_datasource(payload) ds = grafana_iface.datasource_by_name(name)