Skip to content

[datadog_dashboard] Add default_timeframe support#3834

Open
Gurik-M wants to merge 8 commits into
masterfrom
DASHB-970-update-terraform-default-timeframe
Open

[datadog_dashboard] Add default_timeframe support#3834
Gurik-M wants to merge 8 commits into
masterfrom
DASHB-970-update-terraform-default-timeframe

Conversation

@Gurik-M
Copy link
Copy Markdown

@Gurik-M Gurik-M commented May 29, 2026

Summary

Resolves DASHB-970 (Update the terraform resource to respect default_time)

  • Adds an optional default_timeframe block to datadog_dashboard and datadog_dashboard_v2 for configuring the dashboard's default time span on load
  • Supports live (type, unit, value) and fixed (type, from, to) variants, matching the dashboard API schema
  • Allows default_timeframe = null on update to explicitly disable after it has been configured

Test 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_VERSION pins/downloads a Terraform CLI for the harness; optional if terraform version already works on your PATH.)

    Result (local):

    PASS datadog/tests.TestAccDatadogDashboardDefaultTimeframe (5.65s)
    PASS datadog/tests.TestAccDatadogDashboardDefaultTimeframe_import (6.23s)
    PASS datadog/tests (cached)
    
  • make docs && make check-docs after merge prep

Made with Cursor

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>
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 29, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 9 Pipeline jobs failed

Run Tests | all-checks   View in Datadog   GitHub Actions

Run Tests | test (1.1.5, 0, ubuntu-latest)   View in Datadog   GitHub Actions

See error 3 test failures: datadog_dashboard.default_timeframe_dashboard attribute 'default_timeframe.0.value' expected '1', got '0'.

Run Tests | test (1.1.5, 2, ubuntu-latest)   View in Datadog   GitHub Actions

See error TestAccDatadogDashboardDefaultTimeframe_import failed due to non-refresh plan not being empty after applying the test step in resource_datadog_dashboard_default_timeframe_test.go:92.

View all 9 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ad00621 | Docs | Datadog PR Page | Give us feedback!

@Gurik-M Gurik-M self-assigned this May 29, 2026
Gurik-M and others added 3 commits June 1, 2026 16:02
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>
@Gurik-M Gurik-M marked this pull request as ready for review June 1, 2026 21:46
@Gurik-M Gurik-M requested review from a team as code owners June 1, 2026 21:46
@Gurik-M Gurik-M changed the title [datadog_dashboard] Add default_timeframe support [DASHB-970] Add default_timeframe support to datadog_dashboard Jun 2, 2026
@Gurik-M Gurik-M changed the title [DASHB-970] Add default_timeframe support to datadog_dashboard [datadog_dashboard] Add default_timeframe support Jun 2, 2026
Copy link
Copy Markdown
Contributor

@yacomink yacomink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 null for a field that was cleared in HCL.

The engine already has two states for an OmitEmpty: true TypeBlock — include it or skip it. A third state (nil in the data map → serialize as JSON null) would cover this case generically. The abstraction would be a NullOnClear: bool flag on FieldSpec:

// 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.

Gurik-M and others added 2 commits June 2, 2026 18:37
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>
@Gurik-M Gurik-M requested a review from michlee1337 June 4, 2026 15:54
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants