diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index f7a6829afe..61f35b7323 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -190,8 +190,15 @@ func (ctx *BuiltinEvalContext) ConfigureProvider(addr addrs.ProviderConfig, cfg diags = diags.Append(fmt.Errorf("%s not initialized", addr)) return diags } + + providerSchema := ctx.ProviderSchema(absAddr) + if providerSchema == nil { + diags = diags.Append(fmt.Errorf("schema for %s is not available", absAddr)) + return diags + } + // FIXME: The provider API isn't yet updated to take a cty.Value directly. - rc := NewResourceConfigShimmed(cfg, ctx.ProviderSchema(absAddr).Provider) + rc := NewResourceConfigShimmed(cfg, providerSchema.Provider) err := p.Configure(rc) if err != nil { diags = diags.Append(err) diff --git a/terraform/eval_validate.go b/terraform/eval_validate.go index 7a35c23f4e..8a5e91fa7b 100644 --- a/terraform/eval_validate.go +++ b/terraform/eval_validate.go @@ -314,6 +314,10 @@ type EvalValidateResource struct { } func (n *EvalValidateResource) Eval(ctx EvalContext) (interface{}, error) { + if n.ProviderSchema == nil { + return nil, fmt.Errorf("EvalValidateResource has nil schema for %s", n.Addr) + } + var diags tfdiags.Diagnostics provider := *n.Provider cfg := *n.Config diff --git a/terraform/transform_attach_schema.go b/terraform/transform_attach_schema.go index 034af35d6c..4c51582299 100644 --- a/terraform/transform_attach_schema.go +++ b/terraform/transform_attach_schema.go @@ -104,11 +104,16 @@ func (t *AttachSchemaTransformer) Transform(g *Graph) error { typeName := addr.Resource.Type providerAddr, _ := tv.ProvidedBy() var schema *configschema.Block + providerSchema := schemas[providerAddr.ProviderConfig.Type] + if providerSchema == nil { + log.Printf("[ERROR] AttachSchemaTransformer: No schema available for %s because provider schema for %q is missing", addr, providerAddr.ProviderConfig.Type) + continue + } switch mode { case addrs.ManagedResourceMode: - schema = schemas[providerAddr.ProviderConfig.Type].ResourceTypes[typeName] + schema = providerSchema.ResourceTypes[typeName] case addrs.DataResourceMode: - schema = schemas[providerAddr.ProviderConfig.Type].DataSources[typeName] + schema = providerSchema.DataSources[typeName] } if schema != nil { log.Printf("[TRACE] AttachSchemaTransformer: attaching schema to %s", dag.VertexName(v)) @@ -118,7 +123,14 @@ func (t *AttachSchemaTransformer) Transform(g *Graph) error { } case GraphNodeAttachProviderConfigSchema: providerAddr := tv.ProviderAddr() + providerSchema := schemas[providerAddr.ProviderConfig.Type] + if providerSchema == nil { + log.Printf("[ERROR] AttachSchemaTransformer: No schema available for %s because the whole provider schema is missing", providerAddr) + continue + } + schema := schemas[providerAddr.ProviderConfig.Type].Provider + if schema != nil { log.Printf("[TRACE] AttachSchemaTransformer: attaching schema to %s", dag.VertexName(v)) tv.AttachProviderConfigSchema(schema)