Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions datadog/fwprovider/resource_datadog_observability_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type observabilityPipelineModel struct {
}

type configModel struct {
Sources sourcesModel `tfsdk:"sources"`
Processors processorsModel `tfsdk:"processors"`
Destinations destinationsModel `tfsdk:"destinations"`
UseLegacySearchSyntax types.Bool `tfsdk:"use_legacy_search_syntax"`
Sources sourcesModel `tfsdk:"sources"`
Processors processorsModel `tfsdk:"processors"`
Destinations destinationsModel `tfsdk:"destinations"`
}
type sourcesModel struct {
DatadogAgentSource []*datadogAgentSourceModel `tfsdk:"datadog_agent"`
Expand Down Expand Up @@ -667,6 +668,12 @@ func (r *observabilityPipelineResource) Schema(_ context.Context, _ resource.Sch
Blocks: map[string]schema.Block{
"config": schema.SingleNestedBlock{
Description: "Configuration for the pipeline.",
Attributes: map[string]schema.Attribute{
"use_legacy_search_syntax": schema.BoolAttribute{
Optional: true,
Description: "Use this field to configure the pipeline's filter queries to use the deprecated search syntax.",
},
},
Blocks: map[string]schema.Block{
"sources": schema.SingleNestedBlock{
Description: "List of sources.",
Expand Down Expand Up @@ -2476,6 +2483,11 @@ func expandPipeline(ctx context.Context, state *observabilityPipelineModel) (*da

config := datadogV2.NewObservabilityPipelineConfigWithDefaults()

// Set use_legacy_search_syntax if provided
if !state.Config.UseLegacySearchSyntax.IsNull() {
config.SetUseLegacySearchSyntax(state.Config.UseLegacySearchSyntax.ValueBool())
}

// Sources
for _, s := range state.Config.Sources.DatadogAgentSource {
config.Sources = append(config.Sources, expandDatadogAgentSource(s))
Expand Down Expand Up @@ -2656,6 +2668,13 @@ func flattenPipeline(ctx context.Context, state *observabilityPipelineModel, res
cfg := attrs.GetConfig()
outCfg := configModel{}

// Handle use_legacy_search_syntax
if useLegacySearchSyntax, ok := cfg.GetUseLegacySearchSyntaxOk(); ok {
outCfg.UseLegacySearchSyntax = types.BoolValue(*useLegacySearchSyntax)
} else {
outCfg.UseLegacySearchSyntax = types.BoolNull()
}

for _, src := range cfg.GetSources() {

if a := flattenDatadogAgentSource(src.ObservabilityPipelineDatadogAgentSource); a != nil {
Expand Down
103 changes: 103 additions & 0 deletions datadog/tests/resource_datadog_observability_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3581,3 +3581,106 @@ resource "datadog_observability_pipeline" "pubsub_dest" {
},
})
}

func TestAccDatadogObservabilityPipeline_useLegacySearchSyntax(t *testing.T) {
_, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)

resourceName := "datadog_observability_pipeline.legacy_search"

resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: accProviders,
CheckDestroy: testAccCheckDatadogPipelinesDestroy(providers.frameworkProvider),
Steps: []resource.TestStep{
{
Config: testAccObservabilityPipelineUseLegacySearchSyntaxConfig(true),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogPipelinesExists(providers.frameworkProvider),
resource.TestCheckResourceAttr(resourceName, "name", "pipeline with legacy search"),
resource.TestCheckResourceAttr(resourceName, "config.use_legacy_search_syntax", "true"),
resource.TestCheckResourceAttr(resourceName, "config.sources.datadog_agent.0.id", "source-1"),
resource.TestCheckResourceAttr(resourceName, "config.processors.filter.0.id", "filter-1"),
resource.TestCheckResourceAttr(resourceName, "config.destinations.datadog_logs.0.id", "destination-1"),
),
},
{
Config: testAccObservabilityPipelineUseLegacySearchSyntaxConfig(false),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogPipelinesExists(providers.frameworkProvider),
resource.TestCheckResourceAttr(resourceName, "name", "pipeline with legacy search"),
resource.TestCheckResourceAttr(resourceName, "config.use_legacy_search_syntax", "false"),
),
},
{
Config: testAccObservabilityPipelineUseLegacySearchSyntaxConfigUnset(),
Check: resource.ComposeTestCheckFunc(
testAccCheckDatadogPipelinesExists(providers.frameworkProvider),
resource.TestCheckResourceAttr(resourceName, "name", "pipeline with legacy search"),
// When unset, the attribute should not be present in state
resource.TestCheckNoResourceAttr(resourceName, "config.use_legacy_search_syntax"),
),
},
},
})
}

func testAccObservabilityPipelineUseLegacySearchSyntaxConfig(useLegacySearchSyntax bool) string {
return fmt.Sprintf(`
resource "datadog_observability_pipeline" "legacy_search" {
name = "pipeline with legacy search"

config {
use_legacy_search_syntax = %t

sources {
datadog_agent {
id = "source-1"
}
}

processors {
filter {
id = "filter-1"
include = "service:my-service"
inputs = ["source-1"]
}
}

destinations {
datadog_logs {
id = "destination-1"
inputs = ["filter-1"]
}
}
}
}`, useLegacySearchSyntax)
}

func testAccObservabilityPipelineUseLegacySearchSyntaxConfigUnset() string {
return `
resource "datadog_observability_pipeline" "legacy_search" {
name = "pipeline with legacy search"

config {
sources {
datadog_agent {
id = "source-1"
}
}

processors {
filter {
id = "filter-1"
include = "service:my-service"
inputs = ["source-1"]
}
}

destinations {
datadog_logs {
id = "destination-1"
inputs = ["filter-1"]
}
}
}
}`
}
1 change: 1 addition & 0 deletions docs/resources/observability_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Optional:
- `destinations` (Block, Optional) List of destinations. (see [below for nested schema](#nestedblock--config--destinations))
- `processors` (Block, Optional) List of processors. (see [below for nested schema](#nestedblock--config--processors))
- `sources` (Block, Optional) List of sources. (see [below for nested schema](#nestedblock--config--sources))
- `use_legacy_search_syntax` (Boolean) Use this field to configure the pipeline's filter queries to use the deprecated search syntax.

<a id="nestedblock--config--destinations"></a>
### Nested Schema for `config.destinations`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go/v2 v2.47.1-0.20251014135845-22ba517ffd6e
github.com/DataDog/datadog-api-client-go/v2 v2.47.1-0.20251015175110-ab9dc9cd9aa5
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/Masterminds/semver/v3 v3.3.1
github.com/google/go-cmp v0.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-api-client-go/v2 v2.47.1-0.20251014135845-22ba517ffd6e h1:RmEB58Inv80RY41msREUCmQ70Gmx93AFlR3oZZiz9Xo=
github.com/DataDog/datadog-api-client-go/v2 v2.47.1-0.20251014135845-22ba517ffd6e/go.mod h1:d3tOEgUd2kfsr9uuHQdY+nXrWp4uikgTgVCPdKNK30U=
github.com/DataDog/datadog-api-client-go/v2 v2.47.1-0.20251015175110-ab9dc9cd9aa5 h1:6ccnKe30xCwinAvsJ/Eo7tccWQ63XVKOpfVxTg2pQ+E=
github.com/DataDog/datadog-api-client-go/v2 v2.47.1-0.20251015175110-ab9dc9cd9aa5/go.mod h1:d3tOEgUd2kfsr9uuHQdY+nXrWp4uikgTgVCPdKNK30U=
github.com/DataDog/datadog-go v4.4.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
Loading