-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
8 changed files
with
625 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
datadog/fwprovider/data_source_datadog_logs_pipelines_order.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
datadog/tests/cassettes/TestAccDatadogLogsPipelinesOrderDatasource.freeze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2024-12-18T23:56:58.835973+01:00 |
Oops, something went wrong.