1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package provider
- import (
- "context"
- "log"
- "github.com/hashicorp/terraform-plugin-framework/diag"
- "github.com/hashicorp/terraform-plugin-framework/tfsdk"
- "github.com/hashicorp/terraform-plugin-framework/types"
- )
- var _ tfsdk.DataSourceType = exampleDataSourceType{}
- var _ tfsdk.DataSource = exampleDataSource{}
- type exampleDataSourceType struct{}
- func (t exampleDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
- return tfsdk.Schema{
-
- MarkdownDescription: "Example data source",
- Attributes: map[string]tfsdk.Attribute{
- "configurable_attribute": {
- MarkdownDescription: "Example configurable attribute",
- Optional: true,
- Type: types.StringType,
- },
- "id": {
- MarkdownDescription: "Example identifier",
- Type: types.StringType,
- Computed: true,
- },
- },
- }, nil
- }
- func (t exampleDataSourceType) NewDataSource(ctx context.Context, in tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) {
- provider, diags := convertProviderType(in)
- return exampleDataSource{
- provider: provider,
- }, diags
- }
- type exampleDataSourceData struct {
- ConfigurableAttribute types.String `tfsdk:"configurable_attribute"`
- Id types.String `tfsdk:"id"`
- }
- type exampleDataSource struct {
- provider provider
- }
- func (d exampleDataSource) Read(ctx context.Context, req tfsdk.ReadDataSourceRequest, resp *tfsdk.ReadDataSourceResponse) {
- var data exampleDataSourceData
- diags := req.Config.Get(ctx, &data)
- resp.Diagnostics.Append(diags...)
- log.Printf("got here")
- if resp.Diagnostics.HasError() {
- return
- }
- log.Printf("got here")
-
-
-
-
-
-
-
-
-
- data.Id = types.String{Value: "example-id"}
- diags = resp.State.Set(ctx, &data)
- resp.Diagnostics.Append(diags...)
- }
|