Skip to content

Commit

Permalink
Merge pull request #3569 from hashicorp/b-meta-diffs-should-bump-serial
Browse files Browse the repository at this point in the history
core: state metadata difference should bump serial
  • Loading branch information
phinze committed Oct 20, 2015
2 parents 15a36d0 + fca44bd commit 68e0133
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
15 changes: 15 additions & 0 deletions terraform/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
72 changes: 72 additions & 0 deletions terraform/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -224,6 +261,41 @@ func TestStateIncrementSerialMaybe(t *testing.T) {
},
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": {
&State{Serial: 5},
&State{
Expand Down

0 comments on commit 68e0133

Please sign in to comment.