Skip to content

Commit 8526d7d

Browse files
authored
Merge pull request #5894 from influxdata/jstirnaman/issue5869
fix(cloudv2): Doesn't support environment references in templates
2 parents 271b0a2 + e6fffd7 commit 8526d7d

File tree

7 files changed

+324
-286
lines changed

7 files changed

+324
-286
lines changed

Dockerfile.pytest

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ RUN echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influ
1010

1111
RUN echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | tee /etc/apt/sources.list.d/influxdata.list
1212

13+
# Vault is used for testing InfluxDB 2.0 Secrets
14+
# Fetch vault package information from HashiCorp repository
15+
ADD https://apt.releases.hashicorp.com/gpg /tmp/hashicorp.gpg
16+
RUN apt-get update && apt-get install -y lsb-release && \
17+
cat /tmp/hashicorp.gpg | gpg --dearmor > /usr/share/keyrings/hashicorp-archive-keyring.gpg && \
18+
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
19+
tee /etc/apt/sources.list.d/hashicorp.list
20+
21+
1322
# Install depedencies for clients and tests.
1423
# - InfluxData clients to use in tests.
1524
# - apt-utils for verification tools
@@ -32,6 +41,7 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
3241
python3-venv \
3342
rsync \
3443
telegraf \
44+
vault \
3545
wget \
3646
yq
3747

@@ -55,6 +65,7 @@ WORKDIR /app
5565

5666
RUN mkdir -p /app/log && chmod +w /app/log
5767
RUN mkdir -p /app/assets && chmod +w /app/assets
68+
RUN mkdir -p /root/influxdb/templates && chmod +rw /root/influxdb/templates
5869

5970
# Some Python test dependencies (pytest-dotenv and pytest-codeblocks) aren't
6071
# available as packages in apt-cache, so use pip to download dependencies in a # separate step and use Docker's caching.
@@ -78,6 +89,7 @@ RUN echo '#!/bin/bash' > /usr/local/bin/xdg-open \
7889
&& chmod +x /usr/local/bin/xdg-open
7990

8091
RUN service influxdb start
92+
RUN vault server -dev > ~/.vault-server-log 2>&1 &
8193

8294
# Copy test scripts and make them executable.
8395
COPY --chmod=755 ./test/scripts/parse_yaml.sh /usr/local/bin/parse_yaml

api-docs/influxdb/cloud/v2/ref.yml

Lines changed: 7 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10564,13 +10564,12 @@ paths:
1056410564
template and generates the resource diff, but doesn’t make any
1056510565
changes to your instance.
1056610566

10567+
**Important**: InfluxDB Cloud doesn't support all template features. We recommend using InfluxDB OSS v2 if you need full template support.
10568+
1056710569
#### Custom values for templates
1056810570

10569-
- Some templates may contain [environment references](/influxdb/cloud/influxdb-templates/create/#include-user-definable-resource-names) for custom metadata.
10570-
To provide custom values for environment references, pass the _`envRefs`_
10571-
property in the request body.
10572-
For more information and examples, see how to
10573-
[define environment references](/influxdb/cloud/influxdb-templates/use/#define-environment-references).
10571+
- **Not supported**: InfluxDB Cloud doesn't
10572+
support environment reference substitution in templates. Variable names you define in templates aren't replaced by user-defined values.
1057410573

1057510574
- Some templates may contain queries that use
1057610575
[secrets](/influxdb/cloud/security/secrets/).
@@ -10782,67 +10781,6 @@ paths:
1078210781
]
1078310782
}
1078410783
EOF
10785-
- label: 'cURL: Apply template objects with environment references'
10786-
lang: Shell
10787-
source: |
10788-
curl --request POST "http://localhost:8086/api/v2/templates/apply" \
10789-
--header "Authorization: Token INFLUX_API_TOKEN" \
10790-
--data @- << EOF
10791-
{ "orgID": "INFLUX_ORG_ID",
10792-
"envRefs": {
10793-
"linux-cpu-label": "MY_CPU_LABEL",
10794-
"docker-bucket": "MY_DOCKER_BUCKET",
10795-
"docker-spec-1": "MY_DOCKER_SPEC"
10796-
},
10797-
"templates": [
10798-
{ "contents": [{
10799-
"apiVersion": "influxdata.com/v2alpha1",
10800-
"kind": "Label",
10801-
"metadata": {
10802-
"name": {
10803-
"envRef": {
10804-
"key": "linux-cpu-label"
10805-
}
10806-
}
10807-
},
10808-
"spec": {
10809-
"color": "#326BBA",
10810-
"name": "inputs.cpu"
10811-
}
10812-
}]
10813-
},
10814-
"templates": [
10815-
{ "contents": [{
10816-
"apiVersion": "influxdata.com/v2alpha1",
10817-
"kind": "Label",
10818-
"metadata": {
10819-
"name": {
10820-
"envRef": {
10821-
"key": "linux-cpu-label"
10822-
}
10823-
}
10824-
},
10825-
"spec": {
10826-
"color": "#326BBA",
10827-
"name": "inputs.cpu"
10828-
}
10829-
}]
10830-
},
10831-
{ "contents": [{
10832-
"apiVersion": "influxdata.com/v2alpha1",
10833-
"kind": "Bucket",
10834-
"metadata": {
10835-
"name": {
10836-
"envRef": {
10837-
"key": "docker-bucket"
10838-
}
10839-
}
10840-
}
10841-
}]
10842-
}
10843-
]
10844-
}
10845-
EOF
1084610784
/api/v2/templates/export:
1084710785
post:
1084810786
operationId: ExportTemplate
@@ -17707,26 +17645,10 @@ components:
1770717645
- type: number
1770817646
- type: boolean
1770917647
description: |
17710-
An object with key-value pairs that map to **environment references** in templates.
17648+
- **Not supported**: InfluxDB Cloud doesn't
17649+
support environment reference substitution in templates. Variable names you define in templates aren't replaced by user-defined values.
1771117650

17712-
Environment references in templates are `envRef` objects with an `envRef.key`
17713-
property.
17714-
To substitute a custom environment reference value when applying templates,
17715-
pass `envRefs` with the `envRef.key` and the value.
17716-
17717-
When you apply a template, InfluxDB replaces `envRef` objects in the template
17718-
with the values that you provide in the `envRefs` parameter.
17719-
For more examples, see how to [define environment references](/influxdb/cloud/influxdb-templates/use/#define-environment-references).
17720-
17721-
The following template fields may use environment references:
17722-
17723-
- `metadata.name`
17724-
- `spec.endpointName`
17725-
- `spec.associations.name`
17726-
17727-
For more information about including environment references in template fields, see how to
17728-
[include user-definable resource names](/influxdb/cloud/influxdb-templates/create/#include-user-definable-resource-names).
17729-
type: object
17651+
**Important**: InfluxDB Cloud doesn't support all template features. We recommend using InfluxDB OSS v2 if you need full template support.
1773017652
orgID:
1773117653
description: |
1773217654
Organization ID.

content/influxdb/cloud/tools/influxdb-templates/create.md

Lines changed: 10 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ influx export all --org <INFLUX_ORG> --file <FILE_PATH> --token <INFLUX_TOKEN>
6767
# Example
6868
influx export all \
6969
--org $INFLUX_ORG \
70-
--file /path/to/TEMPLATE_FILE.yml \
70+
--file /path/to/templates/TEMPLATE_FILE.yml \
7171
--token $INFLUX_TOKEN
7272
```
7373

@@ -85,10 +85,10 @@ and
8585
(labelName == "Example1" or labelName == "Example2")
8686
```
8787

88-
```sh
88+
```bash
8989
influx export all \
9090
--org $INFLUX_ORG \
91-
--file /path/to/TEMPLATE_FILE.yml \
91+
--file /path/to/templates/TEMPLATE_FILE.yml \
9292
--token $INFLUX_TOKEN \
9393
--filter=resourceKind=Bucket \
9494
--filter=resourceKind=Dashboard \
@@ -128,7 +128,7 @@ influx export --file <FILE_PATH> --token <INFLUX_TOKEN> [resource-flags]
128128
```bash
129129
# Example
130130
influx export \
131-
--file /path/to/TEMPLATE_FILE.yml \
131+
--file /path/to/templates/TEMPLATE_FILE.yml \
132132
--token $INFLUX_TOKEN \
133133
--buckets=00x000ooo0xx0xx,o0xx0xx00x000oo \
134134
--dashboards=00000xX0x0X00x000 \
@@ -165,119 +165,17 @@ influx export stack \
165165
# Example
166166
influx export stack \
167167
-t $INFLUX_TOKEN \
168-
-f /path/to/TEMPLATE_FILE.yml \
168+
-f /path/to/templates/TEMPLATE_FILE.yml \
169169
05dbb791a4324000
170170
```
171171

172172
## Include user-definable resource names
173-
After exporting a template manifest, replace resource names with **environment references**
174-
to let users customize resource names when installing your template.
175-
176-
1. [Export a template](#export-a-template)
177-
2. Select any of the following resource fields to update:
178-
179-
- `metadata.name`
180-
- `associations[].name`
181-
- `endpointName` _(unique to `NotificationRule` resources)_
182-
183-
3. Replace the resource field value with an `envRef` object with a `key` property
184-
that reference the key of a key-value pair the user provides when installing the template.
185-
During installation, the `envRef` object is replaced by the value of the
186-
referenced key-value pair.
187-
If the user does not provide the environment reference key-value pair, InfluxDB
188-
uses the `key` string as the default value.
189-
190-
{{< code-tabs-wrapper >}}
191-
{{% code-tabs %}}
192-
[YAML](#)
193-
[JSON](#)
194-
{{% /code-tabs %}}
195-
{{% code-tab-content %}}
196-
```yml
197-
apiVersion: influxdata.com/v2alpha1
198-
kind: Bucket
199-
metadata:
200-
name:
201-
envRef:
202-
key: bucket-name-1
203-
```
204-
{{% /code-tab-content %}}
205-
{{% code-tab-content %}}
206-
```json
207-
{
208-
"apiVersion": "influxdata.com/v2alpha1",
209-
"kind": "Bucket",
210-
"metadata": {
211-
"name": {
212-
"envRef": {
213-
"key": "bucket-name-1"
214-
}
215-
}
216-
}
217-
}
218-
```
219-
{{% /code-tab-content %}}
220-
{{< /code-tabs-wrapper >}}
221-
222-
Using the example above, users are prompted to provide a value for `bucket-name-1`
223-
when [applying the template](/influxdb/cloud/tools/influxdb-templates/use/#apply-templates).
224-
Users can also include the `--env-ref` flag with the appropriate key-value pair
225-
when installing the template.
226173

227-
<!-- //REVIEW I can't get this to work with environment reference substitution
228-
-- Skipping the test for now, but we should review it and fix it.
229-
-->
230-
<!--pytest.mark.skip-->
231-
<!--test:setup
232-
```sh
233-
jq -n '{
234-
apiVersion: "influxdata.com/v2alpha1",
235-
kind: "Bucket",
236-
metadata: {
237-
name: {
238-
envRef: {
239-
key: "bucket-name-1"
240-
}
241-
}
242-
}
243-
}' > /path/to/TEMPLATE_FILE.json
244-
chmod +rx /path/to/TEMPLATE_FILE.json
245-
# View formatted JSON
246-
jq '.' /path/to/TEMPLATE_FILE.json
247-
```
248-
-->
249-
250-
For example, to set a custom bucket name when applying a template with an environment reference:
251-
252-
<!--pytest-codeblocks:cont-->
253-
```sh
254-
# The template, edited to include an environment reference:
255-
# apiVersion: influxdata.com/v2alpha1
256-
# kind: Bucket
257-
# metadata:
258-
# name:
259-
# envRef: bucket-name-1
260-
261-
# Apply template, set bucket-name-1 to "myBucket", and skip verification
262-
influx apply \
263-
--file /path/to/TEMPLATE_FILE.json \
264-
--env-ref bucket-name-1=myBucket \
265-
--force yes
266-
--org $INFLUX_ORG
267-
--token $INFLUX_TOKEN
268-
```
269-
270-
_If sharing your template, we recommend documenting what environment references
271-
exist in the template and what keys to use to replace them._
272-
273-
{{% note %}}
274-
#### Resource fields that support environment references
275-
Only the following fields support environment references:
276-
277-
- `metadata.name`
278-
- `spec.endpointName`
279-
- `spec.associations.name`
280-
{{% /note %}}
174+
> [!Warning]
175+
>
176+
> #### Environment reference substitution not supported
177+
>
178+
> This feature is not supported by InfluxDB Cloud.
281179
282180
## Share your InfluxDB templates
283181
Share your InfluxDB templates with the entire InfluxData community.

content/influxdb/v2/admin/secrets/use-vault.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ The following links provide information about running Vault in both development
3131
- [Start a Vault dev server](https://learn.hashicorp.com/vault/getting-started/dev-server)
3232
- [Deploy Vault](https://learn.hashicorp.com/vault/getting-started/deploy)
3333

34-
{{% note %}}
35-
InfluxDB supports the [Vault KV Secrets Engine Version 2 API](https://www.vaultproject.io/api/secret/kv/kv-v2.html) only.
36-
When you create a secrets engine, enable the `kv-v2` version by running:
37-
38-
```js
39-
vault secrets enable kv-v2
40-
```
41-
{{% /note %}}
34+
> [!Note]
35+
> InfluxDB supports the [Vault KV Secrets Engine Version 2 API](https://www.vaultproject.io/api/secret/kv/kv-v2.html) only.
36+
> When you create a secrets engine, enable the `kv-v2` version by running:
37+
>
38+
> ```js
39+
> vault secrets enable kv-v2
40+
> ```
4241
4342
For this example, install Vault on your local machine and start a Vault dev server.
4443
45-
```sh
44+
<!--pytest.mark.skip-->
45+
```bash
4646
vault server -dev
4747
```
4848
@@ -70,12 +70,23 @@ _Your Vault server configuration may require other Vault settings._
7070
## Start InfluxDB
7171

7272
Start the [`influxd` service](/influxdb/v2/reference/cli/influxd/) with the `--secret-store`
73-
option set to `vault` any other necessary flags.
73+
option set to `vault` and any other necessary flags--for example, enter the following
74+
command:
7475

76+
<!--pytest.mark.skip-->
77+
<!--test:setup
78+
```bash
79+
service influxdb stop \
80+
&& service influxdb start --secret-store vault \
81+
--vault-addr=http://127.0.0.1:8200 \
82+
--vault-token=$VAULT_TOKEN
83+
```
84+
-->
85+
<!--pytest.mark.skip-->
7586
```bash
7687
influxd --secret-store vault \
7788
--vault-addr=http://127.0.0.1:8200 \
78-
--vault-token=s.0X0XxXXx0xXxXXxxxXxXxX0x
89+
--vault-token=$VAULT_TOKEN
7990
```
8091

8192
`influxd` includes the following Vault configuration options.
@@ -97,4 +108,4 @@ For more information, see [InfluxDB configuration options](/influxdb/v2/referenc
97108
## Manage secrets through the InfluxDB API
98109

99110
Use the InfluxDB `/org/{orgID}/secrets` API endpoint to add tokens to Vault.
100-
For details, see [Manage secrets](/influxdb/v2/admin/secrets/manage-secrets/).
111+
For details, see [Secrets](/influxdb/v2/admin/secrets/).

0 commit comments

Comments
 (0)