Skip to content

Commit 5438a9e

Browse files
committed
call Configure in fwserver ListResource RPC
1 parent 63b1416 commit 5438a9e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/fwserver/server_listresource.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package fwserver
55

66
import (
77
"context"
8+
"github.com/hashicorp/terraform-plugin-framework/resource"
89
"github.com/hashicorp/terraform-plugin-go/tftypes"
910
"iter"
1011

@@ -99,6 +100,29 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
99100
}
100101
}
101102

103+
resp := ListResult{}
104+
105+
if listResourceWithConfigure, ok := listResource.(list.ListResourceWithConfigure); ok {
106+
logging.FrameworkTrace(ctx, "ListResource implements ListResourceWithConfigure")
107+
108+
configureReq := resource.ConfigureRequest{
109+
ProviderData: s.ListResourceConfigureData,
110+
}
111+
112+
configureResp := resource.ConfigureResponse{}
113+
114+
logging.FrameworkTrace(ctx, "Called provider defined ListResource Configure")
115+
listResourceWithConfigure.Configure(ctx, configureReq, &configureResp)
116+
logging.FrameworkTrace(ctx, "Called provider defined ListResource Configure")
117+
118+
resp.Diagnostics.Append(configureResp.Diagnostics...)
119+
120+
if resp.Diagnostics.HasError() {
121+
return
122+
}
123+
124+
}
125+
102126
req := list.ListRequest{
103127
Config: *fwReq.Config,
104128
IncludeResource: fwReq.IncludeResource,
@@ -118,6 +142,9 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
118142
stream.Results = list.NoListResults
119143
}
120144

145+
// How should we handle the diags produced by Configure called on line 115? Appending them to an empty stream
146+
// might be misleading, not to mention will error below because Identity will be nil
147+
121148
fwStream.Results = processListResults(req, stream.Results)
122149
}
123150

0 commit comments

Comments
 (0)