Merge pull request #19132 from hashicorp/f-state-mv
Make `state mv` use the new `states.Filter`
This commit is contained in:
commit
c7df8bef39
|
@ -5,7 +5,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/states"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"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
|
||||
// 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.
|
||||
func (c *StateMvCommand) addableResult(results []*terraform.StateFilterResult) interface{} {
|
||||
func (c *StateMvCommand) addableResult(results []*states.FilterResult) interface{} {
|
||||
switch v := results[0].Value.(type) {
|
||||
case *terraform.ModuleState:
|
||||
// If a module state then we should add the full list of modules
|
||||
result := []*terraform.ModuleState{v}
|
||||
case *states.Module:
|
||||
// If a state module then we should add the full list of modules
|
||||
result := []*states.Module{v}
|
||||
if len(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue