Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for the -module-depth flag #19267

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions command/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.


`
Expand Down
19 changes: 0 additions & 19 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
53 changes: 0 additions & 53 deletions command/meta_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"flag"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions command/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

`
Expand Down
3 changes: 1 addition & 2 deletions contrib/fish-completion/terraform.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions website/docs/commands/environment-variables.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions website/docs/commands/graph.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions website/docs/commands/plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions website/docs/commands/show.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 2 additions & 7 deletions website/docs/modules/usage.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down