Merge pull request #3569 from hashicorp/b-meta-diffs-should-bump-serial

core: state metadata difference should bump serial
This commit is contained in:
Paul Hinze 2015-10-20 13:29:12 -05:00
commit 68e0133da0
2 changed files with 87 additions and 0 deletions

View File

@ -965,6 +965,21 @@ func (s *InstanceState) Equal(other *InstanceState) bool {
} }
} }
// Meta must be equal
if len(s.Meta) != len(other.Meta) {
return false
}
for k, v := range s.Meta {
otherV, ok := other.Meta[k]
if !ok {
return false
}
if v != otherV {
return false
}
}
return true return true
} }

View File

@ -188,6 +188,43 @@ func TestStateEqual(t *testing.T) {
}, },
}, },
}, },
// Meta differs
{
false,
&State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"test_instance.foo": &ResourceState{
Primary: &InstanceState{
Meta: map[string]string{
"schema_version": "1",
},
},
},
},
},
},
},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"test_instance.foo": &ResourceState{
Primary: &InstanceState{
Meta: map[string]string{
"schema_version": "2",
},
},
},
},
},
},
},
},
} }
for i, tc := range cases { for i, tc := range cases {
@ -224,6 +261,41 @@ func TestStateIncrementSerialMaybe(t *testing.T) {
}, },
1, 1,
}, },
"S2 is different, but only via Instance Metadata": {
&State{
Serial: 3,
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"test_instance.foo": &ResourceState{
Primary: &InstanceState{
Meta: map[string]string{},
},
},
},
},
},
},
&State{
Serial: 3,
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"test_instance.foo": &ResourceState{
Primary: &InstanceState{
Meta: map[string]string{
"schema_version": "1",
},
},
},
},
},
},
},
4,
},
"S1 serial is higher": { "S1 serial is higher": {
&State{Serial: 5}, &State{Serial: 5},
&State{ &State{