Class: TfOutputs::Configurator::Backends::S3StateConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/tfoutputs/configurator/backends/s3_state_configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ S3StateConfiguration



9
10
11
12
13
14
# 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

Instance Method Details

#saveObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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