core: AttachSchemaTransformer fail gracefully with no schema
Having a missing schema is a programming error, but at the time of this commit we're in the midst of introducing schema all over Terraform and so there are inevitably some places -- particularly in older unit tests -- where schema isn't yet being provided. This error allows us to catch those cases and fail gracefully, rather than panicking further down here when we access t.Components methods. Also includes some additional logging to aid debugging of this transformer.
This commit is contained in:
parent
b73e4ede5d
commit
71d7a9e480
|
@ -38,15 +38,23 @@ type AttachSchemaTransformer struct {
|
||||||
|
|
||||||
func (t *AttachSchemaTransformer) Transform(g *Graph) error {
|
func (t *AttachSchemaTransformer) Transform(g *Graph) error {
|
||||||
|
|
||||||
|
if t.Components == nil {
|
||||||
|
// Should never happen with a reasonable caller, but we'll return a
|
||||||
|
// proper error here anyway so that we'll fail gracefully.
|
||||||
|
return fmt.Errorf("AttachSchemaTransformer used with nil Components")
|
||||||
|
}
|
||||||
|
|
||||||
// First we'll figure out which provider types we need to fetch schemas for.
|
// First we'll figure out which provider types we need to fetch schemas for.
|
||||||
needProviders := make(map[string]struct{})
|
needProviders := make(map[string]struct{})
|
||||||
for _, v := range g.Vertices() {
|
for _, v := range g.Vertices() {
|
||||||
switch tv := v.(type) {
|
switch tv := v.(type) {
|
||||||
case GraphNodeAttachResourceSchema:
|
case GraphNodeAttachResourceSchema:
|
||||||
providerAddr, _ := tv.ProvidedBy()
|
providerAddr, _ := tv.ProvidedBy()
|
||||||
|
log.Printf("[TRACE] AttachSchemaTransformer: %q (%T) needs %s", dag.VertexName(v), v, providerAddr)
|
||||||
needProviders[providerAddr.ProviderConfig.Type] = struct{}{}
|
needProviders[providerAddr.ProviderConfig.Type] = struct{}{}
|
||||||
case GraphNodeAttachProviderConfigSchema:
|
case GraphNodeAttachProviderConfigSchema:
|
||||||
providerAddr := tv.ProviderAddr()
|
providerAddr := tv.ProviderAddr()
|
||||||
|
log.Printf("[TRACE] AttachSchemaTransformer: %q (%T) needs %s", dag.VertexName(v), v, providerAddr)
|
||||||
needProviders[providerAddr.ProviderConfig.Type] = struct{}{}
|
needProviders[providerAddr.ProviderConfig.Type] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue