class TerraformDevKit::TerraformEnvManager
Public Class Methods
active()
click to toggle source
# File lib/TerraformDevKit/terraform_env_manager.rb, line 34 def self.active output = Command.run('terraform env list', print_output: false) active = output.select { |line| line.include?('*') } raise 'Error parsing output from terraform' if active.length != 1 match = /\s*\*\s*(\S+)/.match(active[0]) match[1] unless match.nil? end
create(env)
click to toggle source
# File lib/TerraformDevKit/terraform_env_manager.rb, line 11 def self.create(env) unless exist?(env) Command.run("terraform env new #{env}", print_output: false) end end
delete(env)
click to toggle source
# File lib/TerraformDevKit/terraform_env_manager.rb, line 17 def self.delete(env) if exist?(env) select('default') Command.run("terraform env delete #{env}", print_output: false) end rescue RuntimeError => error # TODO: Get rid of this hack once the following issue gets fixed: # https://github.com/hashicorp/terraform/issues/15343 puts "Error deleting terraform environment: #{error}\n" \ 'NOTE: Deleting an environment does not currently work on Windows' end
exist?(env)
click to toggle source
# File lib/TerraformDevKit/terraform_env_manager.rb, line 6 def self.exist?(env) output = Command.run('terraform env list', print_output: false) output.any? { |line| line.tr('* ', '') == env } end
select(env)
click to toggle source
# File lib/TerraformDevKit/terraform_env_manager.rb, line 29 def self.select(env) create(env) Command.run("terraform env select #{env}", print_output: false) end