Use InfluxDB templates

This page documents an earlier version of InfluxDB. InfluxDB v2.7 is the latest stable version. View this page in the v2.7 documentation.

Preview, validate, and apply templates for InfluxDB resources. Learn how to find and use InfluxDB community templates. Learn how to use secrets and custom names in templates.

Get prebuilt templates

The InfluxDB community templates repository is home to a growing number of InfluxDB templates developed and maintained by others in the InfluxData community. You can use the CLI or API to apply community templates directly from GitHub URLs or you can download the templates and apply them from your system.

The master branch of the InfluxDB community templates repository contains the most current published version of each template. When attempting to access community templates via URL, use the following as the root of the template URL:

  1. https://raw.githubusercontent.com/influxdata/community-templates/master/

For example, the most current version of the Docker community template can be accessed via:

  1. https://raw.githubusercontent.com/influxdata/community-templates/master/docker/docker.yml

View InfluxDB Community Templates

View a template summary

With the influx CLI, you can generate a summary of template resources. The summary contains resource metadata in table format that you can review before applying the template to your InfluxDB instance. You can generate a summary for a template located at a file path or at a URL.

You can’t generate a template summary with the InfluxDB /api/v2 API.

View a template summary with the CLI

To view a template summary, use the influx template command.

  1. # Syntax
  2. influx template --file TEMPLATE_FILE_PATH
  3. influx template -f TEMPLATE_FILE_PATH
  4. influx template --template-url TEMPLATE_FILE_URL
  5. influx template -u TEMPLATE_FILE_URL

--file and --template-url aren’t repeatable with the influx template command; you can only generate a summary for one template at a time.

The following code samples show how to generate a template summary:

  • Summarize a template located on the local file system:

    1. influx template --file /Users/me/template.yml
  • Summarize a template located at a remote URL:

    1. influx template --template-url https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml

The output is a series of tables that contain template resource metadata.

Validate a template

Use the CLI or API to validate and troubleshoot templates before you apply them to your InfluxDB instance.

Validate a template with the CLI

Use the influx template validate command to validate a template from your local file system or a URL.

  1. # Syntax
  2. influx template validate --file TEMPLATE_FILE_PATH
  3. influx template validate -f TEMPLATE_FILE_PATH
  4. influx template validate --template-url TEMPLATE_FILE_URL
  5. influx template validate -u TEMPLATE_FILE_URL

The following code sample shows how to validate a template located on the local file system:

  1. influx template validate --file /path/to/template.yml

The following code sample shows how to validate the linux_system community template located on GitHub:

  1. influx template validate --template-url https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml

To validate a template and preview the changes for your InfluxDB instance, see how to use a template dry run.

Validate a template with the API

To validate a template with the API, use a template dry run.

Use a template dry run to preview changes

Before you install a template, you can do a dry run to preview the installation.

By default, when you apply a template, InfluxDB installs the template, creates or updates resources in the stack, and generates a diff of the changes. With the dryRun option, InfluxDB validates the template and generates the resource diff, but doesn’t make any changes to your instance.

To do a template dry run, pass "dryRun": true in the InfluxDB /api/v2/templates/apply API endpoint request body.

  1. POST /api/v2/templates/apply

When running API code samples, replace the following in each sample:

  • INFLUX_TOKEN: your InfluxDB API token that has write permission for the organization.
  • INFLUX_ORG_ID: your InfluxDB organization ID.

When applying templates, you must use an API token that has write permission for the resource types configured in the template. See tokens for more information.

Consider a template that contains an unsupported value–for example, the following template contains an invalid InfluxDB resource type ("kind": "Foo"):

  1. {
  2. "contents": [
  3. {
  4. "apiVersion": "influxdata.com/v2alpha1",
  5. "kind": "Foo",
  6. "metadata": {
  7. "name": "unruffled-benz-d4d007"
  8. },
  9. "spec": {
  10. "color": "#326BBA",
  11. "name": "inputs.cpu"
  12. }
  13. },
  14. {
  15. "apiVersion": "influxdata.com/v2alpha1",
  16. "kind": "Label",
  17. "metadata": {
  18. "name": "unruffled-boa-d4a001"
  19. },
  20. "spec": {
  21. "color": "#326BBA",
  22. "name": "inputs.mem"
  23. }
  24. }
  25. ]
  26. }

The following code sample shows how to pass dryRun: true and the template to the /api/v2/templates/apply endpoint:

  1. curl "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF
  4. {
  5. "dryRun": true,
  6. "orgID": "INFLUX_ORG_ID",
  7. "template":
  8. {
  9. "contents": [
  10. {
  11. "apiVersion": "influxdata.com/v2alpha1",
  12. "kind": "Foo",
  13. "metadata": {
  14. "name": "unruffled-benz-d4d007"
  15. },
  16. "spec": {
  17. "color": "#326BBA",
  18. "name": "inputs.cpu"
  19. }
  20. },
  21. {
  22. "apiVersion": "influxdata.com/v2alpha1",
  23. "kind": "Label",
  24. "metadata": {
  25. "name": "unruffled-boa-d4a001"
  26. },
  27. "spec": {
  28. "color": "#326BBA",
  29. "name": "inputs.mem"
  30. }
  31. }
  32. ]
  33. }
  34. }
  35. EOF

If you run the code sample, InfluxDB responds with a 422 status code and a response body similar to the following:

  1. {
  2. "sources": [],
  3. "stackID": "",
  4. "diff": {
  5. "buckets": [],
  6. "checks": [],
  7. "dashboards": [],
  8. "labels": [],
  9. "labelMappings": [],
  10. "notificationEndpoints": [],
  11. "notificationRules": [],
  12. "tasks": [],
  13. "telegrafConfigs": [],
  14. "variables": []
  15. },
  16. "summary": {
  17. "buckets": [],
  18. "checks": [],
  19. "dashboards": [],
  20. "notificationEndpoints": [],
  21. "notificationRules": [],
  22. "labels": [],
  23. "labelMappings": [],
  24. "missingEnvRefs": null,
  25. "missingSecrets": null,
  26. "summaryTask": [],
  27. "telegrafConfigs": [],
  28. "variables": []
  29. },
  30. "errors": [
  31. {
  32. "kind": "Foo",
  33. "fields": [
  34. "root",
  35. "kind"
  36. ],
  37. "idxs": [
  38. 0,
  39. null
  40. ],
  41. "reason": "unsupported kind provided"
  42. }
  43. ],
  44. "code": "unprocessable entity",
  45. "message": "unprocessable entity"
  46. }

Given the invalid Foo type, the template fails validation and the response contains the following:

  • empty stack ID
  • empty resource diffs
  • list of errors
  • error code and message

If you replace "kind": "Foo" with "kind": "Label" in the sample and pass it in a new dry run request, InfluxDB responds with a 200 OK status: the template is valid, and the response body is similar to the following:

  1. {
  2. "sources": [
  3. "byte stream"
  4. ],
  5. "stackID": "",
  6. "diff": {
  7. "buckets": [],
  8. "checks": [],
  9. "dashboards": [],
  10. "labels": [
  11. {
  12. "id": 0,
  13. "stateStatus": "new",
  14. "templateMetaName": "unruffled-benz-d4d007",
  15. "kind": "Label",
  16. "new": {
  17. "name": "inputs.cpu",
  18. "color": "#326BBA",
  19. "description": ""
  20. },
  21. "old": null
  22. },
  23. {
  24. "id": 0,
  25. "stateStatus": "new",
  26. "templateMetaName": "unruffled-boa-d4a001",
  27. "kind": "Label",
  28. "new": {
  29. "name": "inputs.mem",
  30. "color": "#326BBA",
  31. "description": ""
  32. },
  33. "old": null
  34. }
  35. ],
  36. "labelMappings": [],
  37. "notificationEndpoints": [],
  38. "notificationRules": [],
  39. "tasks": [],
  40. "telegrafConfigs": [],
  41. "variables": []
  42. },
  43. "summary": {
  44. "buckets": [],
  45. "checks": [],
  46. "dashboards": [],
  47. "notificationEndpoints": [],
  48. "notificationRules": [],
  49. "labels": [
  50. {
  51. "kind": "Label",
  52. "templateMetaName": "unruffled-benz-d4d007",
  53. "envReferences": [],
  54. "id": 0,
  55. "orgID": 5244587287857221000,
  56. "name": "inputs.cpu",
  57. "properties": {
  58. "color": "#326BBA",
  59. "description": ""
  60. }
  61. },
  62. {
  63. "kind": "Label",
  64. "templateMetaName": "unruffled-boa-d4a001",
  65. "envReferences": [],
  66. "id": 0,
  67. "orgID": 5244587287857221000,
  68. "name": "inputs.mem",
  69. "properties": {
  70. "color": "#326BBA",
  71. "description": ""
  72. }
  73. }
  74. ],
  75. "labelMappings": [],
  76. "missingEnvRefs": [],
  77. "missingSecrets": [],
  78. "summaryTask": [],
  79. "telegrafConfigs": [],
  80. "variables": []
  81. }
  82. }
  • The dry run diff shows that the template would add two Label resources.
  • Labels with id: 0 indicate that no labels were created.
  • An empty stackID indicates that no stack was created or updated.

Apply templates to an InfluxDB instance

When you apply a template, you specify the organization that owns the template resources. InfluxDB validates and then installs the template to create and update resources in the organization. If you provide a stack ID when applying a template, InfluxDB updates the installed stack in your instance. If you apply a template without providing a stack ID, InfluxDB initializes a new stack with all new resources.

To learn how to use InfluxDB stacks, see InfluxDB stacks.

After applying the template, InfluxDB responds with the following:

  • Stack ID for the stack that was created or updated
  • A diff of added and removed resources

When running API code samples, replace the following in each sample:

  • INFLUX_TOKEN: your InfluxDB API token that has write permission for the organization.
  • INFLUX_ORG_ID: your InfluxDB organization ID.

When applying templates, you must use an API token that has write permission for the resource types configured in the template. See tokens for more information.

Use the influx CLI or /api/v2 API to apply templates to an InfluxDB instance.

Apply templates with the CLI

Use the influx apply command to install templates to your InfluxDB organization. You can apply templates stored in your local file system or from URLs.

The following code sample uses influx apply to apply the sample-data template to the $INFLUX_ORG configured in the environment:

  1. influx apply \
  2. --template-url https://raw.githubusercontent.com/influxdata/community-templates/master/sample-data/sample-data.yml \
  3. --token INFLUX_TOKEN

Once the template is applied, InfluxDB responds with the stack ID and a table-formatted diff. The output is similar to the following:

  1. BUCKETS +add | -remove | unchanged
  2. +-----+--------------------+------------------+---------------+------------------+-------------+-------------+------------------+
  3. | +/- | METADATA NAME | ID | RESOURCE NAME | RETENTION PERIOD | DESCRIPTION | SCHEMA TYPE | NUM MEASUREMENTS |
  4. +-----+--------------------+------------------+---------------+------------------+-------------+-------------+------------------+
  5. | + | sample-data-bucket | 0000000000000000 | sample_data | 168h0m0s | | implicit | 0 |
  6. +-----+--------------------+------------------+---------------+------------------+-------------+-------------+------------------+
  7. | TOTAL | 1 |
  8. +-----+--------------------+------------------+---------------+------------------+-------------+-------------+------------------+
  9. TASKS +add | -remove | unchanged
  10. +-----+-------------------+------------------+-------------------+-------------+-------+
  11. | +/- | METADATA NAME | ID | RESOURCE NAME | DESCRIPTION | CYCLE |
  12. +-----+-------------------+------------------+-------------------+-------------+-------+
  13. | + | fetch-sample-data | 0000000000000000 | Fetch Sample Data | | |
  14. +-----+-------------------+------------------+-------------------+-------------+-------+
  15. | TOTAL | 1 |
  16. +-----+-------------------+------------------+-------------------+-------------+-------+
  17. BUCKETS
  18. +--------------------+------------------+---------------+-----------+--------------------------------+-------------+
  19. | PACKAGE NAME | ID | RESOURCE NAME | RETENTION | DESCRIPTION | SCHEMA TYPE |
  20. +--------------------+------------------+---------------+-----------+--------------------------------+-------------+
  21. | sample-data-bucket | d981dd0a2fed16be | sample_data | 168h0m0s | | implicit |
  22. +--------------------+------------------+---------------+-----------+--------------------------------+-------------+
  23. | TOTAL | 1 |
  24. +--------------------+------------------+---------------+-----------+--------------------------------+-------------+
  25. Stack ID: 09bd87cd33be3000

Apply a template from the file system

To install templates stored on your local machine, pass the -f, --file option with the relative or absolute file path of the template manifest.

  1. # Syntax
  2. influx apply --file TEMPLATE_FILE_PATH
  3. influx apply -f TEMPLATE_FILE_PATH

The following code sample shows how to apply a template from a file path.

  1. influx apply --file /Users/me/template.yml

To use one command to apply multiple templates, pass --file for each template file path–for example:

  1. # Apply multiple templates
  2. influx apply --org my-org \
  3. --file /path/to/first/template.yml \
  4. --file /path/to/second/template.yml

Apply all templates in a directory

To apply all templates in a directory, pass the --file option with the directory path where template manifests are stored. By default, this only applies templates stored in the specified directory. To apply all templates stored in the specified directory and its subdirectories, pass the --recurse flag.

  1. # Syntax
  2. influx apply --org INFLUX_ORG --file DIRECTORY_PATH [--recurse]

The following code sample shows how to apply all templates from a directory:

  1. # Apply all templates in a directory
  2. influx apply --org INFLUX_ORG --file /Users/me

The following code sample uses the --recurse flag to apply all templates from a directory and its subdirectories:

  1. # Apply all templates in a directory and its subdirectories
  2. influx apply --org INFLUX_ORG --file /Users/me --recurse

Apply a template from a URL

To apply a template from a URL, pass the --template-url, -u option with the URL of the template file.

  1. # Syntax
  2. influx apply --org INFLUX_ORG --template-url TEMPLATE_FILE_URL

The following code sample shows how to apply a community template located on GitHub:

  1. # Apply a single template from a URL
  2. influx apply --org my-org --template-url https://raw.githubusercontent.com/influxdata/community-templates/master/kafka/kafka-template.yml

To use one command to apply multiple templates from URLs, pass --template-url for each template file–for example:

  1. # Apply multiple templates from URLs
  2. influx apply --org my-org \
  3. --template-url https://example.com/templates/template1.yml \
  4. --template-url https://example.com/templates/template2.yml

Apply multiple templates from files and URLs

To use a single command to apply templates from multiple file paths and URLs, pass each template with the appropriate --file or --template-url option.

  1. # Syntax
  2. influx apply --org my-org --template-url TEMPLATE_FILE_URL --file TEMPLATE_FILE_PATH

The following code sample shows a single command to apply multiple templates from URLs and file paths:

  1. influx apply --org INFLUX_ORG \
  2. --template-url https://example.com/templates/template1.yml \
  3. --template-url https://example.com/templates/template2.yml \
  4. --file ~/templates/custom-template.yml \
  5. --file ~/templates/iot/home/ \
  6. --recurse

The --recurse flag applies any templates from the ~/templates/iot/home/ directory and subdirectories.

Apply templates with the API

Use the /api/v2/templates/apply endpoint to install templates to your InfluxDB instance.

  1. POST /api/v2/templates/apply

With the API, you can apply templates from remote URLs or template objects in your request.

Apply templates from template objects

To apply a template from a template object, pass the template parameter with a template in the request body. A template contains a contents property with a list of template resources. For more information about template schemas, see the /api/v2/templates/apply reference documentation.

The following code sample shows how to define a template and apply it with the /api/v2/templates/apply API endpoint:

  1. curl "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF
  4. { "orgID": "INFLUX_ORG_ID",
  5. "dryRun": true,
  6. "template": {
  7. "contents": [
  8. {
  9. "apiVersion": "influxdata.com/v2alpha1",
  10. "kind": "Bucket",
  11. "metadata": {
  12. "name": "heuristic-sinoussi-004"
  13. },
  14. "spec": {
  15. "name": "docker",
  16. "retentionRules": [
  17. {
  18. "everySeconds": 604800,
  19. "type": "expire"
  20. }
  21. ]
  22. }
  23. },
  24. {
  25. "apiVersion": "influxdata.com/v2alpha1",
  26. "kind": "Label",
  27. "metadata": {
  28. "name": "unruffled-benz-004"
  29. },
  30. "spec": {
  31. "color": "#326BBA",
  32. "name": "inputs.cpu"
  33. }
  34. }
  35. ]
  36. }
  37. }
  38. EOF

To apply multiple templates in a single request, pass the templates parameter with an array of template objects in the request body–for example:

  1. curl "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF
  4. { "orgID": "INFLUX_ORG_ID",
  5. "dryRun": true,
  6. "templates": [
  7. { "contents": [{
  8. "apiVersion": "influxdata.com/v2alpha1",
  9. "kind": "Label",
  10. "metadata": {
  11. "name": "unruffled-benz-001"
  12. },
  13. "spec": {
  14. "color": "#326BBA",
  15. "name": "inputs.cpu"
  16. }
  17. }]
  18. },
  19. { "contents": [{
  20. "apiVersion": "influxdata.com/v2alpha1",
  21. "kind": "Bucket",
  22. "metadata": {
  23. "name": "heuristic-sinoussi-004"
  24. },
  25. "spec": {
  26. "name": "docker",
  27. "retentionRules": [
  28. {
  29. "everySeconds": 604800,
  30. "type": "expire"
  31. }
  32. ]
  33. }
  34. }]
  35. }
  36. ]
  37. }
  38. EOF

The template and templates parameters are mutually exclusive; if you pass both parameters in your request, InfluxDB responds with an error–for example:

  1. {
  2. ...
  3. "errors": [
  4. {
  5. "kind": "Label",
  6. "fields": [
  7. "root",
  8. "spec",
  9. "name"
  10. ],
  11. "idxs": [
  12. 2,
  13. null,
  14. null
  15. ],
  16. "reason": "duplicate name: unruffled-benz-004"
  17. }
  18. ],
  19. "code": "unprocessable entity",
  20. "message": "unprocessable entity"
  21. }

Apply templates from URLs with the API

To apply a template located at a URL, pass remotes with an array in the request body. In the array, pass an object with the url property for the template you want to apply.

The following code sample shows how to install the linux_system community template located on GitHub:

  1. curl "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF
  4. { "orgID": "INFLUX_ORG_ID",
  5. "remotes": [
  6. {
  7. "url": "https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml"
  8. }
  9. ]
  10. }
  11. EOF

Apply templates from URLs and template objects

The following code sample shows how to pass remotes and templates parameters to apply templates from a URL and template objects:

  1. curl "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF
  4. { "orgID": "INFLUX_ORG_ID",
  5. "dryRun": true,
  6. "remotes": [
  7. {
  8. "url": "https://raw.githubusercontent.com/influxdata/community-templates/master/docker/docker.yml"
  9. }
  10. ],
  11. "templates": [
  12. { "contents": [{
  13. "apiVersion": "influxdata.com/v2alpha1",
  14. "kind": "Label",
  15. "metadata": {
  16. "name": "unruffled-benz-001"
  17. },
  18. "spec": {
  19. "color": "#326BBA",
  20. "name": "inputs.cpu"
  21. }
  22. }]
  23. },
  24. { "contents": [{
  25. "apiVersion": "influxdata.com/v2alpha1",
  26. "kind": "Bucket",
  27. "metadata": {
  28. "name": "heuristic-sinoussi-004"
  29. },
  30. "spec": {
  31. "name": "docker",
  32. "retentionRules": [
  33. {
  34. "everySeconds": 604800,
  35. "type": "expire"
  36. }
  37. ]
  38. }
  39. }]
  40. }]
  41. }
  42. EOF

Define environment references

Some templates include environment references that let you provide custom names for resources and specs.

Define environment references with the CLI

The influx apply command prompts you to provide a value for each environment reference in the template. You can also provide values for environment references by passing an --env-ref option with a key-value pair comprised of the environment reference key and the value to replace it–for example:

  1. influx apply --org INFLUX_ORG_ID --file /path/to/template.yml \
  2. --env-ref=bucket-name-1=myBucket
  3. --env-ref=label-name-1=Label1 \
  4. --env-ref=label-name-2=Label2

Define environment references with the API

To provide environment reference values when you apply a template with the /api/v2/templates/apply API endpoint, pass envRefs with key-value pairs in the request body.

The following code sample shows a request that defines environment references (envRef) in template objects, and passes environment reference values (envRefs):

  1. curl -v "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF
  4. { "orgID": "INFLUX_ORG_ID",
  5. "dryRun": true,
  6. "envRefs": {
  7. "linux-cpu-label": "MY_CPU_LABEL",
  8. "docker-bucket": "MY_DOCKER_BUCKET",
  9. "docker-spec-1": "MY_DOCKER_SPEC"
  10. },
  11. "templates": [
  12. { "contents": [{
  13. "apiVersion": "influxdata.com/v2alpha1",
  14. "kind": "Label",
  15. "metadata": {
  16. "name": {
  17. "envRef": {
  18. "key": "linux-cpu-label"
  19. }
  20. }
  21. },
  22. "spec": {
  23. "color": "#326BBA",
  24. "name": "inputs.cpu"
  25. }
  26. }]
  27. },
  28. { "contents": [{
  29. "apiVersion": "influxdata.com/v2alpha1",
  30. "kind": "Bucket",
  31. "metadata": {
  32. "name": {
  33. "envRef": {
  34. "key": "docker-bucket"
  35. }
  36. }
  37. },
  38. "spec": {
  39. "name": {
  40. "envRef": {
  41. "key": "docker-spec-1"
  42. }
  43. },
  44. "retentionRules": [
  45. {
  46. "everySeconds": 604800,
  47. "type": "expire"
  48. }
  49. ]
  50. }
  51. }]
  52. }
  53. ]
  54. }
  55. EOF

For more API schema detail, see the /api/v2/templates/apply reference documentation.

Pass secrets when installing a template

Some queries use secrets–for example, to access external APIs for sending data or messages.

The following example Flux (from the fortnite community template) requires aSLACK_WEBHOOK secret for sending a Slack message:

  1. import "slack"
  2. import "strings"
  3. import "influxdata/influxdb/secrets"
  4. webhook = secrets.get(key: "SLACK_WEBHOOK")
  5. sendSlackMessage = (text) =>
  6. (slack.message(
  7. url: webhook,
  8. token: "",
  9. channel: "",
  10. text: text,
  11. color: "good",
  12. ))
  13. from(bucket: "fortnite")
  14. |> range(start: -2h, stop: -30m)
  15. |> filter(fn: (r) =>
  16. (r["_measurement"] == "exec_fortnite"))
  17. |> filter(fn: (r) =>
  18. (r["_field"] == "squad_placetop1" or r["_field"] == "solo_placetop1" or r["_field"] == "duo_placetop1"))
  19. |> filter(fn: (r) =>
  20. (r["pro"] == "no" or r["pro"] == "yes"))
  21. |> group(columns: ["name", "_field"])
  22. |> drop(columns: ["_start", "_stop", "pro"])
  23. |> difference()
  24. |> group(columns: ["_time", "name"])
  25. |> filter(fn: (r) =>
  26. (r["_value"] == 1))
  27. |> map(fn: (r) =>
  28. ({r with newColumn: if r["_value"] == 1 then sendSlackMessage(text: "Congratulations to *${string(v: r.name)}* for winning a Fortnite *${strings.trimSuffix(v: r._field, suffix: "_placetop1")}* match! :boom: :boom: :boom:") else 100}))

community-templates/fortnite/fn-template.yml on GitHub

When you apply a template that uses secrets, you can pass the secret key-value pairs in your request. Don’t include secret values in your template.

Pass secrets with the CLI

To define secret values when installing a template with the influx CLI, include the --secret flag with the secret key-value pair.

  1. # Syntax
  2. influx apply --org INFLUX_ORG --file TEMPLATE_FILE_PATH \
  3. [--secret=SECRET_KEY=SECRET_VALUE]
  4. # Examples
  5. # Define a single secret when applying a template
  6. influx apply --org my-org --file /path/to/template.yml \
  7. --secret=FOO=BAR
  8. # Define multiple secrets when applying a template
  9. influx apply --org my-org --file /path/to/template.yml \
  10. --secret=FOO=bar \
  11. --secret=BAZ=quz

InfluxDB doesn’t expose secret values in CLI or API responses.

To add a secret after applying a template, see Add secrets.

Pass secrets with the API

To define secret values when installing a template with the InfluxDB /api/v2/templates/apply endpoint, pass the secrets parameter in the request body with an object that contains the secret key-value pairs.

The following code sample shows how to pass SLACK_WEBHOOK in secrets when applying the fortnite community template:

  1. curl "http://localhost:8086/api/v2/templates/apply" \
  2. --header "Authorization: Token INFLUX_TOKEN" \
  3. --data @- << EOF | jq .
  4. {
  5. "dryRun": false,
  6. "orgID": "INFLUX_ORG_ID",
  7. "secrets": {
  8. "SLACK_WEBHOOK": "YOUR_SECRET_WEBHOOK_URL"
  9. },
  10. "remotes": [
  11. {
  12. "url": "https://raw.githubusercontent.com/influxdata/community-templates/master/fortnite/fn-template.yml"
  13. }
  14. ]
  15. }
  16. EOF

The secret value is not exposed in the InfluxDB /api/v2/templates/apply API response.

For more detail about the API schema, see the /api/v2/templates/apply reference documentation.

Troubleshoot applying templates

If applying a template fails, check the InfluxDB response for your specific error. Below are common causes of template failures.

API error responses

HTTP response codeError messageDescription
HTTP 401 “Unauthorized”unauthorized accessThe API token may not have read or write access for resources in the template.
HTTP 422 “Unprocessable Entity”duplicate name: RESOURCE NAMEYou may have passed a parameter combination that InfluxDB doesn’t support–for example, template and templates in the same request.

templates