Skip to content

Commit

Permalink
hardcoded data
Browse files Browse the repository at this point in the history
  • Loading branch information
robwhitby committed Sep 25, 2024
1 parent e3d74a0 commit 6b62982
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ provider "ee-platform" {}

data "ee-platform_teams" "teams" {}

output "all_teams" {
value = data.ee-platform_teams.teams
}
55 changes: 54 additions & 1 deletion internal/provider/teams_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
}

0 comments on commit 6b62982

Please sign in to comment.