• Martin Atkins's avatar
    command: Fix various issues in the "terraform state ..." subcommands · c39905e1
    Martin Atkins authored
    In earlier refactoring we updated these commands to support the new
    address and state types, but attempted to partially retain the old-style
    "StateFilter" abstraction that originally lived in the Terraform package,
    even though that was no longer being used for any other functionality.
    
    Unfortunately the adaptation of the existing filtering to the new types
    wasn't exact and so these commands ended up having a few bugs that were
    not covered by the existing tests.
    
    Since the old StateFilter behavior was the source of various misbehavior
    anyway, here it's removed altogether and replaced with some simpler
    functions in the state_meta.go file that are tailored to the use-cases of
    these sub-commands.
    
    As well as just generally behaving more consistently with the other
    parts of Terraform that use the new resource address types, this commit
    fixes the following bugs:
    
    - A resource address of aws_instance.foo would previously match an
      resource of that type and name in any module, which disagreed with the
      expected interpretation elsewhere of meaning a single resource in the
      root module.
    
    - The "terraform state mv" command was not supporting moves from a single
      resource address to an indexed address and vice-versa, because the old
      logic didn't need to make that distinction while they are two separate
      address types in the new logic. Now we allow resources that do not have
      count/for_each to be treated as if they are instances for the purposes
      of this command, which is a better match for likely user intent and for
      the old behavior.
    
    Finally, we also clean up a little some of the usage output from these
    commands, which hasn't been updated for some time and so had both some
    stale information and some inaccurate terminology.
    c39905e1