Skip to content

Instantly share code, notes, and snippets.

@mkuzmin
Created March 15, 2023 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkuzmin/b94eac133347fab097c21485a37ec743 to your computer and use it in GitHub Desktop.
Save mkuzmin/b94eac133347fab097c21485a37ec743 to your computer and use it in GitHub Desktop.
package teamcity
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var (
_ datasource.DataSource = &testDataSource{}
)
func NewTestDataSource() datasource.DataSource {
return &testDataSource{}
}
type testDataSource struct {
}
type testDataSourceModel1 struct {
ID types.String `tfsdk:"id"`
}
type testDataSourceModel2 struct {
testDataSourceModel1
Version types.String `tfsdk:"version"`
}
func (d *testDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_test"
}
func (d *testDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"version": schema.StringAttribute{
Computed: true,
},
},
}
}
func (d *testDataSource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
var state testDataSourceModel2
state.ID = types.StringValue("a")
state.Version = types.StringValue("b")
diags := resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment