From d0a1ffb2166f44269a8172a14773badc13d9a146 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:17:08 +0200 Subject: [PATCH 1/6] fix: handling of desired default state --- plugins/modules/grafana_datasource.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 9b1aea6a..1ab24131 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -945,6 +945,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 ) From 3ff475ca980838486b372f44620cfc298db41834 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:20:23 +0200 Subject: [PATCH 2/6] docs: changelog fragment --- changelogs/fragments/364-first-datasource-default.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/364-first-datasource-default.yml diff --git a/changelogs/fragments/364-first-datasource-default.yml b/changelogs/fragments/364-first-datasource-default.yml new file mode 100644 index 00000000..e84d1e45 --- /dev/null +++ b/changelogs/fragments/364-first-datasource-default.yml @@ -0,0 +1,2 @@ +bugfixes: + - Handling of desired default state for first `grafana_datasource` From 2fab33e04c98ffe990d18ade0dbf38e5201b016d Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:27:53 +0200 Subject: [PATCH 3/6] test: remove remaining test datasource --- .../grafana_datasource/tasks/elastic.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/targets/grafana_datasource/tasks/elastic.yml b/tests/integration/targets/grafana_datasource/tasks/elastic.yml index ff05b93f..be587357 100644 --- a/tests/integration/targets/grafana_datasource/tasks/elastic.yml +++ b/tests/integration/targets/grafana_datasource/tasks/elastic.yml @@ -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: From 4088424dde4345d1747b7c956a52fe5d6e429e94 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:28:17 +0200 Subject: [PATCH 4/6] test: new postgres datasource type --- tests/integration/targets/grafana_datasource/tasks/postgres.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/grafana_datasource/tasks/postgres.yml b/tests/integration/targets/grafana_datasource/tasks/postgres.yml index b07bc752..8945e2bd 100644 --- a/tests/integration/targets/grafana_datasource/tasks/postgres.yml +++ b/tests/integration/targets/grafana_datasource/tasks/postgres.yml @@ -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 From d150a615045af8aabd371df443d61018851099a1 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:05:58 +0200 Subject: [PATCH 5/6] fix: remove type from diff if postgres --- plugins/modules/grafana_datasource.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 1ab24131..b011e5db 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -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: From 0f7cac37119b774b74ef6636c870927da1feaeed Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:19:22 +0200 Subject: [PATCH 6/6] docs: changelog fragment updated --- changelogs/fragments/364-first-datasource-default.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/changelogs/fragments/364-first-datasource-default.yml b/changelogs/fragments/364-first-datasource-default.yml index e84d1e45..3d39e9a0 100644 --- a/changelogs/fragments/364-first-datasource-default.yml +++ b/changelogs/fragments/364-first-datasource-default.yml @@ -1,2 +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