Class: Terrafying::Config
- Inherits:
-
Object
- Object
- Terrafying::Config
- Defined in:
- lib/terrafying.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #apply ⇒ Object
- #destroy ⇒ Object
- #graph ⇒ Object
- #import(addr, id) ⇒ Object
-
#initialize(path, options) ⇒ Config
constructor
A new instance of Config.
- #json ⇒ Object
- #list ⇒ Object
- #plan ⇒ Object
- #show_state ⇒ Object
- #use_local_state ⇒ Object
- #use_remote_state ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(path, options) ⇒ Config
Returns a new instance of Config.
22 23 24 25 26 27 28 29 30 |
# File 'lib/terrafying.rb', line 22 def initialize(path, ) @path = File.(path) @options = @scope = [:scope] || scope_for_path(@path) $stderr.puts "Scope: #{@scope}" load(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/terrafying.rb', line 20 def path @path end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
20 21 22 |
# File 'lib/terrafying.rb', line 20 def scope @scope end |
Instance Method Details
#apply ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/terrafying.rb', line 70 def apply exit_code = 1 with_config do with_lock do with_state(mode: :update) do exit_code = exec_with_optional_target "apply -auto-approve -backup=- #{@dir}" end end end exit_code end |
#destroy ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/terrafying.rb', line 82 def destroy exit_code = 1 with_config do with_lock do with_state(mode: :update) do exit_code = stream_command("terraform destroy -backup=- #{@dir}") end end end exit_code end |
#graph ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/terrafying.rb', line 50 def graph exit_code = 1 with_config do with_state(mode: :read) do exit_code = exec_with_optional_target 'graph' end end exit_code end |
#import(addr, id) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/terrafying.rb', line 119 def import(addr, id) exit_code = 1 with_config do with_lock do with_state(mode: :update) do exit_code = exec_with_optional_target "import -backup=- #{@dir} #{addr} #{id}" end end end exit_code end |
#json ⇒ Object
36 37 38 |
# File 'lib/terrafying.rb', line 36 def json Terrafying::Generator.pretty_generate end |
#list ⇒ Object
32 33 34 |
# File 'lib/terrafying.rb', line 32 def list Terrafying::Generator.resource_names end |
#plan ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/terrafying.rb', line 40 def plan exit_code = 1 with_config do with_state(mode: :read) do exit_code = exec_with_optional_target 'plan' end end exit_code end |
#show_state ⇒ Object
94 95 96 |
# File 'lib/terrafying.rb', line 94 def show_state puts(State.store(self).get) end |
#use_local_state ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/terrafying.rb', line 109 def use_local_state with_lock do remote = State.remote(self) state = remote.get if state State.local(self).put(state) end end end |
#use_remote_state ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/terrafying.rb', line 98 def use_remote_state with_lock do local = State.local(self) state = local.get if state State.remote(self).put(state) end local.delete end end |
#validate ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/terrafying.rb', line 60 def validate exit_code = 1 with_config do with_state(mode: :read) do exit_code = exec_with_optional_target 'validate' end end exit_code end |