@@ -130,10 +130,49 @@ func isImportedFlagFromPrivate(p []byte) (f bool, d []*tfprotov5.Diagnostic) {
130130func (s * RawProviderServer ) PlanResourceChange (ctx context.Context , req * tfprotov5.PlanResourceChangeRequest ) (* tfprotov5.PlanResourceChangeResponse , error ) {
131131 resp := & tfprotov5.PlanResourceChangeResponse {}
132132
133+ rt , err := GetResourceType (req .TypeName )
134+ if err != nil {
135+ resp .Diagnostics = append (resp .Diagnostics , & tfprotov5.Diagnostic {
136+ Severity : tfprotov5 .DiagnosticSeverityError ,
137+ Summary : "Failed to determine planned resource type" ,
138+ Detail : err .Error (),
139+ })
140+ return resp , nil
141+ }
142+ // Decode proposed resource state
143+ proposedState , err := req .ProposedNewState .Unmarshal (rt )
144+ if err != nil {
145+ resp .Diagnostics = append (resp .Diagnostics , & tfprotov5.Diagnostic {
146+ Severity : tfprotov5 .DiagnosticSeverityError ,
147+ Summary : "Failed to unmarshal planned resource state" ,
148+ Detail : err .Error (),
149+ })
150+ return resp , nil
151+ }
152+ s .logger .Trace ("[PlanResourceChange]" , "[ProposedState]" , dump (proposedState ))
153+
154+ proposedVal := make (map [string ]tftypes.Value )
155+ err = proposedState .As (& proposedVal )
156+ if err != nil {
157+ resp .Diagnostics = append (resp .Diagnostics , & tfprotov5.Diagnostic {
158+ Severity : tfprotov5 .DiagnosticSeverityError ,
159+ Summary : "Failed to extract planned resource state from tftypes.Value" ,
160+ Detail : err .Error (),
161+ })
162+ return resp , nil
163+ }
164+
133165 canDeferr := req .ClientCapabilities != nil && req .ClientCapabilities .DeferralAllowed
134166
135167 if canDeferr && s .clientConfigUnknown {
136168 // if client supports it, request deferral when client configuration not fully known
169+ proposedVal ["object" ] = tftypes .NewValue (tftypes .DynamicPseudoType , tftypes .UnknownValue )
170+ newPlannedState := tftypes .NewValue (proposedState .Type (), proposedVal )
171+ ps , err := tfprotov5 .NewDynamicValue (newPlannedState .Type (), newPlannedState )
172+ if err != nil {
173+ return resp , err
174+ }
175+ resp .PlannedState = & ps
137176 resp .Deferred = & tfprotov5.Deferred {
138177 Reason : tfprotov5 .DeferredReasonProviderConfigUnknown ,
139178 }
@@ -164,38 +203,6 @@ func (s *RawProviderServer) PlanResourceChange(ctx context.Context, req *tfproto
164203 return resp , nil
165204 }
166205
167- rt , err := GetResourceType (req .TypeName )
168- if err != nil {
169- resp .Diagnostics = append (resp .Diagnostics , & tfprotov5.Diagnostic {
170- Severity : tfprotov5 .DiagnosticSeverityError ,
171- Summary : "Failed to determine planned resource type" ,
172- Detail : err .Error (),
173- })
174- return resp , nil
175- }
176- // Decode proposed resource state
177- proposedState , err := req .ProposedNewState .Unmarshal (rt )
178- if err != nil {
179- resp .Diagnostics = append (resp .Diagnostics , & tfprotov5.Diagnostic {
180- Severity : tfprotov5 .DiagnosticSeverityError ,
181- Summary : "Failed to unmarshal planned resource state" ,
182- Detail : err .Error (),
183- })
184- return resp , nil
185- }
186- s .logger .Trace ("[PlanResourceChange]" , "[ProposedState]" , dump (proposedState ))
187-
188- proposedVal := make (map [string ]tftypes.Value )
189- err = proposedState .As (& proposedVal )
190- if err != nil {
191- resp .Diagnostics = append (resp .Diagnostics , & tfprotov5.Diagnostic {
192- Severity : tfprotov5 .DiagnosticSeverityError ,
193- Summary : "Failed to extract planned resource state from tftypes.Value" ,
194- Detail : err .Error (),
195- })
196- return resp , nil
197- }
198-
199206 computedFields := make (map [string ]* tftypes.AttributePath )
200207 var atp * tftypes.AttributePath
201208 cfVal , ok := proposedVal ["computed_fields" ]
0 commit comments