Class: Terraspace::Terraform::Runner::Backend::Parser
- Inherits:
-
Object
- Object
- Terraspace::Terraform::Runner::Backend::Parser
- Extended by:
- Memoist
- Defined in:
- lib/terraspace/terraform/runner/backend/parser.rb
Instance Method Summary collapse
- #backend_path ⇒ Object
- #exist?(path) ⇒ Boolean
- #hcl_backend ⇒ Object
-
#initialize(mod) ⇒ Parser
constructor
A new instance of Parser.
- #json_backend ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize(mod) ⇒ Parser
Returns a new instance of Parser.
7 8 9 |
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 7 def initialize(mod) @mod = mod end |
Instance Method Details
#backend_path ⇒ Object
36 37 38 39 |
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 36 def backend_path expr = "#{@mod.cache_dir}/backend.tf*" Dir.glob(expr).first end |
#exist?(path) ⇒ Boolean
32 33 34 |
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 32 def exist?(path) path && File.exist?(path) end |
#hcl_backend ⇒ Object
25 26 27 28 29 30 |
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 25 def hcl_backend return {} unless File.exist?(backend_path) backend_raw = HclParser.load(IO.read(backend_path)) return {} unless backend_raw backend_raw.dig("terraform", "backend") || {} end |
#json_backend ⇒ Object
20 21 22 23 |
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 20 def json_backend data = JSON.load(IO.read(backend_path)) data.dig("terraform", "backend") || {} end |
#result ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/terraspace/terraform/runner/backend/parser.rb', line 11 def result return {} unless exist?(backend_path) if backend_path.include?('.json') json_backend else hcl_backend end end |