Sha256: 601c4244581c9a436b06fc31b4a3a48f5bcd6afbbdd4a72a3a67b664ad45296c

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require 'rake_factory'
require 'ruby_terraform'
require 'ostruct'
require 'colored2'

module RakeTerraform
  module Tasks
    class Plan < RakeFactory::Task
      default_name :plan
      default_prerequisites ->(t) { [t.ensure_task_name] }
      default_description ->(t) {
        "Plan #{t.configuration_name} using terraform"
      }

      parameter :configuration_name, :required => true
      parameter :source_directory, :required => true
      parameter :work_directory, :required => true

      parameter :backend_config

      parameter :vars, default: {}
      parameter :var_file
      parameter :state_file

      parameter :debug, :default => false
      parameter :no_color, :default => false

      parameter :plan_file
      parameter :destroy, :default => false

      parameter :ensure_task_name, :default => :'terraform:ensure'

      action do |t|
        Colored2.disable! if t.no_color

        configuration_directory =
            File.join(t.work_directory, t.source_directory)

        puts "Planning #{configuration_name}".cyan
        RubyTerraform.clean(
            directory: configuration_directory)

        mkdir_p File.dirname(configuration_directory)
        cp_r t.source_directory, configuration_directory

        Dir.chdir(configuration_directory) do
          RubyTerraform.init(
              backend_config: t.backend_config,
              no_color: t.no_color)
          RubyTerraform.plan(
              no_color: t.no_color,
              destroy: t.destroy,
              state: t.state_file,
              plan: t.plan_file,
              vars: t.vars,
              var_file: t.var_file)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake_terraform-1.1.0 lib/rake_terraform/tasks/plan.rb
rake_terraform-1.0.0.pre.pre.2 lib/rake_terraform/tasks/plan.rb
rake_terraform-1.0.0.pre.pre.1 lib/rake_terraform/tasks/plan.rb