stacks/stackruntime: Report if provider schema fetching fails

We were previously just ignoring the errors on the assumption that some
other codepath would propagate them, as is our assumption for all
inter-dependencies between objects in stackeval.

However, provider types are a bit of an oddity right now in that they are
really _only_ accessed by implication, and so we don't directly visit them
to get an opportunity to gather any errors. We'll hopefully improve on that
later, but for now we'll just emit the error once for each component
instance to ensure that it gets emitted _somewhere_.

We must also stop before trying to call terraform.NewContext if schema
loading failed, because otherwise terraform.NewContext itself will fail
trying to interact with a provider whose schema it wasn't given.
pull/34738/head
Martin Atkins 3 years ago
parent 2095a7d000
commit 6a45cdf7b0

@ -388,10 +388,24 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
}
schema, err := pTy.Schema(ctx)
if err != nil {
// FIXME: it's not technically our job to report a schema
// fetch failure, but currently there is no single other
// place that definitely does it, so we'll do it here at
// the risk of some redundant errors if we end up using
// the same provider multiple times.
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Provider initialization error",
Detail: fmt.Sprintf("Failed to fetch the provider schema for %s: %s.", sourceAddr, err),
Subject: decl.DeclRange.ToHCL().Ptr(),
})
continue // not our job to report a schema fetch failure
}
providerSchemas[sourceAddr] = schema
}
if diags.HasErrors() {
return nil, diags
}
tfCtx, err := terraform.NewContext(&terraform.ContextOpts{
PreloadedProviderSchemas: providerSchemas,

Loading…
Cancel
Save