Skip to content

Commit

Permalink
Merge branch 'main' into auto-bump-grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemental authored May 8, 2024
2 parents 5110bb3 + c831311 commit 95875e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/364-first-datasource-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- Handling of desired default state for first `grafana_datasource`
- Ignore `type` argument for diff comparison if `grafana-postgresq-datasource` alias `postgres` is used
6 changes: 6 additions & 0 deletions plugins/modules/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ def compare_datasources(new, current, compareSecureData=True):
del current["password"]
if "basicAuthPassword" in current:
del current["basicAuthPassword"]
if current["type"] == "grafana-postgresql-datasource" and new["type"] == "postgres":
del current["type"]
del new["type"]

# check if secureJsonData should be compared
if not compareSecureData:
Expand Down Expand Up @@ -945,6 +948,9 @@ def main():
if ds is None:
grafana_iface.create_datasource(payload)
ds = grafana_iface.datasource_by_name(name)
if ds.get("isDefault") != module.params["is_default"]:
grafana_iface.update_datasource(ds.get("id"), payload)
ds = grafana_iface.datasource_by_name(name)
module.exit_json(
changed=True, datasource=ds, msg="Datasource %s created" % name
)
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/targets/grafana_datasource/tasks/elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,32 @@
- result.datasource.secureJsonFields.secureTest == true
- result.diff.after.secureJsonData is defined

- name: Delete elasticsearch legacy datasource
register: result
community.grafana.grafana_datasource:
name: datasource/elasticLegacy
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
state: absent

- ansible.builtin.assert:
that:
- result.changed

- name: Delete elasticsearch legacy datasource (idempotency)
register: result
community.grafana.grafana_datasource:
name: datasource/elasticLegacy
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
state: absent

- ansible.builtin.assert:
that:
- not result.changed

- name: Delete elasticsearch datasource
register: result
community.grafana.grafana_datasource:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
- result.datasource.jsonData.timescaledb == true
- result.datasource.name == 'datasource-postgres'
- result.datasource.orgId == 1
- result.datasource.type == 'postgres'
- result.datasource.type in ['postgres', 'grafana-postgresql-datasource']
- result.datasource.url == 'postgres.company.com:5432'
- result.datasource.user == 'postgres'
- result.datasource.withCredentials == false
Expand Down

0 comments on commit 95875e7

Please sign in to comment.