mirror of
https://github.com/hashicorp/terraform.git
synced 2026-02-17 09:52:49 -05:00
This introduces the terraform state list command to list the resources within a state. This is the first of many state management commands to come into 0.7. This is the first command of many to come that is considered a "plumbing" command within Terraform (see "plumbing vs porcelain": http://git.661346.n2.nabble.com/what-are-plumbing-and-porcelain-td2190639.html). As such, this PR also introduces a bunch of groundwork to support plumbing commands. The main changes: - Main command output is changed to split "common" and "uncommon" commands. - mitchellh/cli is updated to support nested subcommands, since terraform state list is a nested subcommand. - terraform.StateFilter is introduced as a way in core to filter/search the state files. This is very basic currently but I expect to make it more advanced as time goes on. - terraform state list command is introduced to list resources in a state. This can take a series of arguments to filter this down. Known issues, or things that aren't done in this PR on purpose: - Unit tests for terraform state list are on the way. Unit tests for the core changes are all there.
40 lines
1 KiB
Go
40 lines
1 KiB
Go
package command
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
// StateCommand is a Command implementation that just shows help for
|
|
// the subcommands nested below it.
|
|
type StateCommand struct {
|
|
Meta
|
|
}
|
|
|
|
func (c *StateCommand) Run(args []string) int {
|
|
return cli.RunResultHelp
|
|
}
|
|
|
|
func (c *StateCommand) Help() string {
|
|
helpText := `
|
|
Usage: terraform state <subcommand> [options] [args]
|
|
|
|
This command has subcommands for advanced state management.
|
|
|
|
These subcommands can be used to slice and dice the Terraform state.
|
|
This is sometimes necessary in advanced cases. For your safety, all
|
|
state management commands that modify the state create a timestamped
|
|
backup of the state prior to making modifications.
|
|
|
|
The structure and output of the commands is specifically tailored to work
|
|
well with the common Unix utilities such as grep, awk, etc. We recommend
|
|
using those tools to perform more advanced state tasks.
|
|
|
|
`
|
|
return strings.TrimSpace(helpText)
|
|
}
|
|
|
|
func (c *StateCommand) Synopsis() string {
|
|
return "Advanced state management"
|
|
}
|