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

View File

@ -79,7 +79,7 @@ func graphDotAddResources(buf *bytes.Buffer, g *depgraph.Graph) {
// green = create. Destroy is in the next section.
var color, fillColor string
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"
fillColor = "#FFFF94"
} else {