Sha256: 3727846c650a61f9b82c8b89a28b2a57713374d468cabe7b579a69a4b925f4db

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'ruby_terraform'

require_relative 'command_instantiation'

module RSpec
  module Terraform
    module Helpers
      module Actions
        module Init
          include CommandInstantiation

          def init(parameters)
            parameters = init_parameters(parameters)

            log_init_starting(parameters)
            log_init_using_parameters(parameters)

            init_command.execute(parameters)

            log_init_complete
          end

          private

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

          def log_init_using_parameters(parameters)
            logger&.debug("Initing using parameters: #{parameters}...")
          end

          def log_init_complete
            logger&.info('Init complete.')
          end

          def init_command
            instantiate_command(RubyTerraform::Commands::Init)
          end

          def init_parameters(parameters)
            with_init_execution_mode_parameters(
              with_init_standard_parameters(parameters)
            )
          end

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

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

          def with_init_execution_mode_parameters(parameters)
            source_directory = parameters[:source_directory]
            parameters = parameters.except(:source_directory)

            if execution_mode == :isolated
              return parameters.merge(from_module: source_directory)
            end

            parameters
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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