Skip to content

Commit

Permalink
fix: remove requirement for ds_type and ds_url
Browse files Browse the repository at this point in the history
Require `ds_type` and `ds_url` only when creating / updating a
datasource.
  • Loading branch information
prndrbr authored and rrey committed Apr 18, 2022
1 parent 1fbcea6 commit 4d33a3f
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 104 deletions.
9 changes: 5 additions & 4 deletions plugins/modules/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ds_type:
description:
- The type of the datasource.
required: true
- Required when C(state=present).
choices:
- graphite
- prometheus
Expand All @@ -44,7 +44,7 @@
ds_url:
description:
- The URL of the datasource.
required: true
- Required when C(state=present).
type: str
access:
description:
Expand Down Expand Up @@ -673,8 +673,8 @@ def main():
'camptocamp-prometheus-alertmanager-datasource',
'sni-thruk-datasource',
'redis-datasource',
'loki'], required=True),
ds_url=dict(required=True, type='str'),
'loki']),
ds_url=dict(type='str'),
access=dict(default='proxy', choices=['proxy', 'direct']),
database=dict(type='str', default=""),
user=dict(default='', type='str'),
Expand Down Expand Up @@ -722,6 +722,7 @@ def main():
required_together=[['url_username', 'url_password', 'org_id'], ['tls_client_cert', 'tls_client_key']],
mutually_exclusive=[['url_username', 'grafana_api_key'], ['tls_ca_cert', 'tls_skip_verify']],
required_if=[
['state', 'present', ['ds_type', 'ds_url']],
['ds_type', 'opentsdb', ['tsdb_version', 'tsdb_resolution']],
['ds_type', 'influxdb', ['database']],
['ds_type', 'elasticsearch', ['database', 'es_version', 'time_field', 'interval']],
Expand Down
16 changes: 0 additions & 16 deletions tests/integration/targets/grafana_datasource/tasks/cloudwatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password}}"
org_id: '1'
ds_type: cloudwatch
ds_url: http://monitoring.us-west-1.amazonaws.com
aws_auth_type: keys
aws_default_region: us-west-1
aws_access_key: speakFriendAndEnter
aws_secret_key: mel10n
aws_custom_metrics_namespaces: n1,n2
state: absent

- debug:
Expand All @@ -109,14 +101,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password}}"
org_id: '1'
ds_type: cloudwatch
ds_url: http://monitoring.us-west-1.amazonaws.com
aws_auth_type: keys
aws_default_region: us-west-1
aws_access_key: speakFriendAndEnter
aws_secret_key: mel10n
aws_custom_metrics_namespaces: n1,n2
state: absent

- debug:
Expand Down
24 changes: 0 additions & 24 deletions tests/integration/targets/grafana_datasource/tasks/elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: elasticsearch
ds_url: https://elastic.company.com:9200
database: '[logstash_]YYYY.MM.DD'
basic_auth_user: grafana
basic_auth_password: '******'
time_field: '@timestamp'
time_interval: 1m
interval: Daily
es_version: 56
max_concurrent_shard_requests: 42
tls_ca_cert: /etc/ssl/certs/ca.pem
state: absent

- assert:
Expand All @@ -270,18 +258,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: elasticsearch
ds_url: https://elastic.company.com:9200
database: '[logstash_]YYYY.MM.DD'
basic_auth_user: grafana
basic_auth_password: '******'
time_field: '@timestamp'
time_interval: 1m
interval: Daily
es_version: 56
max_concurrent_shard_requests: 42
tls_ca_cert: /etc/ssl/certs/ca.pem
state: absent

- assert:
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/targets/grafana_datasource/tasks/errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Create datasource without `ds_type` and `ds_url` (expect failure)
register: result
grafana_datasource:
name: datasource-postgres
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
ignore_errors: true

- debug:
var: result

- assert:
that:
- not result.changed
- result.failed
- "result.msg == 'state is present but all of the following are missing: ds_type, ds_url'"
12 changes: 0 additions & 12 deletions tests/integration/targets/grafana_datasource/tasks/influx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: influxdb
ds_url: https://influx.company.com:8086
database: telegraf
time_interval: '>10s'
tls_ca_cert: /etc/ssl/certs/ca.pem
state: absent

- debug:
Expand All @@ -84,12 +78,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: influxdb
ds_url: https://influx.company.com:8086
database: telegraf
time_interval: '>10s'
tls_ca_cert: /etc/ssl/certs/ca.pem
state: absent

- debug:
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/targets/grafana_datasource/tasks/loki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password}}"
org_id: '1'
ds_type: loki
ds_url: https://loki.company.com:3100
state: absent

- debug:
Expand All @@ -75,9 +72,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password}}"
org_id: '1'
ds_type: loki
ds_url: https://loki.company.com:3100
state: absent

- debug:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---

- block:
- include: errors.yml
- include: elastic.yml
- include: influx.yml
- include: postgres.yml
Expand Down
14 changes: 0 additions & 14 deletions tests/integration/targets/grafana_datasource/tasks/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: postgres
ds_url: postgres.company.com:5432
database: db
user: postgres
password: iampgroot
sslmode: verify-full
state: absent

- debug:
Expand All @@ -90,13 +83,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: postgres
ds_url: postgres.company.com:5432
database: db
user: postgres
password: iampgroot
sslmode: verify-full
state: absent

- debug:
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/targets/grafana_datasource/tasks/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: redis-datasource
ds_url: https://redis.company.com:6379
state: absent

- assert:
Expand All @@ -97,9 +94,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: redis-datasource
ds_url: https://redis.company.com:6379
state: absent

- assert:
Expand Down
10 changes: 0 additions & 10 deletions tests/integration/targets/grafana_datasource/tasks/thruk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: "1"
ds_type: sni-thruk-datasource
ds_url: "https://thruk.company.com/sitename/thruk"
tls_skip_verify: yes
validate_certs: no
state: absent

- debug:
Expand All @@ -76,11 +71,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: "1"
ds_type: sni-thruk-datasource
ds_url: "https://thruk.company.com/sitename/thruk"
tls_skip_verify: yes
validate_certs: no
state: absent

- assert:
Expand Down
12 changes: 0 additions & 12 deletions tests/integration/targets/grafana_datasource/tasks/zabbix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: alexanderzobnin-zabbix-datasource
ds_url: https://zabbix.example.com
zabbix_user: grafana
zabbix_password: '******'
tls_ca_cert: /etc/ssl/certs/ca.pem
state: absent

- assert:
Expand All @@ -113,12 +107,6 @@
grafana_url: "{{ grafana_url }}"
grafana_user: "{{ grafana_username }}"
grafana_password: "{{ grafana_password }}"
org_id: '1'
ds_type: alexanderzobnin-zabbix-datasource
ds_url: https://zabbix.example.com
zabbix_user: grafana
zabbix_password: '******'
tls_ca_cert: /etc/ssl/certs/ca.pem
state: absent

- assert:
Expand Down

0 comments on commit 4d33a3f

Please sign in to comment.