terraform: fixing all the panics
This commit is contained in:
parent
f117e33c9d
commit
81abdcafdc
|
@ -381,8 +381,11 @@ func (c *Context) computeResourceVariable(
|
||||||
v.FullKey())
|
v.FullKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
attr, ok := r.Primary.Attributes[v.Field]
|
if r.Primary == nil {
|
||||||
if ok {
|
goto MISSING
|
||||||
|
}
|
||||||
|
|
||||||
|
if attr, ok := r.Primary.Attributes[v.Field]; ok {
|
||||||
return attr, nil
|
return attr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +393,7 @@ func (c *Context) computeResourceVariable(
|
||||||
// and see if anything along the way is a computed set. i.e. if
|
// and see if anything along the way is a computed set. i.e. if
|
||||||
// we have "foo.0.bar" as the field, check to see if "foo" is
|
// we have "foo.0.bar" as the field, check to see if "foo" is
|
||||||
// a computed list. If so, then the whole thing is computed.
|
// a computed list. If so, then the whole thing is computed.
|
||||||
parts := strings.Split(v.Field, ".")
|
if parts := strings.Split(v.Field, "."); len(parts) > 1 {
|
||||||
if len(parts) > 1 {
|
|
||||||
for i := 1; i < len(parts); i++ {
|
for i := 1; i < len(parts); i++ {
|
||||||
key := fmt.Sprintf("%s.#", strings.Join(parts[:i], "."))
|
key := fmt.Sprintf("%s.#", strings.Join(parts[:i], "."))
|
||||||
if attr, ok := r.Primary.Attributes[key]; ok {
|
if attr, ok := r.Primary.Attributes[key]; ok {
|
||||||
|
@ -400,6 +402,7 @@ func (c *Context) computeResourceVariable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MISSING:
|
||||||
return "", fmt.Errorf(
|
return "", fmt.Errorf(
|
||||||
"Resource '%s' does not have attribute '%s' "+
|
"Resource '%s' does not have attribute '%s' "+
|
||||||
"for variable '%s'",
|
"for variable '%s'",
|
||||||
|
@ -448,6 +451,10 @@ func (c *Context) computeResourceMultiVariable(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.Primary == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
attr, ok := r.Primary.Attributes[v.Field]
|
attr, ok := r.Primary.Attributes[v.Field]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
@ -854,7 +861,7 @@ func (c *Context) planDestroyWalkFn(result *Plan) depgraph.WalkFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := rn.Resource
|
r := rn.Resource
|
||||||
if r.State.Primary.ID != "" {
|
if r.State.Primary != nil && r.State.Primary.ID != "" {
|
||||||
log.Printf("[DEBUG] %s: Making for destroy", r.Id)
|
log.Printf("[DEBUG] %s: Making for destroy", r.Id)
|
||||||
|
|
||||||
l.Lock()
|
l.Lock()
|
||||||
|
@ -870,7 +877,7 @@ func (c *Context) planDestroyWalkFn(result *Plan) depgraph.WalkFunc {
|
||||||
|
|
||||||
func (c *Context) refreshWalkFn() depgraph.WalkFunc {
|
func (c *Context) refreshWalkFn() depgraph.WalkFunc {
|
||||||
cb := func(r *Resource) error {
|
cb := func(r *Resource) error {
|
||||||
if r.State.Primary.ID == "" {
|
if r.State.Primary == nil || r.State.Primary.ID == "" {
|
||||||
log.Printf("[DEBUG] %s: Not refreshing, ID is empty", r.Id)
|
log.Printf("[DEBUG] %s: Not refreshing, ID is empty", r.Id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -899,7 +906,7 @@ func (c *Context) refreshWalkFn() depgraph.WalkFunc {
|
||||||
|
|
||||||
// TODO: Handle other moduels
|
// TODO: Handle other moduels
|
||||||
mod := c.state.RootModule()
|
mod := c.state.RootModule()
|
||||||
if rs.Primary.ID == "" {
|
if len(rs.Tainted) == 0 && (rs.Primary == nil || rs.Primary.ID == "") {
|
||||||
delete(mod.Resources, r.Id)
|
delete(mod.Resources, r.Id)
|
||||||
} else {
|
} else {
|
||||||
mod.Resources[r.Id] = rs
|
mod.Resources[r.Id] = rs
|
||||||
|
|
|
@ -1543,6 +1543,7 @@ func TestContextPlan_countDecreaseToOne(t *testing.T) {
|
||||||
s := &State{
|
s := &State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
&ModuleState{
|
&ModuleState{
|
||||||
|
Path: rootModulePath,
|
||||||
Resources: map[string]*ResourceState{
|
Resources: map[string]*ResourceState{
|
||||||
"aws_instance.foo.0": &ResourceState{
|
"aws_instance.foo.0": &ResourceState{
|
||||||
Type: "aws_instance",
|
Type: "aws_instance",
|
||||||
|
|
|
@ -189,13 +189,12 @@ func graphAddConfigResources(
|
||||||
}
|
}
|
||||||
|
|
||||||
tainted := false
|
tainted := false
|
||||||
var mod *ModuleState
|
|
||||||
var state *ResourceState
|
var state *ResourceState
|
||||||
|
|
||||||
if s != nil {
|
|
||||||
// TODO: Handle non-root modules
|
// TODO: Handle non-root modules
|
||||||
mod = s.RootModule()
|
mod := s.ModuleByPath(rootModulePath)
|
||||||
|
|
||||||
|
if s != nil && mod != nil {
|
||||||
// Lookup the resource state
|
// Lookup the resource state
|
||||||
state = mod.Resources[name]
|
state = mod.Resources[name]
|
||||||
if state == nil {
|
if state == nil {
|
||||||
|
@ -511,7 +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) {
|
||||||
// TODO: Handle other modules
|
// TODO: Handle other modules
|
||||||
mod := s.RootModule()
|
mod := s.ModuleByPath(rootModulePath)
|
||||||
|
if mod == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, k := range mod.Orphans(c) {
|
for _, k := range mod.Orphans(c) {
|
||||||
rs := mod.Resources[k]
|
rs := mod.Resources[k]
|
||||||
noun := &depgraph.Noun{
|
noun := &depgraph.Noun{
|
||||||
|
|
|
@ -42,6 +42,9 @@ func (s *State) ModuleByPath(path []string) *ModuleState {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, mod := range s.Modules {
|
for _, mod := range s.Modules {
|
||||||
|
if mod.Path == nil {
|
||||||
|
panic("missing module path")
|
||||||
|
}
|
||||||
if reflect.DeepEqual(mod.Path, path) {
|
if reflect.DeepEqual(mod.Path, path) {
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue