command: nil-check for instance state when showing state
This commit is contained in:
parent
879cb2f8e6
commit
edbdad8fdb
|
@ -92,7 +92,10 @@ func formatStateModuleExpand(
|
||||||
|
|
||||||
rs := m.Resources[k]
|
rs := m.Resources[k]
|
||||||
is := rs.Primary
|
is := rs.Primary
|
||||||
id := is.ID
|
var id string
|
||||||
|
if is != nil {
|
||||||
|
id = is.ID
|
||||||
|
}
|
||||||
if id == "" {
|
if id == "" {
|
||||||
id = "<not created>"
|
id = "<not created>"
|
||||||
}
|
}
|
||||||
|
@ -105,22 +108,24 @@ func formatStateModuleExpand(
|
||||||
buf.WriteString(fmt.Sprintf("%s:%s\n", name, taintStr))
|
buf.WriteString(fmt.Sprintf("%s:%s\n", name, taintStr))
|
||||||
buf.WriteString(fmt.Sprintf(" id = %s\n", id))
|
buf.WriteString(fmt.Sprintf(" id = %s\n", id))
|
||||||
|
|
||||||
// Sort the attributes
|
if is != nil {
|
||||||
attrKeys := make([]string, 0, len(is.Attributes))
|
// Sort the attributes
|
||||||
for ak, _ := range is.Attributes {
|
attrKeys := make([]string, 0, len(is.Attributes))
|
||||||
// Skip the id attribute since we just show the id directly
|
for ak, _ := range is.Attributes {
|
||||||
if ak == "id" {
|
// Skip the id attribute since we just show the id directly
|
||||||
continue
|
if ak == "id" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
attrKeys = append(attrKeys, ak)
|
||||||
}
|
}
|
||||||
|
sort.Strings(attrKeys)
|
||||||
|
|
||||||
attrKeys = append(attrKeys, ak)
|
// Output each attribute
|
||||||
}
|
for _, ak := range attrKeys {
|
||||||
sort.Strings(attrKeys)
|
av := is.Attributes[ak]
|
||||||
|
buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av))
|
||||||
// Output each attribute
|
}
|
||||||
for _, ak := range attrKeys {
|
|
||||||
av := is.Attributes[ak]
|
|
||||||
buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue