From c2b24b91f9b868a693acf3fc6d2afb6def0e8693 Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Fri, 14 Jan 2022 23:11:03 +0000 Subject: [PATCH] dotenv support --- lib/templates/base/project/.gitignore | 1 + lib/terraspace/booter.rb | 1 + lib/terraspace/dotenv.rb | 25 +++++++++++++++++++++++++ terraspace.gemspec | 1 + 4 files changed, 28 insertions(+) create mode 100644 lib/terraspace/dotenv.rb diff --git a/lib/templates/base/project/.gitignore b/lib/templates/base/project/.gitignore index c393e3d1..d6896d28 100644 --- a/lib/templates/base/project/.gitignore +++ b/lib/templates/base/project/.gitignore @@ -13,6 +13,7 @@ terraform.tfvars # Common ruby files *.gem *.rbc +.env* .idea /.bundle /.config diff --git a/lib/terraspace/booter.rb b/lib/terraspace/booter.rb index 630be303..86cea6ef 100644 --- a/lib/terraspace/booter.rb +++ b/lib/terraspace/booter.rb @@ -1,6 +1,7 @@ module Terraspace module Booter def boot + Dotenv.new.load! run_hooks Terraspace::Bundle.require # load plugins load_plugin_default_configs diff --git a/lib/terraspace/dotenv.rb b/lib/terraspace/dotenv.rb new file mode 100644 index 00000000..3fef3d61 --- /dev/null +++ b/lib/terraspace/dotenv.rb @@ -0,0 +1,25 @@ +require 'dotenv' + +module Terraspace + class Dotenv + def load! + ::Dotenv.load(*files) + end + + # dotenv files with the following precedence: + # + # - .env.dev.local - Highest precedence + # - .env.dev + # - .env.local + # - .env - Lowest precedence + # + def files + [ + ".env.#{Terraspace.env}.local", + ".env.#{Terraspace.env}", + ".env.local", + ".env", + ].compact + end + end +end diff --git a/terraspace.gemspec b/terraspace.gemspec index 871157d8..c9fc82f4 100644 --- a/terraspace.gemspec +++ b/terraspace.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |spec| spec.add_dependency "bundler" spec.add_dependency "cli-format" spec.add_dependency "deep_merge" + spec.add_dependency "dotenv" spec.add_dependency "dsl_evaluator" spec.add_dependency "eventmachine-tail" spec.add_dependency "graph"