Module: VagrantPlugins::TerraformProvider::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-terraform/action.rb,
lib/vagrant-terraform/action/halt_vm.rb,
lib/vagrant-terraform/action/start_vm.rb,
lib/vagrant-terraform/action/create_vm.rb,
lib/vagrant-terraform/action/destroy_vm.rb,
lib/vagrant-terraform/action/is_created.rb,
lib/vagrant-terraform/action/is_running.rb,
lib/vagrant-terraform/action/read_state.rb,
lib/vagrant-terraform/action/read_ssh_info.rb,
lib/vagrant-terraform/action/wait_for_vm_up.rb,
lib/vagrant-terraform/action/setup_terraform.rb

Defined Under Namespace

Classes: CreateVM, DestroyVM, HaltVM, IsCreated, IsRunning, ReadSSHInfo, ReadState, SetupTerraform, StartVM, WaitForVmUp

Class Method Summary collapse

Class Method Details

.action_destroyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vagrant-terraform/action.rb', line 44

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      if !env[:result]
        unless env[:machine].id.nil?
          dir = ".vagrant/terraform/#{env[:machine].id}"
          env[:ui].info("Removing: " + dir)
          FileUtils.rm_rf(dir)
        end
        env[:ui].info(I18n.t("vagrant_terraform.not_created"))
        next
      end

      b2.use ProvisionerCleanup, :before if defined?(ProvisionerCleanup)
      # Maybe with sshfs clean halting could be beneficial
      # b2.use HaltVM unless env[:machine].state.id == :stopped
      b2.use DestroyVM
    end
  end
end

.action_haltObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/vagrant-terraform/action.rb', line 106

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, IsRunning do |env, b2|
      if env[:machine_state_id] == :powering_up
        env[:ui].info(I18n.t("vagrant_terraform.powering_up"))
        next
      end
      if !env[:result]
        env[:ui].info(I18n.t("vagrant_terraform.not_up"))
        next
      end
      b2.use HaltVM
    end
  end
end

.action_provisionObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant-terraform/action.rb', line 66

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      # synced_folders defaults to NFS on linux. Make it default to rsync.
      env[:machine].config.nfs.functional = false
      if !env[:result]
        env[:ui].info(I18n.t("vagrant_terraform.not_created"))
        next
      end
      b2.use Provision
      b2.use SyncedFolderCleanup
      require 'vagrant/action/builtin/synced_folders'
      b2.use SyncedFolders
    end
  end
end

.action_read_ssh_infoObject

This action is called to read the SSH info of the machine. The resulting state is expected to be put into the ‘:machine_ssh_info` key.



97
98
99
100
101
102
103
104
# File 'lib/vagrant-terraform/action.rb', line 97

def self.action_read_ssh_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, ReadState do |env, b2|
      b2.use ReadSSHInfo
    end
  end
end

.action_read_stateObject

This action is called to read the state of the machine. The resulting state is expected to be put into the ‘:machine_state_id` key.



86
87
88
89
90
91
92
# File 'lib/vagrant-terraform/action.rb', line 86

def self.action_read_state
  Vagrant::Action::Builder.new.tap do |b|
    b.use HandleBox
    b.use ConfigValidate
    b.use ReadState
  end
end

.action_reloadObject



122
123
124
125
126
127
# File 'lib/vagrant-terraform/action.rb', line 122

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use action_halt
    b.use action_up
  end
end

.action_sshObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vagrant-terraform/action.rb', line 129

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate

    b.use Call, ReadState do |env, b2|
      if env[:machine_state_id] == :not_created
        env[:ui].info(I18n.t("vagrant_terraform.not_created"))
        next
      end
      if env[:machine_state_id] != :running
        env[:ui].info(I18n.t("vagrant_terraform.not_up"))
        next
      end

      raise Errors::NoIPError if env[:ip_address].nil?
      b2.use SSHExec
    end

  end
end

.action_ssh_runObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/vagrant-terraform/action.rb', line 150

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate

    b.use Call, ReadState do |env, b2|
      if env[:machine_state_id] == :not_created
        env[:ui].info(I18n.t("vagrant_terraform.not_created"))
        next
      end
      if env[:machine_state_id] != :running
        env[:ui].info(I18n.t("vagrant_terraform.not_up"))
        next
      end

      raise Errors::NoIPError if env[:ip_address].nil?
      b2.use SSHRun
    end
  end
end

.action_upObject

This action is called to bring the box up from nothing.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant-terraform/action.rb', line 11

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use HandleBox
    b.use ConfigValidate

    b.use Call, ReadState do |env, b2|
      b2.use SetupTerraform
      # synced_folders defaults to NFS on linux. Make it default to rsync.
      env[:machine].config.nfs.functional = false
      if env[:machine_state_id] == :running
        b2.use Provision
        b2.use SyncedFolderCleanup
        require 'vagrant/action/builtin/synced_folders'
        b2.use SyncedFolders
        next
      end

      if env[:machine_state_id] == :not_created
        b2.use CreateVM
        b2.use Provision
        b2.use SetHostname
      end

      b2.use StartVM
      b2.use WaitForVmUp
      b2.use SyncedFolderCleanup
      require 'vagrant/action/builtin/synced_folders'
      b2.use SyncedFolders
    end

  end
end