account for diagnostics when fetching schemas

Maybe we can ensure schemas are all loaded at this point, but we can
tackle that later.
This commit is contained in:
James Bardin 2022-02-02 13:10:39 -05:00
parent c5c7045a89
commit a02d7cc96a
1 changed files with 20 additions and 13 deletions

View File

@ -200,7 +200,10 @@ The -target option is not for routine use, and is provided only for exceptional
panic("nil plan but no errors") panic("nil plan but no errors")
} }
plan.RelevantResources = c.relevantResourcesForPlan(config, plan) relevantResources, rDiags := c.relevantResourcesForPlan(config, plan)
diags = diags.Append(rDiags)
plan.RelevantResources = relevantResources
return plan, diags return plan, diags
} }
@ -363,7 +366,10 @@ func (c *Context) destroyPlan(config *configs.Config, prevRunState *states.State
destroyPlan.PrevRunState = pendingPlan.PrevRunState destroyPlan.PrevRunState = pendingPlan.PrevRunState
} }
destroyPlan.RelevantResources = c.relevantResourcesForPlan(config, destroyPlan) relevantResources, rDiags := c.relevantResourcesForPlan(config, destroyPlan)
diags = diags.Append(rDiags)
destroyPlan.RelevantResources = relevantResources
return destroyPlan, diags return destroyPlan, diags
} }
@ -744,23 +750,24 @@ func blockedMovesWarningDiag(results refactoring.MoveResults) tfdiags.Diagnostic
) )
} }
// ReferenceAnalyzer returns a globalref.Analyzer object to help with // referenceAnalyzer returns a globalref.Analyzer object to help with
// global analysis of references within the configuration that's attached // global analysis of references within the configuration that's attached
// to the receiving context. // to the receiving context.
func (c *Context) ReferenceAnalyzer(config *configs.Config, state *states.State) *globalref.Analyzer { func (c *Context) referenceAnalyzer(config *configs.Config, state *states.State) (*globalref.Analyzer, tfdiags.Diagnostics) {
schemas, diags := c.Schemas(config, state) schemas, diags := c.Schemas(config, state)
if diags != nil { if diags.HasErrors() {
// FIXME: we now have to deal with the diagnostics here return nil, diags
panic(diags.ErrWithWarnings().Error())
} }
return globalref.NewAnalyzer(config, schemas.Providers), diags
return globalref.NewAnalyzer(config, schemas.Providers)
} }
// relevantResourcesForPlan implements the heuristic we use to populate the // relevantResourcesForPlan implements the heuristic we use to populate the
// RelevantResources field of returned plans. // RelevantResources field of returned plans.
func (c *Context) relevantResourcesForPlan(config *configs.Config, plan *plans.Plan) []addrs.AbsResource { func (c *Context) relevantResourcesForPlan(config *configs.Config, plan *plans.Plan) ([]addrs.AbsResource, tfdiags.Diagnostics) {
azr := c.ReferenceAnalyzer(config, plan.PriorState) azr, diags := c.referenceAnalyzer(config, plan.PriorState)
if diags.HasErrors() {
return nil, diags
}
// Our current strategy is that a resource is relevant if it either has // Our current strategy is that a resource is relevant if it either has
// a proposed change action directly, or if its attributes are used as // a proposed change action directly, or if its attributes are used as
@ -792,11 +799,11 @@ func (c *Context) relevantResourcesForPlan(config *configs.Config, plan *plans.P
} }
if len(relevant) == 0 { if len(relevant) == 0 {
return nil return nil, diags
} }
ret := make([]addrs.AbsResource, 0, len(relevant)) ret := make([]addrs.AbsResource, 0, len(relevant))
for _, addr := range relevant { for _, addr := range relevant {
ret = append(ret, addr) ret = append(ret, addr)
} }
return ret return ret, diags
} }