Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemental authored and rndmh3ro committed Jan 18, 2024
1 parent f89f2ea commit b9472a7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 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, org_id):
def get_datasource_payload(data):
payload = {
"orgId": org_id,
"orgId": data["org_id"],
"name": data["name"],
"uid": data["uid"],
"type": data["ds_type"],
Expand Down Expand Up @@ -921,14 +921,15 @@ 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, org_id)
params = module.params
params["org_id"] = (
grafana_iface.organization_by_name(params["org_name"])
if params["org_name"]
else params["org_id"]
)
payload = get_datasource_payload(params)
if ds is None:
grafana_iface.create_datasource(payload)
ds = grafana_iface.datasource_by_name(name)
Expand Down

0 comments on commit b9472a7

Please sign in to comment.