Skip to content

Commit 7c839dd

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

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

influxdb/buckets.sls

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,38 @@ 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+
{%- set data = salt['cmd.shell']("curl -v -s -f -H'Authorization: Token {{ influxdb['user']['admin']['token'] }}' https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/orgs &> /tmp/test_{{ config['name'] }}.txt") %}
24+
2225
get_bucket_{{ config['name'] }}:
2326
http.query:
24-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/buckets/{{ config['name'] }}'
27+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/buckets/{{ config['name'] }}'
2528
- status: 200
2629
- method: GET
2730
- header_dict:
2831
Authorization: Token {{ influxdb['user']['admin']['token'] }}
2932
3033
{%- 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']
34+
'name': config['name'],
35+
'description': config['description'] | default('A bucket for ' + config['name']),
36+
'orgID': orgID,
37+
'rp': config['retention_policy'] | default('0'),
3638
} %}
3739
create_bucket_{{ config['name'] }}:
3840
http.query:
39-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/buckets'
41+
- name: 'https://{{ influxdb['remote']['host'] }}:{{ influxdb['remote']['port'] }}/api/v2/buckets'
4042
- status: 200
4143
- method: POST
4244
- data: '{{ bucket_data | tojson }}'
4345
- header_dict:
4446
Authorization: Token {{ influxdb['user']['admin']['token'] }}
4547
- onfail:
4648
- 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'") %}
49+
{%- 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'") %}
50+
51+
testb_{{ config['name'] }}_{{ bucket }}:
52+
cmd.run:
53+
- name: echo {{ bucket }}
4854
{% endif %}
4955
5056
{%- 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)