Comments (12)
Ran into the same thing. Could someone from team give some guidance or will this on future release?
from terraform-provider-datadog.
Why make the graph a resource (which it is not)? Just make it a data item. Then a timeboard resource can be composed from a number them.
Then in Terraform it would be more like:
data "datadog_timeboard_graph" "cpu" {
count = ""
...
}
resource "datadog_timeboard" "this" {
title = "${title(var.name)} Timeboard [${upper(var.environment)}]"
description = "A timeboard generated automatically by Terraform for the ${title(var.name)} service"
read_only = true
graphs = ["${data.datadog_timeboard_graph.cpu}"]
}
Or it you want to treat it like a resource in Terraform, then you need to be able to build the full timeboard data structure before calling the API. Not sure is dependency control will be enough to accomplish this
from terraform-provider-datadog.
I spent some time investigating this, and the big difference between Datadog timeboards and AWS security groups is that there is an API for adding a single security group rule to a security group (authorize-security-group-egress and authorize-security-group-ingress), but the only API for timeboards requires setting all graphs.
It's still possible to do, but would probably require locking the dashboard with a mutex for each graph, pulling the existing config, merging in the graph config, and setting the entire dashboard. I think having a datadog_timeboard_graph
resource would be very useful, and I wouldn't mind taking on the work to add it, but I'd like to get some validation from a codeowner here that this approach is reasonable.
from terraform-provider-datadog.
I like the data approach, because you're right, it's not a resource. The missing piece for me is that I'd like to be able to have a dynamic number of graphs without needing to specify them all in the timeboard. Something like this:
simple_app module:
data "datadog_timeboard_graph" "cpu" {
title = "${var.name} CPU"
viz = "timeseries"
timeboard = "${var.timeboard_id}"
request {
q = "avg:docker.cpu.user{${var.label}:${var.value}}"
}
}
data "datadog_timeboard_graph" "memory" {
title = "${var.name} memory"
viz = "timeseries"
timeboard = "${var.timeboard_id}"
request {
q = "avg:docker.mem.rss{${var.label}:${var.value}}"
}
}
base config:
resource "datadog_timeboard" "my-apps" {
title = "My Apps"
description = "Metrics for all of my apps"
}
module "simple_app" {
name = "Frontend"
label = "app_name"
value = "frontend_xyz"
timeboard_id = "${datadog_timeboard.my-apps.id}"
}
module "simple_app" {
name = "Backend"
label = "app_name"
value = "backend_xyz"
timeboard_id = "${datadog_timeboard.my-apps.id}"
}
Then I could abstract common patterns more easily, and do things like add another graph for each app without needing to enumerate the list of new graphs.
from terraform-provider-datadog.
Well if they are data, they can't add themselves to a resource. The resource needs to reference them. But with a little work (and not pretty code) you could specify all of them in the timeboard resource and then use count to enable/disable each one in the data
from terraform-provider-datadog.
I think I fixed this using locals, feel free to contribute to this module, I'm not a heavy Datadog user myself.
https://registry.terraform.io/modules/maartenvanderhoef/timeboard/datadog/0.0.4
https://github.com/maartenvanderhoef/terraform-datadog-timeboard/blob/master/examples/main.tf
from terraform-provider-datadog.
@maartenvanderhoef I don't think locals works since you can't loop using the count option.
from terraform-provider-datadog.
@assiotis have you looked at template variables? They should save you from having to create multiple identical dashboards and instead let you switch the data set (e.g. environment, cluster, etc) by using a drop-down.
https://docs.datadoghq.com/graphing/dashboards/template_variables/
from terraform-provider-datadog.
I do not think templates variables are a good alternative for that. The ability to dynamically create graphs would be really great to have.
Maybe dynamic nested blocks would be enough here ?
from terraform-provider-datadog.
I ended concocting an embarrassing hack, that so far seems to work OK. Using Terraform 0.10.x.
First setup the various components you want to dynamically switch in and out
locals {
graphs_basics = [
{
title = "Hosts"
viz = "hostmap"
// bla bla
}, ... {
// more graphs
}]
}
locals {
graphs_nginx = [
{ // more graphs
}]
}
locals {
graphs_business = [
{ // more graphs
}]
}
Then in the main code for the module we construct the list of graphs step by step. At each step, we either append the next set of graphs or copy the previous step as-is, all depending if the component is enabled or disabled:
locals {
step0 = "${local.graphs_basics}"
step1 = "${slice(concat(local.step0, local.graphs_nginx),
0,
var.enable_nginx_graphs ? length(local.step0) + length(local.graphs_nginx) : length(local.step0))}"
step2 = "${slice(concat(local.step1, local.graphs_business),
0,
var.enable_business_metric_graphs ? length(local.step1) + length(local.graphs_business) : length(local.step1))}"
// more of the same
step20 = // concat with the previous variable and slice differently depending if the component is enabled or not
stepN = "${slice(concat(local.step20, local.graphs_blablabla),
0,
var.enable_blabla_component ? length(local.step20) + length(local.graphs_blabla) : length(local.step20))}"
final = "${concat(local.stepN, var.extra_graphs)}"
}
// now construct timeboard
resource "datadog_timeboard" "this" {
title = "${upper(replace(var.name, "-_", " "))} Timeboard [TF]"
description = "A timeboard generated automatically by Terraform for the ${title(var.name)} service"
read_only = false
graph = "${local.final}"
// can setup template variables as well or whatever else is needed
template_variable { }
}
from terraform-provider-datadog.
Seems like this could be solved using the dynamic
blocks feature that's been newly introduced in TF 0.12 [1]. I'll create a PR for our docs to present example usage.
[1] https://www.terraform.io/docs/configuration/expressions.html#dynamic-blocks
from terraform-provider-datadog.
PR #232 was merged, closing this issue. Thanks everyone for your participation!
from terraform-provider-datadog.
Related Issues (20)
- datadog_logs_archive / terraform plan / Error: object contains unparsed element: map[bucket:datadog-rehydrate-tf integration:map[] path:/test type:s3] HOT 1
- Reference Tables Resource Provider
- Cannot update Monitor Downtime HOT 1
- Add support for order by group on dashboard query_table_definition
- Provider has incorrect checksum when downloaded from GitHub (darwin/arm64) HOT 1
- More flexibility in writing recurring_schedule.recurrence.duration
- Provider attempting to remove query metric
- `widget.timeseries_definition.request.query.slo_query.slo_query_type` doesn't support `time_slice` option
- Error for inconsistent result after apply for Datadog Azure Integration HOT 2
- Support for Team Notifications channel
- Error: Provider produced inconsistent result after apply HOT 1
- Support for Schema v3 in datadog_service_definition_yaml
- Support for `monitor_options.renotify_occurrences` in resource `datadog_synthetics_test`
- Provider produced inconsistent final plan - Replacing `-` with `_` in names of `datadog_metric_metadata.metric_description` HOT 1
- Support for Error Tracking rules and rate limits configuration
- error validating monitor from /api/v1/monitor/validate: 400 Bad Request: {"errors":["Some monitor IDs are invalid"]} HOT 1
- datadog_security_monitoring_rule 409 conflict HOT 1
- Submit signatures for OpenTofu provider registry
- Documentation for `datadog_team_permission_settings` is misleading/incomplete HOT 1
- Logs Index Resource `name` is missing `ForceNew`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-datadog.