Make `state mv` use the new `states.Filter`
This commit is contained in:
parent
5e11de460a
commit
536c2fe6f1
|
@ -5,7 +5,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/states"
|
"github.com/hashicorp/terraform/states"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -141,43 +140,18 @@ func (c *StateMvCommand) Run(args []string) int {
|
||||||
// addableResult takes the result from a filter operation and returns what to
|
// addableResult takes the result from a filter operation and returns what to
|
||||||
// call State.Add with. The reason we do this is because in the module case
|
// call State.Add with. The reason we do this is because in the module case
|
||||||
// we must add the list of all modules returned versus just the root module.
|
// we must add the list of all modules returned versus just the root module.
|
||||||
func (c *StateMvCommand) addableResult(results []*terraform.StateFilterResult) interface{} {
|
func (c *StateMvCommand) addableResult(results []*states.FilterResult) interface{} {
|
||||||
switch v := results[0].Value.(type) {
|
switch v := results[0].Value.(type) {
|
||||||
case *terraform.ModuleState:
|
case *states.Module:
|
||||||
// If a module state then we should add the full list of modules
|
// If a state module then we should add the full list of modules
|
||||||
result := []*terraform.ModuleState{v}
|
result := []*states.Module{v}
|
||||||
if len(results) > 1 {
|
if len(results) > 1 {
|
||||||
for _, r := range results[1:] {
|
for _, r := range results[1:] {
|
||||||
if ms, ok := r.Value.(*terraform.ModuleState); ok {
|
if ms, ok := r.Value.(*states.Module); ok {
|
||||||
result = append(result, ms)
|
result = append(result, ms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
case *terraform.ResourceState:
|
|
||||||
// If a resource state with more than one result, it has a multi-count
|
|
||||||
// and we need to add all of them.
|
|
||||||
result := []*terraform.ResourceState{v}
|
|
||||||
if len(results) > 1 {
|
|
||||||
for _, r := range results[1:] {
|
|
||||||
rs, ok := r.Value.(*terraform.ResourceState)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if rs.Type == v.Type {
|
|
||||||
result = append(result, rs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we only have one item, add it directly
|
|
||||||
if len(result) == 1 {
|
|
||||||
return result[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue