Created
March 15, 2023 00:35
-
-
Save mkuzmin/b94eac133347fab097c21485a37ec743 to your computer and use it in GitHub Desktop.
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
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