-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
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
There are no files selected for viewing
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 GitHub Actions / docs
|
||
"fmt" | ||
Check failure on line 10 in internal/datasources/secret/data_source.go GitHub Actions / docs
|
||
|
||
"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 GitHub Actions / docs
|
||
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/systems/privatecloudbusiness" | ||
Check failure on line 14 in internal/datasources/secret/data_source.go GitHub Actions / docs
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
Check failure on line 15 in internal/datasources/secret/data_source.go GitHub Actions / docs
|
||
"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 GitHub Actions / docs
|
||
"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)...) | ||
} |