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 d39155e
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions internal/datasources/secret/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// (C) Copyright 2024 Hewlett Packard Enterprise Development LP

//go:build experimental

package secret

import (
"context"
"errors"

Check failure on line 9 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / docs

"errors" imported and not used

Check failure on line 9 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / build (1.22.3)

"errors" imported and not used
"fmt"

Check failure on line 10 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / docs

"fmt" imported and not used

Check failure on line 10 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / build (1.22.3)

"fmt" imported and not used

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/client"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/constants"

Check failure on line 13 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / docs

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/constants" imported and not used

Check failure on line 13 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / build (1.22.3)

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/constants" imported and not used
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/systems/privatecloudbusiness"

Check failure on line 14 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / docs

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/systems/privatecloudbusiness" imported and not used

Check failure on line 14 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / build (1.22.3)

"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/systems/privatecloudbusiness" imported and not used
"github.com/hashicorp/terraform-plugin-framework/attr"

Check failure on line 15 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / docs

"github.com/hashicorp/terraform-plugin-framework/attr" imported and not used

Check failure on line 15 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / build (1.22.3)

"github.com/hashicorp/terraform-plugin-framework/attr" imported and not used
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"

Check failure on line 17 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / docs

"github.com/hashicorp/terraform-plugin-framework/types" imported and not used

Check failure on line 17 in internal/datasources/secret/data_source.go

View workflow job for this annotation

GitHub Actions / build (1.22.3)

"github.com/hashicorp/terraform-plugin-framework/types" imported and not used
"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 d39155e

Please sign in to comment.