diff --git a/examples/provider-install-verification/main.tf b/examples/provider-install-verification/main.tf index bfea898..dfb14c8 100644 --- a/examples/provider-install-verification/main.tf +++ b/examples/provider-install-verification/main.tf @@ -10,3 +10,6 @@ provider "ee-platform" {} data "ee-platform_teams" "teams" {} +output "all_teams" { + value = data.ee-platform_teams.teams +} \ No newline at end of file diff --git a/internal/provider/teams_data_source.go b/internal/provider/teams_data_source.go index 7b1b5b3..fb7087a 100644 --- a/internal/provider/teams_data_source.go +++ b/internal/provider/teams_data_source.go @@ -2,6 +2,7 @@ package provider import ( "context" + "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -27,9 +28,61 @@ func (d *teamsDataSource) Metadata(_ context.Context, req datasource.MetadataReq // Schema defines the schema for the data source. func (d *teamsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{} + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "teams": schema.ListNestedAttribute{ + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + "cf_org": schema.StringAttribute{ + Computed: true, + Optional: true, + }, + }, + }, + }, + }, + } } // Read refreshes the Terraform state with the latest data. func (d *teamsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + state := teamsDataSourceModel{ + Teams: []teamsModel{ + { + ID: types.StringValue("team1"), + Name: types.StringValue("Team 1"), + CfOrg: types.StringValue("cforg1"), + }, + { + ID: types.StringValue("team2"), + Name: types.StringValue("Team 2"), + }, + }, + } + + // Set state + diags := resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +// coffeesDataSourceModel maps the data source schema data. +type teamsDataSourceModel struct { + Teams []teamsModel `tfsdk:"teams"` +} + +// teamsModel maps coffees schema data. +type teamsModel struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + CfOrg types.String `tfsdk:"cf_org"` }