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.
20 21 22 23 24 25 26 27 28 |
# File 'lib/terrafying.rb', line 20 def initialize(path, ) @path = File.(path) @options = @scope = [:scope] || scope_for_path(@path) warn "Scope: #{@scope}" load(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/terrafying.rb', line 18 def path @path end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
18 19 20 |
# File 'lib/terrafying.rb', line 18 def scope @scope end |
Instance Method Details
#apply ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/terrafying.rb', line 68 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
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/terrafying.rb', line 80 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
48 49 50 51 52 53 54 55 56 |
# File 'lib/terrafying.rb', line 48 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
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/terrafying.rb', line 113 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
34 35 36 |
# File 'lib/terrafying.rb', line 34 def json Terrafying::Generator.pretty_generate end |
#list ⇒ Object
30 31 32 |
# File 'lib/terrafying.rb', line 30 def list Terrafying::Generator.resource_names end |
#plan ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/terrafying.rb', line 38 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
92 93 94 |
# File 'lib/terrafying.rb', line 92 def show_state puts(State.store(self).get) end |
#use_local_state ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/terrafying.rb', line 105 def use_local_state with_lock do remote = State.remote(self) state = remote.get State.local(self).put(state) if state end end |
#use_remote_state ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/terrafying.rb', line 96 def use_remote_state with_lock do local = State.local(self) state = local.get State.remote(self).put(state) if state local.delete end end |
#validate ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/terrafying.rb', line 58 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 |