Remove support for the -module-depth flag

# Conflicts:
#	backend/backend.go
This commit is contained in:
Sander van Harmelen 2018-11-02 17:58:38 +01:00
parent 47d5d62bdb
commit 178ec8f7b4
11 changed files with 15 additions and 113 deletions

View File

@ -31,7 +31,7 @@ func (c *GraphCommand) Run(args []string) int {
}
cmdFlags := flag.NewFlagSet("graph", flag.ContinueOnError)
c.addModuleDepthFlag(cmdFlags, &moduleDepth)
cmdFlags.IntVar(&moduleDepth, "module-depth", -1, "module-depth")
cmdFlags.BoolVar(&verbose, "verbose", false, "verbose")
cmdFlags.BoolVar(&drawCycles, "draw-cycles", false, "draw-cycles")
cmdFlags.StringVar(&graphTypeStr, "type", "", "type")
@ -181,13 +181,16 @@ Usage: terraform graph [options] [DIR]
Options:
-draw-cycles Highlight any cycles in the graph with colored edges.
This helps when diagnosing cycle errors.
-draw-cycles Highlight any cycles in the graph with colored edges.
This helps when diagnosing cycle errors.
-no-color If specified, output won't contain any color.
-module-depth=n Specifies the depth of modules to show in the output.
By default this is -1, which will expand all.
-type=plan Type of graph to output. Can be: plan, plan-destroy, apply,
validate, input, refresh.
-no-color If specified, output won't contain any color.
-type=plan Type of graph to output. Can be: plan, plan-destroy, apply,
validate, input, refresh.
`

View File

@ -513,25 +513,6 @@ func (m *Meta) showDiagnostics(vals ...interface{}) {
}
}
const (
// ModuleDepthDefault is the default value for
// module depth, which can be overridden by flag
// or env var
ModuleDepthDefault = -1
// ModuleDepthEnvVar is the name of the environment variable that can be used to set module depth.
ModuleDepthEnvVar = "TF_MODULE_DEPTH"
)
func (m *Meta) addModuleDepthFlag(flags *flag.FlagSet, moduleDepth *int) {
flags.IntVar(moduleDepth, "module-depth", ModuleDepthDefault, "module-depth")
if envVar := os.Getenv(ModuleDepthEnvVar); envVar != "" {
if md, err := strconv.Atoi(envVar); err == nil {
*moduleDepth = md
}
}
}
// outputShadowError outputs the error from ctx.ShadowError. If the
// error is nil then nothing happens. If output is false then it isn't
// outputted to the user (you can define logic to guard against outputting).

View File

@ -1,7 +1,6 @@
package command
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
@ -226,58 +225,6 @@ func TestMeta_initStatePaths(t *testing.T) {
}
}
func TestMeta_addModuleDepthFlag(t *testing.T) {
old := os.Getenv(ModuleDepthEnvVar)
defer os.Setenv(ModuleDepthEnvVar, old)
cases := map[string]struct {
EnvVar string
Args []string
Expected int
}{
"env var sets value when no flag present": {
EnvVar: "4",
Args: []string{},
Expected: 4,
},
"flag overrides envvar": {
EnvVar: "4",
Args: []string{"-module-depth=-1"},
Expected: -1,
},
"negative envvar works": {
EnvVar: "-1",
Args: []string{},
Expected: -1,
},
"invalid envvar is ignored": {
EnvVar: "-#",
Args: []string{},
Expected: ModuleDepthDefault,
},
"empty envvar is okay too": {
EnvVar: "",
Args: []string{},
Expected: ModuleDepthDefault,
},
}
for tn, tc := range cases {
m := new(Meta)
var moduleDepth int
flags := flag.NewFlagSet("test", flag.ContinueOnError)
os.Setenv(ModuleDepthEnvVar, tc.EnvVar)
m.addModuleDepthFlag(flags, &moduleDepth)
err := flags.Parse(tc.Args)
if err != nil {
t.Fatalf("%s: err: %#v", tn, err)
}
if moduleDepth != tc.Expected {
t.Fatalf("%s: expected: %#v, got: %#v", tn, tc.Expected, moduleDepth)
}
}
}
func TestMeta_Env(t *testing.T) {
td := tempDir(t)
os.MkdirAll(td, 0755)

View File

@ -19,7 +19,6 @@ type PlanCommand struct {
func (c *PlanCommand) Run(args []string) int {
var destroy, refresh, detailed bool
var outPath string
var moduleDepth int
args, err := c.Meta.process(args, true)
if err != nil {
@ -29,7 +28,6 @@ func (c *PlanCommand) Run(args []string) int {
cmdFlags := c.Meta.flagSet("plan")
cmdFlags.BoolVar(&destroy, "destroy", false, "destroy")
cmdFlags.BoolVar(&refresh, "refresh", true, "refresh")
c.addModuleDepthFlag(cmdFlags, &moduleDepth)
cmdFlags.StringVar(&outPath, "out", "", "path")
cmdFlags.IntVar(
&c.Meta.parallelism, "parallelism", DefaultParallelism, "parallelism")
@ -221,10 +219,6 @@ Options:
-lock-timeout=0s Duration to retry a state lock.
-module-depth=n Specifies the depth of modules to show in the output.
This does not affect the plan itself, only the output
shown. By default, this is -1, which will expand all.
-no-color If specified, output won't contain any color.
-out=path Write a plan file to the given path. This can be used as

View File

@ -173,9 +173,6 @@ Usage: terraform show [options] [path]
Options:
-module-depth=n Specifies the depth of modules to show in the output.
By default this is -1, which will expand all.
-no-color If specified, output won't contain any color.
`

View File

@ -59,6 +59,7 @@ complete -f -c terraform -n '__fish_seen_subcommand_from get' -o no-color -d 'If
### graph
complete -f -c terraform -n '__fish_use_subcommand' -a graph -d 'Create a visual graph of Terraform resources'
complete -f -c terraform -n '__fish_seen_subcommand_from graph' -o draw-cycles -d 'Highlight any cycles in the graph'
complete -f -c terraform -n '__fish_seen_subcommand_from graph' -o module-depth -d 'Depth of modules to show in the output'
complete -f -c terraform -n '__fish_seen_subcommand_from graph' -o no-color -d 'If specified, output won\'t contain any color'
complete -f -c terraform -n '__fish_seen_subcommand_from graph' -o type -d 'Type of graph to output'
@ -101,7 +102,6 @@ complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o detailed-exitc
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o input -d 'Ask for input for variables if not directly set'
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o lock -d 'Lock the state file when locking is supported'
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o lock-timeout -d 'Duration to retry a state lock'
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o module-depth -d 'Depth of modules to show in the output'
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o no-color -d 'If specified, output won\'t contain any color'
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o out -d 'Write a plan file to the given path'
complete -f -c terraform -n '__fish_seen_subcommand_from plan' -o parallelism -d 'Limit the number of concurrent operations'
@ -138,7 +138,6 @@ complete -f -c terraform -n '__fish_seen_subcommand_from refresh' -o var-file -d
### show
complete -f -c terraform -n '__fish_use_subcommand' -a show -d 'Inspect Terraform state or plan'
complete -f -c terraform -n '__fish_seen_subcommand_from show' -o module-depth -d 'Depth of modules to show in the output'
complete -f -c terraform -n '__fish_seen_subcommand_from show' -o no-color -d 'If specified, output won\'t contain any color'
### taint

View File

@ -48,16 +48,6 @@ If set to "false" or "0", causes terraform commands to behave as if the `-input=
export TF_INPUT=0
```
## TF_MODULE_DEPTH
When given a value, causes terraform commands to behave as if the `-module-depth=VALUE` flag was specified. By setting this to 0, for example, you enable commands such as [plan](/docs/commands/plan.html) and [graph](/docs/commands/graph.html) to display more compressed information.
```shell
export TF_MODULE_DEPTH=0
```
For more information regarding modules, check out the section on [Using Modules](/docs/modules/usage.html).
## TF_VAR_name
Environment variables can be used to set variables. The environment variables must be in the format `TF_VAR_name` and this will be checked last for a value. For example:

View File

@ -36,6 +36,9 @@ Options:
* `-draw-cycles` - Highlight any cycles in the graph with colored edges.
This helps when diagnosing cycle errors.
* `-module-depth=n` - Specifies the depth of modules to show in the output.
By default this is -1, which will expand all.
* `-no-color` - If specified, output won't contain any color.
* `-type=plan` - Type of graph to output. Can be: plan, plan-destroy, apply, legacy.

View File

@ -52,10 +52,6 @@ The command-line flags are all optional. The list of available flags are:
* `-lock-timeout=0s` - Duration to retry a state lock.
* `-module-depth=n` - Specifies the depth of modules to show in the output.
This does not affect the plan itself, only the output shown. By default,
this is -1, which will expand all.
* `-no-color` - Disables output with coloring.
* `-out=path` - The path to save the generated execution plan. This plan

View File

@ -22,8 +22,5 @@ file. If no path is specified, the current state will be shown.
The command-line flags are all optional. The list of available flags are:
* `-module-depth=n` - Specifies the depth of modules to show in the output.
By default this is -1, which will expand all.
* `-no-color` - Disables output with coloring

View File

@ -390,9 +390,8 @@ several regions or datacenters.
## Summarizing Modules in the UI
By default, commands such as the [plan command](/docs/commands/plan.html) and
[graph command](/docs/commands/graph.html) will show each resource in a nested
module to represent the full scope of the configuration. For more complex
By default the [graph command](/docs/commands/graph.html) will show each resource
in a nested module to represent the full scope of the configuration. For more complex
configurations, the `-module-depth` option may be useful to summarize some or all
of the modules as single objects.
@ -405,10 +404,6 @@ If we instead set `-module-depth=0`, the graph will look like this:
![Terraform Module Graph](docs/module_graph.png)
Other commands work similarly with modules. Note that `-module-depth` only
affects how modules are presented in the UI; it does not affect how modules
and their contained resources are processed by Terraform operations.
## Tainting resources within a module
The [taint command](/docs/commands/taint.html) can be used to _taint_ specific