module Terraformer module Credentials class AwsMissingCredentals < RuntimeError attr_reader :key def initialize(key) @key = key super(message) end def message "'#{key}' not passed. set it via CLI --#{key} or #{key.upcase} enviroment variable." end end class Aws KEYS = %w(aws_region aws_access_key_id aws_secret_access_key).freeze def self.get_from_options(options) KEYS.inject({}) do |credentials, key| aws_key = key.sub("aws_", "").to_sym credentials[aws_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym] credentials[aws_key] = ENV[key.upcase] if credentials[aws_key].nil? raise AwsMissingCredentals.new(key) if credentials[aws_key].nil? credentials end end end end end