From 6a45cdf7b0b09f4d5c42b2a2f772bad9db4fcd15 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 11 Sep 2023 12:20:48 -0700 Subject: [PATCH] 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. --- .../internal/stackeval/component_instance.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/stacks/stackruntime/internal/stackeval/component_instance.go b/internal/stacks/stackruntime/internal/stackeval/component_instance.go index 08885367c5..94242e047a 100644 --- a/internal/stacks/stackruntime/internal/stackeval/component_instance.go +++ b/internal/stacks/stackruntime/internal/stackeval/component_instance.go @@ -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,