Class: RubyTerraform::Commands::Format

Inherits:
Base
  • Object
show all
Includes:
Options::Global
Defined in:
lib/ruby_terraform/commands/format.rb

Overview

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 Base#initialize.

When executing an instance of Format via Base#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: If true, lists files whose formatting differs; defaults to false; always disabled if using standard input.

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

  • :diff: If true, displays diffs of formatting changes; defaults to false.

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

  • :no_color: whether or not the output from the command should be in color; defaults to false.

  • :recursive: If true, also processes files in subdirectories; defaults to false such that only the provided :directory is processed.

The Base#execute method accepts an optional second parameter which is a map of invocation options. Currently, the only supported option is :environment which is a map of environment variables to expose during invocation of the command.

Examples:

Basic Invocation

RubyTerraform::Commands::Format.new.execute(
  directory: 'infra/networking')

Constructor Details

This class inherits a constructor from RubyTerraform::Commands::Base