Skip to content

Commit

Permalink
[mq] working branch - merge 7a35ca4 on top of master at ac5d614
Browse files Browse the repository at this point in the history
{"baseBranch":"master","baseCommit":"ac5d61404ace832dcabcffb198ceaa9ea7c0f53d","createdAt":"2025-01-03T14:31:54.596659Z","headSha":"7a35ca40cedd5f3fd792ec5e0b336b77177ad4a4","id":"b358ee42-47d9-454b-bf22-6b15ff2a7ffe","priority":"200","pullRequestNumber":"2732","queuedAt":"2025-01-03T14:31:54.596253Z","status":"STATUS_QUEUED"}
  • Loading branch information
dd-mergequeue[bot] authored Jan 3, 2025
2 parents 4c2b7c3 + 7a35ca4 commit 7e7fbee
Show file tree
Hide file tree
Showing 8 changed files with 625 additions and 0 deletions.
77 changes: 77 additions & 0 deletions datadog/fwprovider/data_source_datadog_logs_pipelines_order.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}
1 change: 1 addition & 0 deletions datadog/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var Datasources = []func() datasource.DataSource{
NewDatadogRoleUsersDataSource,
NewSecurityMonitoringSuppressionDataSource,
NewCSMThreatsAgentRulesDataSource,
NewLogsPipelinesOrderDataSource,
}

// FrameworkProvider struct
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-12-18T23:56:58.835973+01:00
Loading

0 comments on commit 7e7fbee

Please sign in to comment.