maintain private data through provider ACC tests
The private->meta data was lost in the test harness.
This commit is contained in:
parent
49fee6ba78
commit
4cb6ebe22c
|
@ -1,6 +1,7 @@
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/addrs"
|
"github.com/hashicorp/terraform/addrs"
|
||||||
|
@ -52,20 +53,33 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
|
||||||
resource := getResource(providers, providerType, res.Addr)
|
resource := getResource(providers, providerType, res.Addr)
|
||||||
|
|
||||||
for key, i := range res.Instances {
|
for key, i := range res.Instances {
|
||||||
|
resState := &terraform.ResourceState{
|
||||||
|
Type: resType,
|
||||||
|
Provider: res.ProviderConfig.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// We should always have a Current instance here, but be safe about checking.
|
||||||
|
if i.Current != nil {
|
||||||
flatmap, err := shimmedAttributes(i.Current, resource)
|
flatmap, err := shimmedAttributes(i.Current, resource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error decoding state for %q: %s", resType, err)
|
return nil, fmt.Errorf("error decoding state for %q: %s", resType, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resState := &terraform.ResourceState{
|
var meta map[string]interface{}
|
||||||
Type: resType,
|
if i.Current.Private != nil {
|
||||||
Primary: &terraform.InstanceState{
|
err := json.Unmarshal(i.Current.Private, &meta)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resState.Primary = &terraform.InstanceState{
|
||||||
ID: flatmap["id"],
|
ID: flatmap["id"],
|
||||||
Attributes: flatmap,
|
Attributes: flatmap,
|
||||||
Tainted: i.Current.Status == states.ObjectTainted,
|
Tainted: i.Current.Status == states.ObjectTainted,
|
||||||
},
|
Meta: meta,
|
||||||
Provider: res.ProviderConfig.String(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i.Current.SchemaVersion != 0 {
|
if i.Current.SchemaVersion != 0 {
|
||||||
resState.Primary.Meta = map[string]interface{}{
|
resState.Primary.Meta = map[string]interface{}{
|
||||||
"schema_version": i.Current.SchemaVersion,
|
"schema_version": i.Current.SchemaVersion,
|
||||||
|
@ -89,6 +103,7 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
|
||||||
}
|
}
|
||||||
|
|
||||||
mod.Resources[res.Addr.String()+idx] = resState
|
mod.Resources[res.Addr.String()+idx] = resState
|
||||||
|
}
|
||||||
|
|
||||||
// add any deposed instances
|
// add any deposed instances
|
||||||
for _, dep := range i.Deposed {
|
for _, dep := range i.Deposed {
|
||||||
|
@ -97,10 +112,19 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
|
||||||
return nil, fmt.Errorf("error decoding deposed state for %q: %s", resType, err)
|
return nil, fmt.Errorf("error decoding deposed state for %q: %s", resType, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var meta map[string]interface{}
|
||||||
|
if dep.Private != nil {
|
||||||
|
err := json.Unmarshal(dep.Private, &meta)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deposed := &terraform.InstanceState{
|
deposed := &terraform.InstanceState{
|
||||||
ID: flatmap["id"],
|
ID: flatmap["id"],
|
||||||
Attributes: flatmap,
|
Attributes: flatmap,
|
||||||
Tainted: dep.Status == states.ObjectTainted,
|
Tainted: dep.Status == states.ObjectTainted,
|
||||||
|
Meta: meta,
|
||||||
}
|
}
|
||||||
if dep.SchemaVersion != 0 {
|
if dep.SchemaVersion != 0 {
|
||||||
deposed.Meta = map[string]interface{}{
|
deposed.Meta = map[string]interface{}{
|
||||||
|
|
Loading…
Reference in New Issue