Skip to content

Commit

Permalink
scaffold app in tf provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tyffical committed Dec 18, 2024
1 parent f4b4421 commit 8006937
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 0 deletions.
62 changes: 62 additions & 0 deletions datadog/fwprovider/data_source_datadog_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package fwprovider

import (
"context"

"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
"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.DataSource = &appDataSource{}

type appDataSource struct {
Api *datadogV2.AppsApi
Auth context.Context
}

func NewDatadogAppDataSource() datasource.DataSource {
return &appDataSource{}
}

// TODO: figure out rest of model
type datadogAppDatasourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

func (d *appDataSource) Configure(_ context.Context, request datasource.ConfigureRequest, response *datasource.ConfigureResponse) {
providerData := request.ProviderData.(*FrameworkProvider)
d.Api = providerData.DatadogApiInstances.GetAppsApiV2()
d.Auth = providerData.Auth
}

func (d *appDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) {
response.TypeName = "app"
}

// TODO: figure out rest of schema
func (d *appDataSource) Schema(_ context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Description: "Use this data source to retrieve information about an existing App, for use in other resources.",
Attributes: map[string]schema.Attribute{
"id": utils.ResourceIDAttribute(),
},
}
}

// TODO
func (d *appDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var state datadogAppDatasourceModel
diags := request.Config.Get(ctx, &state)
response.Diagnostics.Append(diags...)
if response.Diagnostics.HasError() {
return
}

state.ID = types.StringValue("hi")
diags = response.State.Set(ctx, &state)
response.Diagnostics.Append(diags...)
}
2 changes: 2 additions & 0 deletions datadog/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var Resources = []func() resource.Resource{
NewWebhookCustomVariableResource,
NewLogsCustomDestinationResource,
NewTenantBasedHandleResource,
NewAppResource,
}

var Datasources = []func() datasource.DataSource{
Expand All @@ -92,6 +93,7 @@ var Datasources = []func() datasource.DataSource{
NewDatadogRoleUsersDataSource,
NewSecurityMonitoringSuppressionDataSource,
NewCSMThreatsAgentRulesDataSource,
NewDatadogAppDataSource,
}

// FrameworkProvider struct
Expand Down
Loading

0 comments on commit 8006937

Please sign in to comment.