Class: Bcome::Terraform::State
- Inherits:
-
Object
- Object
- Bcome::Terraform::State
- Defined in:
- lib/objects/terraform/state.rb
Constant Summary collapse
- TSTATE_FILENAME =
"terraform.tfstate".freeze
Instance Method Summary collapse
- #config ⇒ Object
- #config_exists? ⇒ Boolean
- #config_path ⇒ Object
-
#initialize(namespace) ⇒ State
constructor
A new instance of State.
- #modules ⇒ Object
- #resources ⇒ Object
- #terraform_installation_path ⇒ Object
Constructor Details
#initialize(namespace) ⇒ State
Returns a new instance of State.
7 8 9 |
# File 'lib/objects/terraform/state.rb', line 7 def initialize(namespace) @namespace = namespace end |
Instance Method Details
#config ⇒ Object
24 25 26 27 |
# File 'lib/objects/terraform/state.rb', line 24 def config return {} unless config_exists? JSON.parse(File.read(config_path)) end |
#config_exists? ⇒ Boolean
20 21 22 |
# File 'lib/objects/terraform/state.rb', line 20 def config_exists? File.exist?(config_path) end |
#config_path ⇒ Object
16 17 18 |
# File 'lib/objects/terraform/state.rb', line 16 def config_path "#{terraform_installation_path}/#{TSTATE_FILENAME}" end |
#modules ⇒ Object
29 30 31 32 |
# File 'lib/objects/terraform/state.rb', line 29 def modules return {} unless config_exists? return config["modules"] end |
#resources ⇒ Object
34 35 36 37 38 |
# File 'lib/objects/terraform/state.rb', line 34 def resources # TODO What was I thinking ... We need all the modules... return {} unless config_exists? return modules[0]["resources"] end |
#terraform_installation_path ⇒ Object
11 12 13 14 |
# File 'lib/objects/terraform/state.rb', line 11 def terraform_installation_path # Look for a terraform config installation in the path belonging to this node @terraform_installation_path ||= "terraform/environments/#{@namespace.gsub(":","_")}" end |