Skip to content

Commit

Permalink
refactor: get ds payload optional org_id parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemental authored and rndmh3ro committed Jan 18, 2024
1 parent 63db02f commit 1acfb76
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions plugins/modules/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=None):
payload = {
"orgId": data["org_id"],
"orgId": data["org_id"] if org_id is None else org_id,
"name": data["name"],
"uid": data["uid"],
"type": data["ds_type"],
Expand Down Expand Up @@ -923,13 +923,12 @@ def main():
ds = grafana_iface.datasource_by_name(name)

if state == "present":
params = module.params
params["org_id"] = (
grafana_iface.organization_by_name(params["org_name"])
if params["org_name"]
else params["org_id"]
org_id = (
grafana_iface.organization_by_name(module.params["org_name"])
if module.params["org_name"]
else module.params["org_id"]
)
payload = get_datasource_payload(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)
Expand Down

0 comments on commit 1acfb76

Please sign in to comment.