terraform: porting to new state

This commit is contained in:
Armon Dadgar 2014-09-16 12:34:21 -07:00
parent 04a2b5288b
commit 3404277f31
2 changed files with 21 additions and 13 deletions

View File

@ -188,30 +188,36 @@ func graphAddConfigResources(
index = i index = i
} }
// Determine if this resource is tainted
tainted := false tainted := false
if s != nil && s.Tainted != nil { var mod *ModuleState
_, tainted = s.Tainted[r.Id()]
}
var state *ResourceState var state *ResourceState
if s != nil {
state = s.Resources[name]
if s != nil {
// TODO: Handle non-root modules
mod = s.RootModule()
// Lookup the resource state
state = mod.Resources[name]
if state == nil { if state == nil {
if r.Count == 1 { if r.Count == 1 {
// If the count is one, check the state for ".0" // If the count is one, check the state for ".0"
// appended, which might exist if we go from // appended, which might exist if we go from
// count > 1 to count == 1. // count > 1 to count == 1.
state = s.Resources[r.Id()+".0"] state = mod.Resources[r.Id()+".0"]
} else if i == 0 { } else if i == 0 {
// If count is greater than one, check for state // If count is greater than one, check for state
// with just the ID, which might exist if we go // with just the ID, which might exist if we go
// from count == 1 to count > 1 // from count == 1 to count > 1
state = s.Resources[r.Id()] state = mod.Resources[r.Id()]
} }
} }
// Determine if this resource is tainted
if state != nil && len(state.Tainted) > 0 {
tainted = true
} }
}
if state == nil { if state == nil {
state = &ResourceState{ state = &ResourceState{
Type: r.Type, Type: r.Type,
@ -382,7 +388,7 @@ func graphAddDiff(g *depgraph.Graph, d *Diff) error {
} }
rn2 := n2.Meta.(*GraphNodeResource) rn2 := n2.Meta.(*GraphNodeResource)
if rn2.Resource.State.ID == dep.ID { if rn2.Resource.Id == dep {
n2.Deps = append(n2.Deps, &depgraph.Dependency{ n2.Deps = append(n2.Deps, &depgraph.Dependency{
Name: n.Name, Name: n.Name,
Source: n2, Source: n2,
@ -504,8 +510,10 @@ func graphAddMissingResourceProviders(
// graphAddOrphans adds the orphans to the graph. // graphAddOrphans adds the orphans to the graph.
func graphAddOrphans(g *depgraph.Graph, c *config.Config, s *State) { func graphAddOrphans(g *depgraph.Graph, c *config.Config, s *State) {
for _, k := range s.Orphans(c) { // TODO: Handle other modules
rs := s.Resources[k] mod := s.RootModule()
for _, k := range mod.Orphans(c) {
rs := mod.Resources[k]
noun := &depgraph.Noun{ noun := &depgraph.Noun{
Name: k, Name: k,
Meta: &GraphNodeResource{ Meta: &GraphNodeResource{

View File

@ -79,7 +79,7 @@ func graphDotAddResources(buf *bytes.Buffer, g *depgraph.Graph) {
// green = create. Destroy is in the next section. // green = create. Destroy is in the next section.
var color, fillColor string var color, fillColor string
if rn.Resource.Diff != nil && !rn.Resource.Diff.Empty() { if rn.Resource.Diff != nil && !rn.Resource.Diff.Empty() {
if rn.Resource.State != nil && rn.Resource.State.ID != "" { if rn.Resource.State != nil && rn.Resource.State.Primary.ID != "" {
color = "#FFFF00" color = "#FFFF00"
fillColor = "#FFFF94" fillColor = "#FFFF94"
} else { } else {