Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grafana_datasource): handling of desired default state #364

Merged
merged 7 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":
rndmh3ro marked this conversation as resolved.
Show resolved Hide resolved
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
Loading