The required arguments for this resource vary depending on the type of data source selected (via the 'type' argument).
resource "grafana_data_source" "arbitrary-data" {
type = "stackdriver"
name = "sd-arbitrary-data"
json_data_encoded = jsonencode({
"tokenUri" = "https://oauth2.googleapis.com/token"
"authenticationType" = "jwt"
"defaultProject" = "default-project"
"clientEmail" = "client-email@default-project.iam.gserviceaccount.com"
})
secure_json_data_encoded = jsonencode({
"privateKey" = "-----BEGIN PRIVATE KEY-----\nprivate-key\n-----END PRIVATE KEY-----\n"
})
}
resource "grafana_data_source" "influxdb" {
type = "influxdb"
name = "myapp-metrics"
url = "http://influxdb.example.net:8086/"
basic_auth_enabled = true
basic_auth_username = "username"
database_name = "dbname" // Example: influxdb_database.metrics.name
json_data_encoded = jsonencode({
authType = "default"
basicAuthPassword = "mypassword"
})
}
resource "grafana_data_source" "cloudwatch" {
type = "cloudwatch"
name = "cw-example"
json_data_encoded = jsonencode({
defaultRegion = "us-east-1"
authType = "keys"
})
secure_json_data_encoded = jsonencode({
accessKey = "123"
secretKey = "456"
})
}
resource "grafana_data_source" "prometheus" {
type = "prometheus"
name = "mimir"
url = "https://my-instances.com"
basic_auth_enabled = true
basic_auth_username = "username"
json_data_encoded = jsonencode({
httpMethod = "POST"
prometheusType = "Mimir"
prometheusVersion = "2.4.0"
})
secure_json_data_encoded = jsonencode({
basicAuthPassword = "password"
})
}
name
(String) A unique name for the data source.type
(String) The data source type. Must be one of the supported data source keywords.access_mode
(String) The method by which Grafana will access the data source: proxy
or direct
. Defaults to proxy
.basic_auth_enabled
(Boolean) Whether to enable basic auth for the data source. Defaults to false
.basic_auth_username
(String) Basic auth username. Defaults to ``.database_name
(String) (Required by some data source types) The name of the database to use on the selected data source server. Defaults to ``.http_headers
(Map of String, Sensitive) Custom HTTP headersis_default
(Boolean) Whether to set the data source as default. This should only be true
to a single data source. Defaults to false
.json_data_encoded
(String) Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.org_id
(String) The Organization ID. If not set, the Org ID defined in the provider block will be used.secure_json_data_encoded
(String, Sensitive) Serialized JSON string containing the secure json data. This attribute can be used to pass secure configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.uid
(String) Unique identifier. If unset, this will be automatically generated.url
(String) The URL for the data source. The type of URL required varies depending on the chosen data source type.username
(String) (Required by some data source types) The username to use to authenticate to the data source. Defaults to ``.id
(String) The ID of this resource.Import is supported using the following syntax:
terraform import grafana_data_source.name "{{ uid }}"
terraform import grafana_data_source.name "{{ orgID }}:{{ uid }}"