Sha256: 02535e381f41f76201fc4027b187e97e6ab18bea1f2be4dd384ce1adb9efa18c

Contents?: true

Size: 929 Bytes

Versions: 6

Compression:

Stored size: 929 Bytes

Contents

require 'socket'

module TerraformDevKit
  class Environment
    attr_reader :name

    def initialize(name)
      /^[0-9a-zA-Z]+$/ =~ name || (raise "Invalid environment name: #{name}")
      @name = name.downcase
    end

    def config
      case @name
      when 'prod'
        'prod'
      when 'test'
        'test'
      else
        'dev'
      end
    end

    def local_backend?
      case @name
      when 'prod', 'test'
        false
      else
        true
      end
    end

    def working_dir
      # TODO: get rid of ROOT_PATH
      File.join(ROOT_PATH, 'envs', @name)
    end

    def self.temp_name
      hostname = Socket.gethostname
      date = Time.now.strftime('%y%m%d%H%M')
      env = "#{hostname}#{date}"
      env.gsub(/[^0-9a-zA-Z]/, '')
    end

    def self.running_on_jenkins?
      ENV.key?('JENKINS_URL') && ENV.key?('BUILD_ID')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
TerraformDevKit-0.4.0 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.8 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.7 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.6 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.5 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.4 lib/TerraformDevKit/environment.rb