From fcb8c53454426382bc0747e09fe791681d13c619 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 2 Apr 2020 15:45:19 -0700 Subject: [PATCH] command/jsonconfig: Use correct provider address to access schema There was a remaining TODO in this package to find the true provider FQN when looking up the schema for a resource type. We now have that data available in the Provider field of configs.Resource, so we can now complete that change. The tests for this functionality actually live in the parent "command" package as part of the tests for the "terraform show" command, so this fix is verified by all of the TestShow... tests now passing except one, and that remaining one is failing for some other reason which we'll address in a later commit. --- command/jsonconfig/config.go | 6 ++---- command/jsonplan/plan.go | 2 +- command/jsonstate/state.go | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/command/jsonconfig/config.go b/command/jsonconfig/config.go index 21775db7d..1911bfa22 100644 --- a/command/jsonconfig/config.go +++ b/command/jsonconfig/config.go @@ -303,15 +303,13 @@ func marshalResources(resources map[string]*configs.Resource, schemas *terraform } } - // TODO: get actual providerFqn - providerFqn := addrs.NewLegacyProvider(v.ProviderConfigAddr().LocalName) schema, schemaVer := schemas.ResourceTypeConfig( - providerFqn, + v.Provider, v.Mode, v.Type, ) if schema == nil { - return nil, fmt.Errorf("no schema found for %s", v.Addr().String()) + return nil, fmt.Errorf("no schema found for %s (in provider %s)", v.Addr().String(), v.Provider) } r.SchemaVersion = schemaVer diff --git a/command/jsonplan/plan.go b/command/jsonplan/plan.go index 7a8bf0efd..ee12a408c 100644 --- a/command/jsonplan/plan.go +++ b/command/jsonplan/plan.go @@ -183,7 +183,7 @@ func (p *plan) marshalResourceChanges(changes *plans.Changes, schemas *terraform addr.Resource.Resource.Type, ) if schema == nil { - return fmt.Errorf("no schema found for %s", r.Address) + return fmt.Errorf("no schema found for %s (in provider %s)", r.Address, rc.ProviderAddr.Provider) } changeV, err := rc.Decode(schema.ImpliedType()) diff --git a/command/jsonstate/state.go b/command/jsonstate/state.go index 1af503c1b..ab1b29683 100644 --- a/command/jsonstate/state.go +++ b/command/jsonstate/state.go @@ -291,7 +291,7 @@ func marshalResources(resources map[string]*states.Resource, module addrs.Module current.SchemaVersion = ri.Current.SchemaVersion if schema == nil { - return nil, fmt.Errorf("no schema found for %s", resAddr.String()) + return nil, fmt.Errorf("no schema found for %s (in provider %s)", resAddr.String(), r.ProviderConfig.Provider) } riObj, err := ri.Current.Decode(schema.ImpliedType()) if err != nil {