class Terraform

Wrapper for Terraform commands

Public Instance Methods

cli_flags(**flags) click to toggle source

Returns `Array` of CLI flags for Terraform E.g. `{ foo: true, bar: 'baz' }` -> `[ '-foo=true', '-bar=baz' ]`

# File lib/terraform.rb, line 44
def cli_flags(**flags)
  flags.map { |k, v| "-#{k}=#{v}" }
end
find_tfvars_files(dir = nil, &block) click to toggle source

Finds all *.tfvars files recursively in the given directory, or current working directory if not specified.

# File lib/terraform.rb, line 36
def find_tfvars_files(dir = nil, &block)
  dir = "#{dir}/" if dir && !dir.empty? && dir[-1] != '/'

  Dir.glob("#{dir}**/*.tfvars", &block)
end
fmt(paths, **flags) { |path, cmd| ... } click to toggle source
# File lib/terraform.rb, line 7
def fmt(paths, **flags)
  base_cmd = %w[terraform fmt] + cli_flags(flags)

  Array(paths).inject(true) do |result, path|
    cmd = base_cmd + [path]

    yield(path, cmd) if block_given?

    system(*cmd) && result # carry on failure
  end
end
pre_0_12?() click to toggle source

Checks if the version is older than 0.12

# File lib/terraform.rb, line 30
def pre_0_12?
  VersionRequirement.new('< 0.12.0-alpha').satisfied_by?(version)
end
version() click to toggle source

Find out current Terraform version

# File lib/terraform.rb, line 20
def version
  @version ||= begin
    m = /^Terraform v(?<version>[^\s]+)/.match(`terraform version`)
    m && m[:version]
  end
rescue Errno::ENOENT
  nil
end