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.
- #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 raise "No terraform tstate for this environment" 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 |
#resources ⇒ Object
29 30 31 32 |
# File 'lib/objects/terraform/state.rb', line 29 def resources return {} unless config_exists? return config["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 |