Sha256: 8c6dd0d3c51cab85382761d3a9ad32d4ad2c056a6d5be60715891e83f7b069c7

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require 'ruby_terraform'

require_relative './command_instantiation'

module RSpec
  module Terraform
    module Helpers
      module Actions
        module Destroy
          include CommandInstantiation

          def destroy(parameters)
            parameters = destroy_parameters(parameters)

            log_destroy_starting(parameters)
            log_destroy_using_parameters(parameters)

            destroy_command.execute(parameters)

            log_destroy_complete
          end

          private

          def log_destroy_starting(parameters)
            logger&.info(
              'Destroying for configuration in directory: ' \
              "'#{parameters[:chdir]}'..."
            )
          end

          def log_destroy_using_parameters(parameters)
            logger&.debug("Destroying using parameters: #{parameters}...")
          end

          def log_destroy_complete
            logger&.info('Destroy complete.')
          end

          def destroy_command
            instantiate_command(RubyTerraform::Commands::Destroy)
          end

          def destroy_parameters(parameters)
            with_destroy_state_file_parameters(
              with_destroy_standard_parameters(parameters)
            )
          end

          def with_destroy_standard_parameters(parameters)
            configuration_directory = parameters[:configuration_directory]

            parameters
              .except(:configuration_directory)
              .merge(
                chdir: configuration_directory,
                input: false,
                auto_approve: true
              )
          end

          def with_destroy_state_file_parameters(parameters)
            state_file = parameters[:state_file]
            if state_file
              return parameters
                       .except(:state_file)
                       .merge(state: state_file)
            end

            parameters
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rspec-terraform-0.5.0.pre.3 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.5.0.pre.2 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.5.0.pre.1 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.4.0 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.3.0.pre.1 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.2.0 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.1.0.pre.49 lib/rspec/terraform/helpers/actions/destroy.rb
rspec-terraform-0.1.0.pre.48 lib/rspec/terraform/helpers/actions/destroy.rb