[datadog_dashboard] Add default_timeframe support#3834
Conversation
Expose an optional default_timeframe block on datadog_dashboard and datadog_dashboard_v2 so users can configure the dashboard's default time span, including explicit null to disable after it has been set. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Register acceptance tests, add VCR cassettes, generate docs, and add a dedicated example so the change follows dashboard Terraform contribution guidelines and passes provider checks. Co-authored-by: Cursor <cursoragent@cursor.com>
… RECORD=none Integration uses live API where v1 rejects default_timeframe; align with datadog_dashboard_v2 cassette pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
…meframe Adds the blank line before the tab nested schema anchor so make check-docs matches the generator after the default_timeframe schema updates. Co-authored-by: Cursor <cursoragent@cursor.com>
yacomink
left a comment
There was a problem hiding this comment.
Can you please load this claude skill: https://github.com/DataDog/claude-marketplace/tree/main/dashboard-terraform-openapi-sync and go over this change with it?
The claude skill has some conventions and pointers for making changes to the datadog_dashboard_v2 spec. One of those is preferring expanding the engine over adding custom build/flatten code for individual fields. With that guidance in place the skill gave me this suggestion:
The custom build code is all a consequence of one missing engine capability: no way to emit JSON
nullfor a field that was cleared in HCL.
The engine already has two states for an
OmitEmpty: trueTypeBlock — include it or skip it. A third state (nilin the data map → serialize as JSONnull) would cover this case generically. The abstraction would be aNullOnClear: boolflag onFieldSpec:
// In BuildEngineJSONFromMap, TypeBlock case:
rawVal := data[f.HCLKey]
if rawVal == nil && f.NullOnClear {
result[f.effectiveJSONKey()] = nil // explicit JSON null
continue
}
// ... existing block handling unchanged ...I'd also suggest making your OpenAPI change PR at the same time. The skill works best if you make the two changes in one session.
Adds a NullOnClear bool flag to FieldSpec that enables a third build-direction state for TypeBlock fields: when the data map value is nil, emit explicit JSON null instead of skipping the field. This is distinct from OmitEmpty (which skips entirely) and prepares the engine for the default_timeframe refactor once the OpenAPI spec and generated client model the field with nullable: true. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds TestAccDatadogDashboardV2DefaultTimeframe reusing the existing v1 cassette (TestAccDatadogDashboardDefaultTimeframe) via dashboardV2Config, and shows default_timeframe usage in the datadog_dashboard_v2 example. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Resolves DASHB-970 (Update the terraform resource to respect
default_time)default_timeframeblock todatadog_dashboardanddatadog_dashboard_v2for configuring the dashboard's default time span on loadlive(type,unit,value) andfixed(type,from,to) variants, matching the dashboard API schemadefault_timeframe = nullon update to explicitly disable after it has been configuredTest plan
Unit tests for build/flatten/null handling (
datadog/dashboardmapping/dashboard_default_timeframe_test.go)Acceptance tests (cassette replay,
RECORD=false):TF_ACC_TERRAFORM_VERSION=1.13.1 \ RECORD=false \ TESTARGS='-run TestAccDatadogDashboardDefaultTimeframe' \ make testacc(
TF_ACC_TERRAFORM_VERSIONpins/downloads a Terraform CLI for the harness; optional ifterraform versionalready works on yourPATH.)Result (local):
make docs && make check-docsafter merge prepMade with Cursor