Sha256: 8eef50d53c6c29b9e35adb22e46264006e4d975487d926bfbdc7cdb0df3ff3bd

Contents?: true

Size: 1.54 KB

Versions: 25

Compression:

Stored size: 1.54 KB

Contents

class Terraspace::CLI
  class Down < Base
    include Concerns::PlanPath
    include Terraspace::Cloud::Streamer
    include Terraspace::Cloud::Vcs::Commenter
    include TfcConcern

    def run
      cloud_update.cani?
      @stream = cloud_stream.open("down")
      success = perform
      cloud_stream.close(success, @exception)
      exit 1 unless success
    end

    def perform
      success = nil
      if @options[:yes] && !tfc?
        success = plan
      else
        skip_plan = true
      end
      if success or skip_plan
        success = destroy
      end
      success
    rescue Exception => e
      @exception = true
      logger.info "Exception #{e.class}: #{e.message}".color(:red)
      logger.info e.backtrace.join("\n")
      false
    end

  private
    def plan
      if Terraspace.cloud? && !@options[:out]
        @options[:out] = plan_path
      end
      plan = Plan.new(@options.merge(destroy: true))
      plan.plan_only # returns success: true or false
    end

    def destroy
      commander = Commander.new("destroy", @options.merge(command: "down"))
      success = commander.run
      update = cloud_update.create(success, @stream)

      if success && @options[:destroy_workspace]
        Terraspace::Terraform::Tfc::Workspace.new(@options).destroy
      end

      logger.info "Terraspace Cloud #{update['data']['attributes']['url']}" if update
      success
    end

    def cloud_update
      Terraspace::Cloud::Update.new(@options.merge(stack: @mod.name, kind: kind, vcs_vars: vcs_vars))
    end
    memoize :cloud_update
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/cli/down.rb
terraspace-2.2.16 lib/terraspace/cli/down.rb
terraspace-2.2.15 lib/terraspace/cli/down.rb
terraspace-2.2.14 lib/terraspace/cli/down.rb
terraspace-2.2.13 lib/terraspace/cli/down.rb
terraspace-2.2.12 lib/terraspace/cli/down.rb
terraspace-2.2.11 lib/terraspace/cli/down.rb
terraspace-2.2.10 lib/terraspace/cli/down.rb
terraspace-2.2.9 lib/terraspace/cli/down.rb
terraspace-2.2.8 lib/terraspace/cli/down.rb
terraspace-2.2.7 lib/terraspace/cli/down.rb
terraspace-2.2.6 lib/terraspace/cli/down.rb
terraspace-2.2.5 lib/terraspace/cli/down.rb
terraspace-2.2.4 lib/terraspace/cli/down.rb
terraspace-2.2.3 lib/terraspace/cli/down.rb
terraspace-2.2.2 lib/terraspace/cli/down.rb
terraspace-2.2.1 lib/terraspace/cli/down.rb
terraspace-2.2.0 lib/terraspace/cli/down.rb
terraspace-2.1.7 lib/terraspace/cli/down.rb
terraspace-2.1.6 lib/terraspace/cli/down.rb