From 178ec8f7b42f1bbe5eb3c449da811d2872eacc6d Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 2 Nov 2018 17:58:38 +0100 Subject: [PATCH] Remove support for the -module-depth flag # Conflicts: # backend/backend.go --- command/graph.go | 15 +++--- command/meta.go | 19 ------- command/meta_test.go | 53 ------------------- command/plan.go | 6 --- command/show.go | 3 -- contrib/fish-completion/terraform.fish | 3 +- .../commands/environment-variables.html.md | 10 ---- website/docs/commands/graph.html.markdown | 3 ++ website/docs/commands/plan.html.markdown | 4 -- website/docs/commands/show.html.markdown | 3 -- website/docs/modules/usage.html.markdown | 9 +--- 11 files changed, 15 insertions(+), 113 deletions(-) diff --git a/command/graph.go b/command/graph.go index 03612f6a1..d923ce437 100644 --- a/command/graph.go +++ b/command/graph.go @@ -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. ` diff --git a/command/meta.go b/command/meta.go index da6d1c09b..dbc1437d0 100644 --- a/command/meta.go +++ b/command/meta.go @@ -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). diff --git a/command/meta_test.go b/command/meta_test.go index 63ab0fb28..b42312924 100644 --- a/command/meta_test.go +++ b/command/meta_test.go @@ -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) diff --git a/command/plan.go b/command/plan.go index 6f45650a8..2f3411286 100644 --- a/command/plan.go +++ b/command/plan.go @@ -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 diff --git a/command/show.go b/command/show.go index bb1106b59..66140a4a3 100644 --- a/command/show.go +++ b/command/show.go @@ -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. ` diff --git a/contrib/fish-completion/terraform.fish b/contrib/fish-completion/terraform.fish index 41f3660f7..0c5646230 100644 --- a/contrib/fish-completion/terraform.fish +++ b/contrib/fish-completion/terraform.fish @@ -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 diff --git a/website/docs/commands/environment-variables.html.md b/website/docs/commands/environment-variables.html.md index e53428806..50098a6cb 100644 --- a/website/docs/commands/environment-variables.html.md +++ b/website/docs/commands/environment-variables.html.md @@ -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: diff --git a/website/docs/commands/graph.html.markdown b/website/docs/commands/graph.html.markdown index b7d677c7b..6be2f49e7 100644 --- a/website/docs/commands/graph.html.markdown +++ b/website/docs/commands/graph.html.markdown @@ -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. diff --git a/website/docs/commands/plan.html.markdown b/website/docs/commands/plan.html.markdown index 00d705a4b..41bf7d295 100644 --- a/website/docs/commands/plan.html.markdown +++ b/website/docs/commands/plan.html.markdown @@ -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 diff --git a/website/docs/commands/show.html.markdown b/website/docs/commands/show.html.markdown index f2b9edc5e..18196bc22 100644 --- a/website/docs/commands/show.html.markdown +++ b/website/docs/commands/show.html.markdown @@ -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 diff --git a/website/docs/modules/usage.html.markdown b/website/docs/modules/usage.html.markdown index 20e01ce26..1f39c1e55 100644 --- a/website/docs/modules/usage.html.markdown +++ b/website/docs/modules/usage.html.markdown @@ -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