Skip to content

Commit b722e12

Browse files
committed
fix: bucket config
1 parent 6ff082f commit b722e12

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

influxdb/buckets.sls

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,41 @@ influxdb_bucket_{{ config['name'] }}:
1919
- pkg: jq
2020
{%- set bucket = salt['cmd.shell']("influx bucket list --json | jq -r '.[] | select(.name == \"" + config['name'] + "\").id'") %}
2121
{% else %}
22+
{%- set orgID = salt['cmd.shell']("curl -s -f -H'Authorization: Token {{ influxdb['user']['admin']['token'] }}' https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/orgs | jq -r '.orgs[0].id'") %}
23+
24+
test_{{ config['name'] }}:
25+
cmd.run:
26+
- name: echo {{ orgID }}
27+
2228
get_bucket_{{ config['name'] }}:
2329
http.query:
24-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/buckets/{{ config['name'] }}'
30+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/buckets/{{ config['name'] }}'
2531
- status: 200
2632
- method: GET
2733
- header_dict:
2834
Authorization: Token {{ influxdb['user']['admin']['token'] }}
2935
3036
{%- set bucket_data = {
31-
name: config['name'],
32-
description: config['description'] | default('A bucket for ' + config['name']),
33-
orgID: config['orgID'],
34-
retentionRules: [],
35-
rp: config['retention_policy']
37+
'name': config['name'],
38+
'description': config['description'] | default('A bucket for ' + config['name']),
39+
'orgID': orgID,
40+
'rp': config['retention_policy'] | default('0'),
3641
} %}
3742
create_bucket_{{ config['name'] }}:
3843
http.query:
39-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/buckets'
44+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/buckets'
4045
- status: 200
4146
- method: POST
4247
- data: '{{ bucket_data | tojson }}'
4348
- header_dict:
4449
Authorization: Token {{ influxdb['user']['admin']['token'] }}
4550
- onfail:
4651
- http: get_bucket_{{ config['name'] }}
47-
{%- set bucket = salt['cmd.shell']("curl -s -f -H'Authorization: Token {{ influxdb['user']['admin']['token'] }}' https://{{ influxdb['remote']['host'] }}/api/v2/buckets | jq -r '.[] | select(.name == \"" + config['name'] + "\").id'") %}
52+
{%- set bucket = salt['cmd.shell']("curl -s -f -H'Authorization: Token {{ influxdb['user']['admin']['token'] }}' https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/buckets | jq -r '.buckets[] | select(.name == \"" + config['name'] + "\").id'") %}
53+
54+
testb_{{ config['name'] }}:
55+
cmd.run:
56+
- name: echo {{ bucket }}
4857
{% endif %}
4958
5059
{%- if 'mapping' in config and bucket %}

influxdb/users.sls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ influxdb_user_{{ loop.index0 }}:
2020
{% for name,config in influxdb["user"].items() %}
2121
get_user_{{ loop.index0 }}:
2222
http.query:
23-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/users/{{ name }}'
23+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/users/{{ name }}'
2424
- status: 200
2525
- method: GET
2626
- header_dict:
2727
Authorization: Token {{ influxdb['user']['admin']['token'] }}
2828
2929
create_user_{{ loop.index0 }}:
3030
http.query:
31-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/users'
31+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/users'
3232
- status: 200
3333
- method: POST
3434
- data: '{"name": "{{ name }}"}'
@@ -40,7 +40,7 @@ create_user_{{ loop.index0 }}:
4040
{% if "password" in config %}
4141
set_password_{{ loop.index0 }}:
4242
http.query:
43-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/users{{ name }}/password'
43+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/users/{{ name }}/password'
4444
- status: 200
4545
- method: POST
4646
- data: '{"password": "{{ config["password"] }}"}'

0 commit comments

Comments
 (0)