class TfOutputs::Configurator::Backends::S3StateConfiguration

Public Class Methods

new(options) click to toggle source
# File lib/tfoutputs/configurator/backends/s3_state_configuration.rb, line 9
def initialize(options)
  @bucket_name = options[:bucket_name]
  @bucket_key = options[:bucket_key]
  @bucket_region = options[:bucket_region]
  @profile = options[:profile] ? options[:profile] : nil
end

Public Instance Methods

save() click to toggle source
# File lib/tfoutputs/configurator/backends/s3_state_configuration.rb, line 16
def save
  file = Tempfile.new('tf_state')

  # Setup the base client config which must always have a bucket region
  client_config = {region: @bucket_region}
  # if a profile was supplied, then add that to the client config
  if !@profile.nil?
    client_config[:profile] = @profile
  end

  # setup s3 client
  s3 = Aws::S3::Client.new(client_config)
  resp = s3.get_object bucket: @bucket_name, key: @bucket_key
  file.write(resp.body.string)
  file.rewind
  file
end