Skip to content

Commit bbbdef2

Browse files
aymericDDAymeric
andauthored
feat: support azure monitor datasource (#453)
Signed-off-by: Aymeric <[email protected]> Co-authored-by: Aymeric <[email protected]>
1 parent 9161afc commit bbbdef2

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

docs/resources/data_source.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Optional:
108108
- `authentication_type` (String) (Stackdriver) The authentication type: `jwt` or `gce`.
109109
- `catalog` (String) (Athena) Athena catalog.
110110
- `client_email` (String) (Stackdriver) Service account email address.
111+
- `client_id` (String) (Azure Monitor) The service account client id.
112+
- `cloud_name` (String) (Azure Monitor) The cloud name.
111113
- `conn_max_lifetime` (Number) (MySQL, PostgreSQL, and MSSQL) Maximum amount of time in seconds a connection may be reused (Grafana v5.4+).
112114
- `custom_metrics_namespaces` (String) (CloudWatch) A comma-separated list of custom namespaces to be queried by the CloudWatch data source.
113115
- `database` (String) (Athena) Name of the database within the catalog.
@@ -141,6 +143,8 @@ Optional:
141143
- `sigv4_profile` (String) (Elasticsearch and Prometheus) Credentials profile name, leave blank for default.
142144
- `sigv4_region` (String) (Elasticsearch and Prometheus) AWS region to use for Sigv4.
143145
- `ssl_mode` (String) (PostgreSQL) SSLmode. 'disable', 'require', 'verify-ca' or 'verify-full'.
146+
- `subscription_id` (String) (Azure Monitor) The subscription id
147+
- `tenant_id` (String) (Azure Monitor) Service account tenant ID.
144148
- `time_field` (String) (Elasticsearch) Which field that should be used as timestamp.
145149
- `time_interval` (String) (Prometheus, Elasticsearch, InfluxDB, MySQL, PostgreSQL, and MSSQL) Lowest interval/step value that should be used for this data source.
146150
- `timescaledb` (Boolean) (PostgreSQL) Enable usage of TimescaleDB extension.
@@ -175,6 +179,7 @@ Optional:
175179
- `access_token` (String, Sensitive) (Github) The access token used to access the data source.
176180
- `auth_token` (String, Sensitive) (Sentry) Authorization token.
177181
- `basic_auth_password` (String, Sensitive) (All) Password to use for basic authentication.
182+
- `client_secret` (String, Sensitive) (Azure Monitor) Client secret for authentication.
178183
- `password` (String, Sensitive) (All) Password to use for authentication.
179184
- `private_key` (String, Sensitive) (Stackdriver) The service account key `private_key` to use to access the data source.
180185
- `secret_key` (String, Sensitive) (CloudWatch, Athena) The secret key to use to access the data source.

grafana/resource_data_source.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ source selected (via the 'type' argument).
135135
Optional: true,
136136
Description: "(Stackdriver) Service account email address.",
137137
},
138+
"client_id": {
139+
Type: schema.TypeString,
140+
Optional: true,
141+
Description: "(Azure Monitor) The service account client id.",
142+
},
143+
"cloud_name": {
144+
Type: schema.TypeString,
145+
Optional: true,
146+
Description: "(Azure Monitor) The cloud name.",
147+
},
138148
"conn_max_lifetime": {
139149
Type: schema.TypeInt,
140150
Optional: true,
@@ -332,6 +342,16 @@ source selected (via the 'type' argument).
332342
Optional: true,
333343
Description: "(PostgreSQL) SSLmode. 'disable', 'require', 'verify-ca' or 'verify-full'.",
334344
},
345+
"subscription_id": {
346+
Type: schema.TypeString,
347+
Optional: true,
348+
Description: "(Azure Monitor) The subscription id",
349+
},
350+
"tenant_id": {
351+
Type: schema.TypeString,
352+
Optional: true,
353+
Description: "(Azure Monitor) Service account tenant ID.",
354+
},
335355
"timescaledb": {
336356
Type: schema.TypeBool,
337357
Optional: true,
@@ -439,6 +459,12 @@ source selected (via the 'type' argument).
439459
Sensitive: true,
440460
Description: "(All) Password to use for basic authentication.",
441461
},
462+
"client_secret": {
463+
Type: schema.TypeString,
464+
Optional: true,
465+
Sensitive: true,
466+
Description: "(Azure Monitor) Client secret for authentication.",
467+
},
442468
"password": {
443469
Type: schema.TypeString,
444470
Optional: true,
@@ -652,6 +678,8 @@ func makeJSONData(d *schema.ResourceData) gapi.JSONData {
652678
AuthenticationType: d.Get("json_data.0.authentication_type").(string),
653679
Catalog: d.Get("json_data.0.catalog").(string),
654680
ClientEmail: d.Get("json_data.0.client_email").(string),
681+
ClientID: d.Get("json_data.0.client_id").(string),
682+
CloudName: d.Get("json_data.0.cloud_name").(string),
655683
ConnMaxLifetime: int64(d.Get("json_data.0.conn_max_lifetime").(int)),
656684
CustomMetricsNamespaces: d.Get("json_data.0.custom_metrics_namespaces").(string),
657685
Database: d.Get("json_data.0.database").(string),
@@ -685,6 +713,8 @@ func makeJSONData(d *schema.ResourceData) gapi.JSONData {
685713
SigV4Profile: d.Get("json_data.0.sigv4_profile").(string),
686714
SigV4Region: d.Get("json_data.0.sigv4_region").(string),
687715
Sslmode: d.Get("json_data.0.ssl_mode").(string),
716+
SubscriptionID: d.Get("json_data.0.subscription_id").(string),
717+
TenantID: d.Get("json_data.0.tenant_id").(string),
688718
Timescaledb: d.Get("json_data.0.timescaledb").(bool),
689719
TimeField: d.Get("json_data.0.time_field").(string),
690720
TimeInterval: d.Get("json_data.0.time_interval").(string),
@@ -706,6 +736,7 @@ func makeSecureJSONData(d *schema.ResourceData) gapi.SecureJSONData {
706736
AccessToken: d.Get("secure_json_data.0.access_token").(string),
707737
AuthToken: d.Get("secure_json_data.0.auth_token").(string),
708738
BasicAuthPassword: d.Get("secure_json_data.0.basic_auth_password").(string),
739+
ClientSecret: d.Get("secure_json_data.0.client_secret").(string),
709740
Password: d.Get("secure_json_data.0.password").(string),
710741
PrivateKey: d.Get("secure_json_data.0.private_key").(string),
711742
SecretKey: d.Get("secure_json_data.0.secret_key").(string),

grafana/resource_data_source_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,32 @@ func TestAccDataSource_basic(t *testing.T) {
510510
"secure_json_data.0.secret_key": "456",
511511
},
512512
},
513+
{
514+
resource: "grafana_data_source.azure",
515+
config: `
516+
resource "grafana_data_source" "azure" {
517+
type = "grafana-azure-monitor-datasource"
518+
name = "azure"
519+
json_data {
520+
client_id = "lorem-ipsum"
521+
cloud_name = "azuremonitor"
522+
subscription_id = "lorem-ipsum"
523+
tenant_id = "lorem-ipsum"
524+
}
525+
secure_json_data {
526+
client_secret = "lorem-ipsum"
527+
}
528+
}
529+
`,
530+
attrChecks: map[string]string{
531+
"type": "grafana-azure-monitor-datasource",
532+
"name": "azure",
533+
"json_data.0.client_id": "lorem-ipsum",
534+
"json_data.0.cloud_name": "azuremonitor",
535+
"json_data.0.subscription_id": "lorem-ipsum",
536+
"json_data.0.tenant_id": "lorem-ipsum",
537+
},
538+
},
513539
}
514540

515541
// Iterate over the provided configurations for datasources

0 commit comments

Comments
 (0)