Method: RubyTerraform::ClassMethods#format

Defined in:
lib/ruby_terraform.rb

#format(parameters = {}, invocation_options = {}) ⇒ Object Also known as: fmt

Invokes 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.

Examples:

Basic Invocation

RubyTerraform.format(
  directory: 'infra/networking')

Options Hash (parameters):

  • :directory (String)

    The path to a directory containing terraform configuration (deprecated in terraform 0.14, removed in terraform 0.15, use :chdir instead).

  • :chdir (String)

    The path of a working directory to switch to before executing the given subcommand.

  • :list (Boolean) — default: false

    If true, lists files whose formatting differs; always disabled if using standard input.

  • :write (Boolean) — default: false

    If true, writes to source files; always disabled if using standard input or :check is true.

  • :diff (Boolean) — default: false

    If true, displays diffs of formatting changes.

  • :check (Boolean) — default: false

    If true, checks if the input is formatted; if any input is not properly formatted, an Errors::ExecutionError will be thrown.

  • :no_color (Boolean) — default: false

    Whether or not the output from the command should be in color.

  • :recursive (Boolean) — default: false

    If true, also processes files in subdirectories; by default, only the provided :directory is processed.

Options Hash (invocation_options):

  • :environment (Hash<String, String>)

    A map of environment variables to expose at command invocation time.



255
256
257
258
# File 'lib/ruby_terraform.rb', line 255

def format(parameters = {}, invocation_options = {})
  exec(RubyTerraform::Commands::Format,
       parameters, invocation_options)
end