@@ -347,10 +347,12 @@ func (n *NodeAbstractResource) writeResourceState(ctx EvalContext, addr addrs.Ab
347
347
348
348
// readResourceInstanceState reads the current object for a specific instance in
349
349
// the state.
350
- func (n * NodeAbstractResource ) readResourceInstanceState (ctx EvalContext , addr addrs.AbsResourceInstance ) (* states.ResourceInstanceObject , error ) {
350
+ func (n * NodeAbstractResource ) readResourceInstanceState (ctx EvalContext , addr addrs.AbsResourceInstance ) (* states.ResourceInstanceObject , tfdiags.Diagnostics ) {
351
+ var diags tfdiags.Diagnostics
351
352
provider , providerSchema , err := getProvider (ctx , n .ResolvedProvider )
352
353
if err != nil {
353
- return nil , err
354
+ diags = diags .Append (err )
355
+ return nil , diags
354
356
}
355
357
356
358
log .Printf ("[TRACE] readResourceInstanceState: reading state for %s" , addr )
@@ -365,36 +367,41 @@ func (n *NodeAbstractResource) readResourceInstanceState(ctx EvalContext, addr a
365
367
schema , currentVersion := (providerSchema ).SchemaForResourceAddr (addr .Resource .ContainingResource ())
366
368
if schema == nil {
367
369
// Shouldn't happen since we should've failed long ago if no schema is present
368
- return nil , fmt .Errorf ("no schema available for %s while reading state; this is a bug in Terraform and should be reported" , addr )
370
+ return nil , diags . Append ( fmt .Errorf ("no schema available for %s while reading state; this is a bug in Terraform and should be reported" , addr ) )
369
371
}
370
- var diags tfdiags.Diagnostics
371
- src , diags = upgradeResourceState (addr , provider , src , schema , currentVersion )
372
+ src , upgradeDiags := upgradeResourceState (addr , provider , src , schema , currentVersion )
373
+ if n .Config != nil {
374
+ upgradeDiags = upgradeDiags .InConfigBody (n .Config .Config , addr .String ())
375
+ }
376
+ diags = diags .Append (upgradeDiags )
372
377
if diags .HasErrors () {
373
378
// Note that we don't have any channel to return warnings here. We'll
374
379
// accept that for now since warnings during a schema upgrade would
375
380
// be pretty weird anyway, since this operation is supposed to seem
376
381
// invisible to the user.
377
- return nil , diags . Err ()
382
+ return nil , diags
378
383
}
379
384
380
385
obj , err := src .Decode (schema .ImpliedType ())
381
386
if err != nil {
382
- return nil , err
387
+ diags = diags . Append ( err )
383
388
}
384
389
385
- return obj , nil
390
+ return obj , diags
386
391
}
387
392
388
393
// readResourceInstanceStateDeposed reads the deposed object for a specific
389
394
// instance in the state.
390
- func (n * NodeAbstractResource ) readResourceInstanceStateDeposed (ctx EvalContext , addr addrs.AbsResourceInstance , key states.DeposedKey ) (* states.ResourceInstanceObject , error ) {
395
+ func (n * NodeAbstractResource ) readResourceInstanceStateDeposed (ctx EvalContext , addr addrs.AbsResourceInstance , key states.DeposedKey ) (* states.ResourceInstanceObject , tfdiags.Diagnostics ) {
396
+ var diags tfdiags.Diagnostics
391
397
provider , providerSchema , err := getProvider (ctx , n .ResolvedProvider )
392
398
if err != nil {
393
- return nil , err
399
+ diags = diags .Append (err )
400
+ return nil , diags
394
401
}
395
402
396
403
if key == states .NotDeposed {
397
- return nil , fmt .Errorf ("readResourceInstanceStateDeposed used with no instance key; this is a bug in Terraform and should be reported" )
404
+ return nil , diags . Append ( fmt .Errorf ("readResourceInstanceStateDeposed used with no instance key; this is a bug in Terraform and should be reported" ) )
398
405
}
399
406
400
407
log .Printf ("[TRACE] readResourceInstanceStateDeposed: reading state for %s deposed object %s" , addr , key )
@@ -403,31 +410,35 @@ func (n *NodeAbstractResource) readResourceInstanceStateDeposed(ctx EvalContext,
403
410
if src == nil {
404
411
// Presumably we only have deposed objects, then.
405
412
log .Printf ("[TRACE] readResourceInstanceStateDeposed: no state present for %s deposed object %s" , addr , key )
406
- return nil , nil
413
+ return nil , diags
407
414
}
408
415
409
416
schema , currentVersion := (providerSchema ).SchemaForResourceAddr (addr .Resource .ContainingResource ())
410
417
if schema == nil {
411
418
// Shouldn't happen since we should've failed long ago if no schema is present
412
- return nil , fmt .Errorf ("no schema available for %s while reading state; this is a bug in Terraform and should be reported" , addr )
419
+ return nil , diags . Append ( fmt .Errorf ("no schema available for %s while reading state; this is a bug in Terraform and should be reported" , addr ) )
413
420
414
421
}
415
422
416
- src , diags := upgradeResourceState (addr , provider , src , schema , currentVersion )
423
+ src , upgradeDiags := upgradeResourceState (addr , provider , src , schema , currentVersion )
424
+ if n .Config != nil {
425
+ upgradeDiags = upgradeDiags .InConfigBody (n .Config .Config , addr .String ())
426
+ }
427
+ diags = diags .Append (upgradeDiags )
417
428
if diags .HasErrors () {
418
429
// Note that we don't have any channel to return warnings here. We'll
419
430
// accept that for now since warnings during a schema upgrade would
420
431
// be pretty weird anyway, since this operation is supposed to seem
421
432
// invisible to the user.
422
- return nil , diags . Err ()
433
+ return nil , diags
423
434
}
424
435
425
436
obj , err := src .Decode (schema .ImpliedType ())
426
437
if err != nil {
427
- return nil , err
438
+ diags = diags . Append ( err )
428
439
}
429
440
430
- return obj , nil
441
+ return obj , diags
431
442
}
432
443
433
444
// graphNodesAreResourceInstancesInDifferentInstancesOfSameModule is an
0 commit comments