Class: TerraformWrapper::Tasks::Validate

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Shared::Logging
Defined in:
lib/terraform-wrapper/tasks/validate.rb

Instance Method Summary collapse

Methods included from Shared::Logging

configure_logger_for, logger_for

Constructor Details

#initialize(binary:, code:) {|_self| ... } ⇒ Validate

Returns a new instance of Validate.

Yields:

  • (_self)

Yield Parameters:



21
22
23
24
25
26
27
28
# File 'lib/terraform-wrapper/tasks/validate.rb', line 21

def initialize(binary:, code:)
  @binary = binary
  @code   = code

  yield self if block_given?

  validate_task
end

Instance Method Details

#validate_taskObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/terraform-wrapper/tasks/validate.rb', line 32

def validate_task
  desc 'Validates the Terraform code for an infrastructure component. Will also check formatting by default.'
  task :validate, [:fmt] => :binary do |_t, args|
    args.with_defaults(fmt: true)

    runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)

    logger.info("Validating Terraform component: #{@code.name}...")

    runner.download
    runner.validate
    runner.fmt if args[:fmt].to_s.downcase == 'true'
  end
end