-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8d78a96
commit 038803d
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
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,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)...) | ||
} |