type names don't imply the resource mode
The addr type doesn't imply the resource mode, so data sources and managed resources with the same type name could shim incorrectly.
This commit is contained in:
parent
e8096e9c8b
commit
041ed67e46
|
@ -49,7 +49,7 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
|
||||||
resType := res.Addr.Type
|
resType := res.Addr.Type
|
||||||
providerType := res.ProviderConfig.ProviderConfig.Type
|
providerType := res.ProviderConfig.ProviderConfig.Type
|
||||||
|
|
||||||
resource := getResource(providers, providerType, resType)
|
resource := getResource(providers, providerType, res.Addr)
|
||||||
|
|
||||||
for key, i := range res.Instances {
|
for key, i := range res.Instances {
|
||||||
flatmap, err := shimmedAttributes(i.Current, resource)
|
flatmap, err := shimmedAttributes(i.Current, resource)
|
||||||
|
@ -116,7 +116,7 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResource(providers map[string]terraform.ResourceProvider, providerName, resourceType string) *schema.Resource {
|
func getResource(providers map[string]terraform.ResourceProvider, providerName string, addr addrs.Resource) *schema.Resource {
|
||||||
p := providers[providerName]
|
p := providers[providerName]
|
||||||
if p == nil {
|
if p == nil {
|
||||||
panic(fmt.Sprintf("provider %q not found in test step", providerName))
|
panic(fmt.Sprintf("provider %q not found in test step", providerName))
|
||||||
|
@ -125,23 +125,24 @@ func getResource(providers map[string]terraform.ResourceProvider, providerName,
|
||||||
// this is only for tests, so should only see schema.Providers
|
// this is only for tests, so should only see schema.Providers
|
||||||
provider := p.(*schema.Provider)
|
provider := p.(*schema.Provider)
|
||||||
|
|
||||||
resource := provider.ResourcesMap[resourceType]
|
switch addr.Mode {
|
||||||
if resource != nil {
|
case addrs.ManagedResourceMode:
|
||||||
return resource
|
resource := provider.ResourcesMap[addr.Type]
|
||||||
|
if resource != nil {
|
||||||
|
return resource
|
||||||
|
}
|
||||||
|
case addrs.DataResourceMode:
|
||||||
|
resource := provider.DataSourcesMap[addr.Type]
|
||||||
|
if resource != nil {
|
||||||
|
return resource
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource = provider.DataSourcesMap[resourceType]
|
panic(fmt.Sprintf("resource %s not found in test step", addr.Type))
|
||||||
if resource != nil {
|
|
||||||
return resource
|
|
||||||
}
|
|
||||||
|
|
||||||
panic(fmt.Sprintf("resource %s not found in test step", resourceType))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func shimmedAttributes(instance *states.ResourceInstanceObjectSrc, res *schema.Resource) (map[string]string, error) {
|
func shimmedAttributes(instance *states.ResourceInstanceObjectSrc, res *schema.Resource) (map[string]string, error) {
|
||||||
flatmap := instance.AttrsFlat
|
flatmap := instance.AttrsFlat
|
||||||
|
|
||||||
if flatmap != nil {
|
if flatmap != nil {
|
||||||
return flatmap, nil
|
return flatmap, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue