class RakeTerraform::ApplyTask::Task

Custom rake task to run `terraform apply`

Public Class Methods

new(opts) click to toggle source
# File lib/rake-terraform/apply_task/task.rb, line 11
def initialize(opts)
  @opts = opts
end

Public Instance Methods

execute() click to toggle source
# File lib/rake-terraform/apply_task/task.rb, line 15
def execute
  plan = @opts.get(:plan)
  pre_execute_checks(plan)
  Dir.chdir(@opts.get(:execution_path)) do
    if @opts[:unique_state]
      tf_apply(plan, @opts[:state_file])
    else
      tf_apply(plan)
    end
  end
end

Private Instance Methods

ensure_plan_exists(plan) click to toggle source
# File lib/rake-terraform/apply_task/task.rb, line 38
def ensure_plan_exists(plan)
  raise "Plan #{plan} does not exist! Aborting!" unless File.exist? plan
end
pre_execute_checks(plan = @opts.get(:plan)) click to toggle source

run pre execution checks

# File lib/rake-terraform/apply_task/task.rb, line 30
def pre_execute_checks(plan = @opts.get(:plan))
  validate_terraform_installed
  ensure_plan_exists plan
  tf_show(plan)
  say 'The above changes will be applied to your environment.'
  exit unless agree 'Are you sure you want to execute this plan? (y/n)'
end