Sha256: 48ba108e61477e05e0b48ab2a503c67405b1aec2ad92d76969740f41050b7f9c

Contents?: true

Size: 1.92 KB

Versions: 6

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require 'ruby_terraform'

require_relative 'command_instantiation'

module RSpec
  module Terraform
    module Helpers
      module Actions
        module Apply
          include CommandInstantiation

          def apply(parameters)
            parameters = apply_parameters(parameters)

            log_apply_starting(parameters)
            log_apply_using_parameters(parameters)

            apply_command.execute(parameters)

            log_apply_complete
          end

          private

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

          def log_apply_using_parameters(parameters)
            logger&.debug("Applying using parameters: #{parameters}...")
          end

          def log_apply_complete
            logger&.info('Apply complete.')
          end

          def apply_command
            instantiate_command(RubyTerraform::Commands::Apply)
          end

          def apply_parameters(parameters)
            with_apply_state_file_parameters(
              with_apply_standard_parameters(parameters)
            )
          end

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

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

          def with_apply_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

6 entries across 6 versions & 1 rubygems

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