Skip to content

Commit

Permalink
Add secret data source boilerplate
Browse files Browse the repository at this point in the history
Add initial boilerplate code for the "secret"
data source. Currently this code does nothing, the
relevant functionality will be added in later
changes.
  • Loading branch information
stuart-mclaren-hpe committed Dec 13, 2024
1 parent 8d78a96 commit 038803d
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions internal/datasources/secret/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP

//go:build experimental

package secret

import (
"context"

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/client"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSource = &DataSource{}

func NewDataSource() datasource.DataSource {
return &DataSource{}
}

// DataSource defines the data source implementation.
type DataSource struct {
client *client.PCBeClient
}

func (s *DataSource) Metadata(
ctx context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_secret"
}

func (s *DataSource) Schema(
ctx context.Context,
req datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = SecretDataSourceSchema(ctx)
}

func (s *DataSource) Configure(
ctx context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
tflog.Warn(ctx, "provider has not been configured.")

return
}

s.client = req.ProviderData.(*client.PCBeClient)
}

func (s *DataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var data SecretModel

resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

if resp.Diagnostics.HasError() {
return
}

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

0 comments on commit 038803d

Please sign in to comment.