A Terraform module that provisions a Grafana InfluxDB data source using the grafana/grafana provider. Manage your Grafana InfluxDB data sources as code — versioned, reviewable, and reproducible.
- Provisions a single
grafana_data_sourceresource of typeinfluxdb. - Supports basic authentication and arbitrary JSON / secure JSON configuration.
- Returns the created data source
idas an output for downstream use. - Compatible with Terraform
>= 1.0and the Grafana provider~> 4.0.
| Name | Version |
|---|---|
| terraform | >= 1.0 |
| grafana | ~> 4.0 |
module "influxdb_ds" {
source = "gogorichie/influxdb-ds-module/grafana"
version = "~> 1.0"
grafana_url = "https://grafana.example.com"
grafana_auth = var.grafana_auth_token
ds_name = "my-influxdb"
ds_url = "http://influxdb.example.net:8086/"
database_name = "metrics"
}module "influxdb_ds" {
source = "gogorichie/influxdb-ds-module/grafana"
version = "~> 1.0"
grafana_url = "https://grafana.example.com"
grafana_auth = var.grafana_auth_token
ds_name = "influxdb-prod"
ds_url = "http://influxdb.example.net:8086/"
database_name = "metrics"
basic_auth_enabled = true
basic_auth_username = "grafana_reader"
secure_json_data_encoded = jsonencode({
basicAuthPassword = var.influxdb_password
})
json_data_encoded = jsonencode({
httpMode = "GET"
})
}Tip: Pass secrets such as
grafana_authandsecure_json_data_encodedfrom a secrets manager or environment-bound variables — never hard-code them.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
ds_name |
A unique name for the data source. | string |
n/a | yes |
ds_url |
URL for the InfluxDB data source (e.g., http://influxdb.example.net:8086). |
string |
n/a | yes |
database_name |
Name of the InfluxDB database. | string |
n/a | yes |
grafana_url |
URL of the Grafana server. | string |
null |
no |
grafana_auth |
Authentication credentials for Grafana (e.g., API token). | string |
null |
no |
basic_auth_enabled |
Whether to enable basic auth for the data source. | bool |
true |
no |
basic_auth_username |
Username for basic authentication. | string |
null |
no |
json_data_encoded |
Additional data source configuration as a JSON-encoded string. | string |
null |
no |
secure_json_data_encoded |
Secure configuration (passwords, tokens) as a JSON-encoded string. | string |
null |
no |
| Name | Description |
|---|---|
id |
The ID of the created Grafana data source. |
This module configures the grafana provider internally using the grafana_url and grafana_auth inputs, so you can use it without declaring a separate provider "grafana" block. If you already configure the provider in your root module, you can omit those two inputs.
Contributions are welcome through GitHub Issues and Pull Requests.
- Fork this repository.
- Create a feature branch from
mainwith a descriptive name, for example:feat/add-timeout-settingorfix/readme-example.
- Keep PRs scoped to this module's purpose: provisioning a single
grafana_data_sourceof typeinfluxdb. - Avoid unrelated refactors in the same PR.
- Never commit secrets, Terraform state files, or
.tfvarsfiles.
Run the following commands before opening a PR:
terraform fmt -recursive
terraform init -backend=false
terraform validate
tflint --init
tflintIf you use pre-commit, you can also run:
pre-commit run --all-files- If you change inputs or outputs, regenerate the README tables using
terraform-docs(theterraform_docspre-commit hook handles this). - Include usage updates in examples when behavior changes.
- Describe what changed and why.
- Include any breaking-change notes clearly in the PR description.
- Apply an appropriate release label when possible:
semver:majorfor breaking changessemver:minor(orenhancement) for new backward-compatible featuressemver:patch(orbug) for fixes
