diff --git a/datadog/fwprovider/resource_datadog_observability_pipeline.go b/datadog/fwprovider/resource_datadog_observability_pipeline.go index 89db8fa86..710197be5 100644 --- a/datadog/fwprovider/resource_datadog_observability_pipeline.go +++ b/datadog/fwprovider/resource_datadog_observability_pipeline.go @@ -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"` @@ -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.", @@ -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)) @@ -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 { diff --git a/datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_useLegacySearchSyntax.freeze b/datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_useLegacySearchSyntax.freeze new file mode 100644 index 000000000..d1e456fc6 --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_useLegacySearchSyntax.freeze @@ -0,0 +1 @@ +2025-10-15T14:52:00.052773-04:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_useLegacySearchSyntax.yaml b/datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_useLegacySearchSyntax.yaml new file mode 100644 index 000000000..072807cbc --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_useLegacySearchSyntax.yaml @@ -0,0 +1,317 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 364 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":true},"name":"pipeline with legacy search"},"type":"pipelines"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines + method: POST + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 408 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":true}}}} + headers: + Content-Type: + - application/json + status: 201 Created + code: 201 + duration: 914.891584ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 408 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":true}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 150.86525ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 408 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":true}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 204.988ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 373 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":false},"name":"pipeline with legacy search"},"id":"","type":"pipelines"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: PUT + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 409 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":false}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 458.762541ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 409 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":false}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 177.643583ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 409 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}],"use_legacy_search_syntax":false}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 152.384541ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 340 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}]},"name":"pipeline with legacy search"},"id":"","type":"pipelines"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: PUT + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 376 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}]}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 516.672041ms + - id: 7 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 376 + uncompressed: false + body: | + {"data":{"id":"08b64030-a9f8-11f0-9e79-da7ad0900002","type":"pipelines","attributes":{"name":"pipeline with legacy search","config":{"destinations":[{"id":"destination-1","inputs":["filter-1"],"type":"datadog_logs"}],"processors":[{"id":"filter-1","include":"service:my-service","inputs":["source-1"],"type":"filter"}],"sources":[{"id":"source-1","type":"datadog_agent"}]}}}} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 186.50725ms + - id: 8 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - '*/*' + url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/08b64030-a9f8-11f0-9e79-da7ad0900002 + method: DELETE + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json + status: 204 No Content + code: 204 + duration: 456.948292ms diff --git a/datadog/tests/resource_datadog_observability_pipeline_test.go b/datadog/tests/resource_datadog_observability_pipeline_test.go index cf753f6a6..02c91b4f3 100644 --- a/datadog/tests/resource_datadog_observability_pipeline_test.go +++ b/datadog/tests/resource_datadog_observability_pipeline_test.go @@ -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"] + } + } + } +}` +} diff --git a/docs/resources/observability_pipeline.md b/docs/resources/observability_pipeline.md index 8a5ff91bb..e882affdc 100644 --- a/docs/resources/observability_pipeline.md +++ b/docs/resources/observability_pipeline.md @@ -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. ### Nested Schema for `config.destinations` diff --git a/go.mod b/go.mod index f6f2979ae..c778fe1e6 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 5288ec19e..25166cd3c 100644 --- a/go.sum +++ b/go.sum @@ -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=