From c2f3f0594dd5f358df0dff51e0e0b2f2e1689705 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Feb 2015 11:47:53 -0800 Subject: [PATCH] terraform: sort dependencies of resource state [GH-928] --- CHANGELOG.md | 1 + terraform/state.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e17dc06..c953965f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ BUG FIXES: * core: Fix crash that could occur when there are exactly zero providers installed on a system. [GH-786] * core: JSON TF configurations can configure provisioners. [GH-807] + * core: Sort `depends_on` in state to prevent unnecessary file changes. [GH-928] * command/apply: Won't try to initialize modules in some cases when no arguments are given. [GH-780] * command/apply: Fix regression where user variables weren't asked [GH-736] diff --git a/terraform/state.go b/terraform/state.go index 7535d2a47..dea8fe961 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -156,6 +156,11 @@ func (s *State) prune() { // sort sorts the modules func (s *State) sort() { sort.Sort(moduleStateSort(s.Modules)) + + // Allow modules to be sorted + for _, m := range s.Modules { + m.sort() + } } func (s *State) GoString() string { @@ -347,6 +352,12 @@ func (m *ModuleState) prune() { } } +func (m *ModuleState) sort() { + for _, v := range m.Resources { + v.sort() + } +} + func (m *ModuleState) GoString() string { return fmt.Sprintf("*%#v", *m) } @@ -515,6 +526,10 @@ func (r *ResourceState) prune() { r.Tainted = r.Tainted[:n] } +func (r *ResourceState) sort() { + sort.Strings(r.Dependencies) +} + func (s *ResourceState) GoString() string { return fmt.Sprintf("*%#v", *s) }