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.
This commit is contained in:
Martin Atkins 2020-04-02 15:45:19 -07:00
parent 69cae48a11
commit fcb8c53454
3 changed files with 4 additions and 6 deletions

View File

@ -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

View File

@ -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())

View File

@ -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 {