Update newly added code to work with the updated taint semantics
This commit is contained in:
parent
d97b24e3c1
commit
5af1afd64e
|
@ -133,11 +133,6 @@ func stateAddFunc_Resource_Resource(s *State, fromAddr, addr *ResourceAddress, r
|
|||
}
|
||||
}
|
||||
|
||||
// Move all tainted
|
||||
if len(src.Tainted) > 0 {
|
||||
resource.Tainted = src.Tainted
|
||||
}
|
||||
|
||||
// Move all deposed
|
||||
if len(src.Deposed) > 0 {
|
||||
resource.Deposed = src.Deposed
|
||||
|
@ -281,23 +276,12 @@ func stateAddInitAddr(s *State, addr *ResourceAddress) (interface{}, bool) {
|
|||
exists = true
|
||||
instance := &InstanceState{}
|
||||
switch addr.InstanceType {
|
||||
case TypePrimary:
|
||||
case TypePrimary, TypeTainted:
|
||||
if v := resource.Primary; v != nil {
|
||||
instance = resource.Primary
|
||||
} else {
|
||||
exists = false
|
||||
}
|
||||
case TypeTainted:
|
||||
idx := addr.Index
|
||||
if addr.Index < 0 {
|
||||
idx = 0
|
||||
}
|
||||
if len(resource.Tainted) > idx {
|
||||
instance = resource.Tainted[idx]
|
||||
} else {
|
||||
resource.Tainted = append(resource.Tainted, instance)
|
||||
exists = false
|
||||
}
|
||||
case TypeDeposed:
|
||||
idx := addr.Index
|
||||
if addr.Index < 0 {
|
||||
|
|
|
@ -256,16 +256,15 @@ func TestStateAdd(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
"ResourceState w/ tainted => Resource Addr (new)": {
|
||||
"ResourceState tainted => Resource Addr (new)": {
|
||||
false,
|
||||
"aws_instance.bar",
|
||||
"aws_instance.foo",
|
||||
&ResourceState{
|
||||
Type: "test_instance",
|
||||
Tainted: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
Tainted: true,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -276,12 +275,10 @@ func TestStateAdd(t *testing.T) {
|
|||
Path: []string{"root"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": &ResourceState{
|
||||
Type: "test_instance",
|
||||
Primary: &InstanceState{},
|
||||
Tainted: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
Type: "test_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
Tainted: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/config"
|
||||
)
|
||||
|
||||
// The format byte is prefixed into the state file format so that we have
|
||||
|
@ -342,16 +343,14 @@ func (old *StateV0) upgrade() (*State, error) {
|
|||
root.Resources[id] = newRs
|
||||
|
||||
// Migrate to an instance state
|
||||
instance := &InstanceState{
|
||||
newRs.Primary = &InstanceState{
|
||||
ID: rs.ID,
|
||||
Attributes: rs.Attributes,
|
||||
}
|
||||
|
||||
// Check if this is the primary or tainted instance
|
||||
// Check if old resource was tainted
|
||||
if _, ok := old.Tainted[id]; ok {
|
||||
newRs.Tainted = append(newRs.Tainted, instance)
|
||||
} else {
|
||||
newRs.Primary = instance
|
||||
newRs.Primary.Tainted = true
|
||||
}
|
||||
|
||||
// Warn if the resource uses Extra, as there is
|
||||
|
|
|
@ -235,18 +235,6 @@ func (old *resourceStateV1) upgrade() (*ResourceState, error) {
|
|||
return nil, fmt.Errorf("Error upgrading ResourceState V1: %v", err)
|
||||
}
|
||||
|
||||
tainted := make([]*InstanceState, len(old.Tainted))
|
||||
for i, v := range old.Tainted {
|
||||
upgraded, err := v.upgrade()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error upgrading ResourceState V1: %v", err)
|
||||
}
|
||||
tainted[i] = upgraded
|
||||
}
|
||||
if len(tainted) == 0 {
|
||||
tainted = nil
|
||||
}
|
||||
|
||||
deposed := make([]*InstanceState, len(old.Deposed))
|
||||
for i, v := range old.Deposed {
|
||||
upgraded, err := v.upgrade()
|
||||
|
@ -263,7 +251,6 @@ func (old *resourceStateV1) upgrade() (*ResourceState, error) {
|
|||
Type: old.Type,
|
||||
Dependencies: dependencies.([]string),
|
||||
Primary: primary,
|
||||
Tainted: tainted,
|
||||
Deposed: deposed,
|
||||
Provider: old.Provider,
|
||||
}, nil
|
||||
|
|
Loading…
Reference in New Issue