From e3cfaa82f042c911bb5935fa20668c42abc25190 Mon Sep 17 00:00:00 2001 From: Loris Friedel Date: Thu, 19 Dec 2024 00:06:17 +0100 Subject: [PATCH 1/2] Add datadog_logs_pipelines_order data source --- ...ata_source_datadog_logs_pipelines_order.go | 77 +++ datadog/fwprovider/framework_provider.go | 1 + ...DatadogLogsPipelinesOrderDatasource.freeze | 1 + ...ccDatadogLogsPipelinesOrderDatasource.yaml | 460 ++++++++++++++++++ ...ource_datadog_logs_pipelines_order_test.go | 59 +++ datadog/tests/provider_test.go | 1 + docs/data-sources/logs_pipelines_order.md | 21 + 7 files changed, 620 insertions(+) create mode 100644 datadog/fwprovider/data_source_datadog_logs_pipelines_order.go create mode 100644 datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.freeze create mode 100644 datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.yaml create mode 100644 datadog/tests/data_source_datadog_logs_pipelines_order_test.go create mode 100644 docs/data-sources/logs_pipelines_order.md diff --git a/datadog/fwprovider/data_source_datadog_logs_pipelines_order.go b/datadog/fwprovider/data_source_datadog_logs_pipelines_order.go new file mode 100644 index 000000000..f5549c038 --- /dev/null +++ b/datadog/fwprovider/data_source_datadog_logs_pipelines_order.go @@ -0,0 +1,77 @@ +package fwprovider + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "strings" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" +) + +var ( + _ datasource.DataSourceWithConfigure = &logsPipelinesOrderDataSource{} +) + +type logsPipelinesOrderDataSource struct { + api *datadogV1.LogsPipelinesApi + auth context.Context +} + +type logsPipelinesOrderDataSourceModel struct { + Id types.String `tfsdk:"id"` + PipelineIds []string `tfsdk:"pipeline_ids"` +} + +func NewLogsPipelinesOrderDataSource() datasource.DataSource { + return &logsPipelinesOrderDataSource{} +} + +func (r *logsPipelinesOrderDataSource) Configure(_ context.Context, request datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + providerData := request.ProviderData.(*FrameworkProvider) + r.api = providerData.DatadogApiInstances.GetLogsPipelinesApiV1() + r.auth = providerData.Auth +} + +func (*logsPipelinesOrderDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, response *datasource.MetadataResponse) { + response.TypeName = "logs_pipelines_order" +} + +func (r *logsPipelinesOrderDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { + var state logsPipelinesOrderDataSourceModel + response.Diagnostics.Append(request.Config.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + res, _, err := r.api.GetLogsPipelineOrder(r.auth) + if err != nil { + response.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error while fetching logs pipelines order")) + return + } + + stateIdHash := sha256.Sum256([]byte(strings.Join(res.GetPipelineIds(), ";"))) + state.Id = types.StringValue(hex.EncodeToString(stateIdHash[:])) + + state.PipelineIds = res.GetPipelineIds() + response.Diagnostics.Append(response.State.Set(ctx, &state)...) +} + +func (*logsPipelinesOrderDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, response *datasource.SchemaResponse) { + response.Schema = schema.Schema{ + Description: "Use this data source to retrieve the current order of your log pipelines.", + Attributes: map[string]schema.Attribute{ + "id": utils.ResourceIDAttribute(), + "pipeline_ids": schema.ListAttribute{ + Computed: true, + Description: "Array of strings identifying by their id(s) the pipeline(s) of your organization. For each pipeline, following the order of the array, logs are tested against the query filter and processed if matching.", + ElementType: types.StringType, + }, + }, + } +} diff --git a/datadog/fwprovider/framework_provider.go b/datadog/fwprovider/framework_provider.go index f59316935..3e7e8c9f6 100644 --- a/datadog/fwprovider/framework_provider.go +++ b/datadog/fwprovider/framework_provider.go @@ -92,6 +92,7 @@ var Datasources = []func() datasource.DataSource{ NewDatadogRoleUsersDataSource, NewSecurityMonitoringSuppressionDataSource, NewCSMThreatsAgentRulesDataSource, + NewLogsPipelinesOrderDataSource, } // FrameworkProvider struct diff --git a/datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.freeze b/datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.freeze new file mode 100644 index 000000000..60772f1aa --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.freeze @@ -0,0 +1 @@ +2024-12-18T23:56:58.835973+01:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.yaml b/datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.yaml new file mode 100644 index 000000000..d0fbfcec3 --- /dev/null +++ b/datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.yaml @@ -0,0 +1,460 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 152 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"filter":{"query":"project:sample"},"is_enabled":false,"name":"tf-testaccdatadoglogspipelinesorderdatasource-local-1734562618-sample","processors":[]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v1/logs/config/pipelines + method: POST + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"id":"VxfwbMFDR3iyospifjNrbA","type":"pipeline","name":"tf-testaccdatadoglogspipelinesorderdatasource-local-1734562618-sample","is_enabled":false,"is_read_only":false,"filter":{"query":"project:sample"},"processors":[]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 478.163667ms + - 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw","VxfwbMFDR3iyospifjNrbA"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 152.609666ms + - 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw","VxfwbMFDR3iyospifjNrbA"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 147.13375ms + - id: 3 + 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/v1/logs/config/pipelines/VxfwbMFDR3iyospifjNrbA + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"id":"VxfwbMFDR3iyospifjNrbA","type":"pipeline","name":"tf-testaccdatadoglogspipelinesorderdatasource-local-1734562618-sample","is_enabled":false,"is_read_only":false,"filter":{"query":"project:sample"},"processors":[]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 154.446959ms + - 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw","VxfwbMFDR3iyospifjNrbA"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 152.737125ms + - 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw","VxfwbMFDR3iyospifjNrbA"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 156.102541ms + - id: 6 + 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw","VxfwbMFDR3iyospifjNrbA"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 151.347917ms + - 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/v1/logs/config/pipelines/VxfwbMFDR3iyospifjNrbA + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"id":"VxfwbMFDR3iyospifjNrbA","type":"pipeline","name":"tf-testaccdatadoglogspipelinesorderdatasource-local-1734562618-sample","is_enabled":false,"is_read_only":false,"filter":{"query":"project:sample"},"processors":[]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 307.944417ms + - 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: + - application/json + url: https://api.datadoghq.com/api/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw","VxfwbMFDR3iyospifjNrbA"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 252.539125ms + - id: 9 + 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/v1/logs/config/pipelines/VxfwbMFDR3iyospifjNrbA + method: DELETE + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 3 + uncompressed: false + body: | + {} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 167.670667ms + - id: 10 + 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 151.960459ms + - id: 11 + 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 145.813708ms + - id: 12 + 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/v1/logs/config/pipeline-order + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: + - chunked + trailer: {} + content_length: -1 + uncompressed: true + body: | + {"pipeline_ids":["pMhyxnUeS6ugpnLdWckGIw","7YBUZ3J_RJGDRk6b5ayIIQ","UodPu7HbQ-Gcp2K1aZBRhw","K2HR3G6PSlC_KIhceFuxig","UBNUhCTxR_Goiw7w4wEOlw","cgS5obmTSi6NgGX05lf0tg","JW6WRX6zSYO6P27n-R85vw","4I6FNy5GToqi2fKVAqNZJw","vL--Mbs7SceY84ADEYu40w","dRPabp5dQLO24WxISJq4mg","RSbXaJxLS8WSZbAV6vJnYg","r-jB58U1TI6y_vJbBX2nzA","wLD85Kf3RiGkCu35OTl9KA","C3rLxhf7RrOMi4M9rrBv6g","GJYHVcVzT6uN_0crZdRpzQ","LWIrk9TLT3Kp9hnIbWBs2w","XCYdgKpPQFKyhKexiTkbcQ","TL1aouiMTNmpCCN1iZxoSA","rTxbr2MpQsSCEtn66XmwnQ","2QGdoZWESWi6WArjxl4cxg","0mc2Xh9XTOKHDRooX8oU7Q","htXFf5DCQ_ay1IhQ9Tr4uw"]} + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 146.133459ms diff --git a/datadog/tests/data_source_datadog_logs_pipelines_order_test.go b/datadog/tests/data_source_datadog_logs_pipelines_order_test.go new file mode 100644 index 000000000..38f2b49e8 --- /dev/null +++ b/datadog/tests/data_source_datadog_logs_pipelines_order_test.go @@ -0,0 +1,59 @@ +package test + +import ( + "context" + "fmt" + "regexp" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccDatadogLogsPipelinesOrderDatasource(t *testing.T) { + t.Parallel() + + ctx, _, accProviders := testAccFrameworkMuxProviders(context.Background(), t) + uniq := strings.ToLower(uniqueEntityName(ctx, t)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: accProviders, + Steps: []resource.TestStep{ + { + Config: testAccDatasourceDatadogLogsPipelinesOrderWithPipelineConfig(uniq), + // given the persistent nature of log pipelines we can't check for exact value + Check: resource.TestMatchResourceAttr("data.datadog_logs_pipelines_order.order", "pipeline_ids.#", regexp.MustCompile("[^0].*$")), + }, + { + Config: testAccDatasourceDatadogLogsPipelinesOrderConfig(), + // given the persistent nature of log pipelines we can't check for exact value + // we can assume that at least one pipeline already exists given the previous test + Check: resource.TestMatchResourceAttr("data.datadog_logs_pipelines_order.order", "pipeline_ids.#", regexp.MustCompile("[^0].*$")), + }, + }, + }) +} + +func testAccDatasourceDatadogLogsPipelinesOrderWithPipelineConfig(uniq string) string { + return fmt.Sprintf(` +data "datadog_logs_pipelines_order" "order" { + depends_on = [ + datadog_logs_custom_pipeline.sample_pipeline, + ] +} + +resource "datadog_logs_custom_pipeline" "sample_pipeline" { + name = "%s-sample" + filter { + query = "project:sample" + } +} +`, uniq) +} + +func testAccDatasourceDatadogLogsPipelinesOrderConfig() string { + return ` +data "datadog_logs_pipelines_order" "order" {} +` +} diff --git a/datadog/tests/provider_test.go b/datadog/tests/provider_test.go index a1fd807ee..c6b2f2ad2 100644 --- a/datadog/tests/provider_test.go +++ b/datadog/tests/provider_test.go @@ -68,6 +68,7 @@ var testFiles2EndpointTags = map[string]string{ "tests/data_source_datadog_logs_archives_order_test": "logs-archive", "tests/data_source_datadog_logs_indexes_order_test": "logs-index", "tests/data_source_datadog_logs_indexes_test": "logs-index", + "tests/data_source_datadog_logs_pipelines_order_test": "logs-pipelines", "tests/data_source_datadog_logs_pipelines_test": "logs-pipelines", "tests/data_source_datadog_monitor_config_policies_test": "monitor-config-policies", "tests/data_source_datadog_monitor_config_policy_test": "monitor-config-policies", diff --git a/docs/data-sources/logs_pipelines_order.md b/docs/data-sources/logs_pipelines_order.md new file mode 100644 index 000000000..933efd1ca --- /dev/null +++ b/docs/data-sources/logs_pipelines_order.md @@ -0,0 +1,21 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "datadog_logs_pipelines_order Data Source - terraform-provider-datadog" +subcategory: "" +description: |- + Use this data source to retrieve the current order of your log pipelines. +--- + +# datadog_logs_pipelines_order (Data Source) + +Use this data source to retrieve the current order of your log pipelines. + + + + +## Schema + +### Read-Only + +- `id` (String) The ID of this resource. +- `pipeline_ids` (List of String) Array of strings identifying by their id(s) the pipeline(s) of your organization. For each pipeline, following the order of the array, logs are tested against the query filter and processed if matching. From 7a35ca40cedd5f3fd792ec5e0b336b77177ad4a4 Mon Sep 17 00:00:00 2001 From: Loris Friedel Date: Fri, 20 Dec 2024 19:20:55 +0100 Subject: [PATCH 2/2] Add example + doc --- docs/data-sources/logs_pipelines_order.md | 4 ++++ .../data-sources/datadog_logs_pipelines_order/data-source.tf | 1 + 2 files changed, 5 insertions(+) create mode 100644 examples/data-sources/datadog_logs_pipelines_order/data-source.tf diff --git a/docs/data-sources/logs_pipelines_order.md b/docs/data-sources/logs_pipelines_order.md index 933efd1ca..adc5a69af 100644 --- a/docs/data-sources/logs_pipelines_order.md +++ b/docs/data-sources/logs_pipelines_order.md @@ -10,7 +10,11 @@ description: |- Use this data source to retrieve the current order of your log pipelines. +## Example Usage +```terraform +data "datadog_logs_pipelines_order" "test" {} +``` ## Schema diff --git a/examples/data-sources/datadog_logs_pipelines_order/data-source.tf b/examples/data-sources/datadog_logs_pipelines_order/data-source.tf new file mode 100644 index 000000000..c542e27a3 --- /dev/null +++ b/examples/data-sources/datadog_logs_pipelines_order/data-source.tf @@ -0,0 +1 @@ +data "datadog_logs_pipelines_order" "test" {}