class RubyTerraform::Commands::Format
Wraps the +terraform fmt+ command which rewrites all terraform configuration files to a canonical format.
Both configuration files (.tf) and variables files (.tfvars) are updated. JSON files (.tf.json or .tfvars.json) are not modified.
If :directory
is not specified in the parameters map then the current working directory will be used. If :directory
is +“-”+ then content will be read from the standard input. The given content must be in the terraform language native syntax; JSON is not supported.
For options accepted on construction, see {#initialize}.
When executing an instance of {Format} via {#execute}, the following options are supported:
-
:directory
: the path to a directory containing terraform configuration (deprecated in terraform 0.14, removed in terraform 0.15, use:chdir
instead). -
:chdir
: the path of a working directory to switch to before executing the given subcommand. -
:list
: Iftrue
, lists files whose formatting differs; defaults tofalse
; always disabled if using standard input. -
:write
: Iftrue
, writes to source files; defaults tofalse
; always disabled if using standard input or:check
istrue
. -
:diff
: Iftrue
, displays diffs of formatting changes; defaults tofalse
. -
:check
: Iftrue
, checks if the input is formatted; if any input is not properly formatted, an {RubyTerraform::Errors::ExecutionError} will be thrown; defaults tofalse
. -
:no_color
: whether or not the output from the command should be in color; defaults tofalse
. -
:recursive
: Iftrue
, also processes files in subdirectories; defaults tofalse
such that only the provided:directory
is processed.
@example Basic Invocation
RubyTerraform::Commands::Format.new.execute( directory: 'infra/networking')
Public Instance Methods
@!visibility private
# File lib/ruby_terraform/commands/format.rb, line 68 def arguments(parameters) [parameters[:directory]] end
@!visibility private
RubyTerraform::Options::Global#options
# File lib/ruby_terraform/commands/format.rb, line 56 def options %w[ -list -write -diff -check -no-color -recursive ] + super end
@!visibility private
# File lib/ruby_terraform/commands/format.rb, line 51 def subcommands %w[fmt] end