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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
|
@ -52,43 +53,57 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
|
|||
resource := getResource(providers, providerType, res.Addr)
|
||||
|
||||
for key, i := range res.Instances {
|
||||
flatmap, err := shimmedAttributes(i.Current, resource)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding state for %q: %s", resType, err)
|
||||
resState := &terraform.ResourceState{
|
||||
Type: resType,
|
||||
Provider: res.ProviderConfig.String(),
|
||||
}
|
||||
|
||||
resState := &terraform.ResourceState{
|
||||
Type: resType,
|
||||
Primary: &terraform.InstanceState{
|
||||
// We should always have a Current instance here, but be safe about checking.
|
||||
if i.Current != nil {
|
||||
flatmap, err := shimmedAttributes(i.Current, resource)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error decoding state for %q: %s", resType, err)
|
||||
}
|
||||
|
||||
var meta map[string]interface{}
|
||||
if i.Current.Private != nil {
|
||||
err := json.Unmarshal(i.Current.Private, &meta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resState.Primary = &terraform.InstanceState{
|
||||
ID: flatmap["id"],
|
||||
Attributes: flatmap,
|
||||
Tainted: i.Current.Status == states.ObjectTainted,
|
||||
},
|
||||
Provider: res.ProviderConfig.String(),
|
||||
}
|
||||
if i.Current.SchemaVersion != 0 {
|
||||
resState.Primary.Meta = map[string]interface{}{
|
||||
"schema_version": i.Current.SchemaVersion,
|
||||
Meta: meta,
|
||||
}
|
||||
}
|
||||
|
||||
for _, dep := range i.Current.Dependencies {
|
||||
resState.Dependencies = append(resState.Dependencies, dep.String())
|
||||
}
|
||||
|
||||
// convert the indexes to the old style flapmap indexes
|
||||
idx := ""
|
||||
switch key.(type) {
|
||||
case addrs.IntKey:
|
||||
// don't add numeric index values to resources with a count of 0
|
||||
if len(res.Instances) > 1 {
|
||||
idx = fmt.Sprintf(".%d", key)
|
||||
if i.Current.SchemaVersion != 0 {
|
||||
resState.Primary.Meta = map[string]interface{}{
|
||||
"schema_version": i.Current.SchemaVersion,
|
||||
}
|
||||
}
|
||||
case addrs.StringKey:
|
||||
idx = "." + key.String()
|
||||
}
|
||||
|
||||
mod.Resources[res.Addr.String()+idx] = resState
|
||||
for _, dep := range i.Current.Dependencies {
|
||||
resState.Dependencies = append(resState.Dependencies, dep.String())
|
||||
}
|
||||
|
||||
// convert the indexes to the old style flapmap indexes
|
||||
idx := ""
|
||||
switch key.(type) {
|
||||
case addrs.IntKey:
|
||||
// don't add numeric index values to resources with a count of 0
|
||||
if len(res.Instances) > 1 {
|
||||
idx = fmt.Sprintf(".%d", key)
|
||||
}
|
||||
case addrs.StringKey:
|
||||
idx = "." + key.String()
|
||||
}
|
||||
|
||||
mod.Resources[res.Addr.String()+idx] = resState
|
||||
}
|
||||
|
||||
// add any deposed instances
|
||||
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)
|
||||
}
|
||||
|
||||
var meta map[string]interface{}
|
||||
if dep.Private != nil {
|
||||
err := json.Unmarshal(dep.Private, &meta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
deposed := &terraform.InstanceState{
|
||||
ID: flatmap["id"],
|
||||
Attributes: flatmap,
|
||||
Tainted: dep.Status == states.ObjectTainted,
|
||||
Meta: meta,
|
||||
}
|
||||
if dep.SchemaVersion != 0 {
|
||||
deposed.Meta = map[string]interface{}{
|
||||
|
|
Loading…
Reference in New Issue