class Pfm::Command::Base

def deploy_setup

def deploy_setup
  Terraform::Binary.configure do |config|
    config.version = SETTINGS['TERRAFORM_VERSION']
    config.download_path = "/tmp/#{SecureRandom.uuid}"
  end
  raise InvalidRepository, 'This doesn\'t look like a valid infrastructure repository' unless File.directory? "#{inf_base_dir}/tf"
  config = Idlc::Deploy::Config.new(SETTINGS['AWS_REGION'])
  config.parse("#{inf_base_dir}/env/config/default.yml") if File.exist? "#{inf_base_dir}/env/config/default.yml"
  if ENV['PROD'] == 'true' || ENV['PROD'] == '1'
    config.parse("#{inf_base_dir}/env/config/prod.yml")
  else
    config.parse("#{inf_base_dir}/env/config/devtest.yml")
  end
  config.parse("#{inf_base_dir}/env/size/#{ENV['SIZE']}.yml") if File.exist? "#{inf_base_dir}/env/size/#{ENV['SIZE']}.yml"
  inf_conf_file = 'inf.config.yml'
  # For unit tests
  inf_conf_file = 'inf.config.example.yml' unless File.exist? inf_conf_file
  config.parse(inf_conf_file)
  bucket_name = Idlc::Deploy::Config.get_deployment_var('tfstate_bucket')
  sub_bucket = "#{Idlc::Deploy::Config.get_deployment_var('job_code')}"\
    "#{Idlc::Deploy::Config.get_deployment_var('job')}"\
    "-#{Idlc::Deploy::Config.get_deployment_var('env')}".freeze
  # Pass some ENV vars for Terraform
  Idlc::Deploy::Config.add_deployment_var('environment_key', sub_bucket)
  Idlc::Deploy::Config.add_deployment_var('version', REPO_VERSION)
  Idlc::Deploy::Config.add_deployment_var('major_minor', Idlc::Utility.major_minor(REPO_VERSION))
  Idlc::Deploy::Config.add_deployment_var('major_minor_patch', Idlc::Utility.major_minor_patch(REPO_VERSION))
  Idlc::Deploy::Config.add_deployment_var('build', @config[:server_build])
  Idlc::Deploy::Config.add_deployment_var('app_release', @config[:app_release])
  Idlc::Deploy::Keypair.generate("#{inf_base_dir}/env/kp")
  @workspace.flatten("#{inf_base_dir}/tf", 'tf')
  @workspace.add("#{inf_base_dir}/env/kp")
  @workspace.add('lib/tf/modules')
  config.configure_state(bucket_name, sub_bucket, @workspace.tmp_dir)
end