Sha256: a10927eacac1e325db6819612aa0b096aa2d737e1d541decdec0dff9bc43ae1e

Contents?: true

Size: 1.96 KB

Versions: 5

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require 'ruby_terraform'
require 'stringio'

require_relative 'command_instantiation'

module RSpec
  module Terraform
    module Helpers
      module Actions
        module Show
          include CommandInstantiation

          def show(parameters, plan_file)
            parameters = show_parameters(parameters, plan_file)

            log_show_starting(parameters, plan_file)
            log_show_using_parameters(parameters)

            stdout = StringIO.new
            show_command(stdout: stdout)
              .execute(parameters)

            log_show_complete

            stdout.string
          end

          private

          def log_show_starting(parameters, plan_file)
            logger&.info(
              "Showing file: '#{plan_file}' in configuration directory: " \
              "'#{parameters[:chdir]}'..."
            )
          end

          def log_show_using_parameters(parameters)
            logger&.debug("Showing using parameters: #{parameters}...")
          end

          def log_show_complete
            logger&.info('Show complete.')
          end

          def show_command(opts = {})
            instantiate_command(RubyTerraform::Commands::Show, opts)
          end

          def show_parameters(parameters, plan_file)
            with_show_plan_file_parameters(
              with_show_standard_parameters(parameters),
              plan_file
            )
          end

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

            parameters
              .except(:configuration_directory)
              .merge(
                chdir: configuration_directory,
                no_color: true,
                json: true
              )
          end

          def with_show_plan_file_parameters(parameters, plan_file)
            parameters.merge(
              path: plan_file
            )
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec-terraform-0.5.0.pre.8 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.5.0.pre.7 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.5.0.pre.6 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.5.0.pre.5 lib/rspec/terraform/helpers/actions/show.rb
rspec-terraform-0.5.0.pre.4 lib/rspec/terraform/helpers/actions/show.rb