Class: Terrafying::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/terrafying.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @path = File.expand_path(path)
  @options = options
  @scope = options[:scope] || scope_for_path(@path)

  warn "Scope: #{@scope}"

  load(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/terrafying.rb', line 18

def path
  @path
end

#scopeObject (readonly)

Returns the value of attribute scope.



18
19
20
# File 'lib/terrafying.rb', line 18

def scope
  @scope
end

Instance Method Details

#applyObject



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

#destroyObject



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

#graphObject



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

#jsonObject



34
35
36
# File 'lib/terrafying.rb', line 34

def json
  Terrafying::Generator.pretty_generate
end

#listObject



30
31
32
# File 'lib/terrafying.rb', line 30

def list
  Terrafying::Generator.resource_names
end

#planObject



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_stateObject



92
93
94
# File 'lib/terrafying.rb', line 92

def show_state
  puts(State.store(self).get)
end

#use_local_stateObject



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_stateObject



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

#validateObject



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