Class: VagrantPlugins::TerraformProvider::Action::ReadSSHInfo

Inherits:
Object
  • Object
show all
Includes:
Util::TerraformExecute
Defined in:
lib/vagrant-terraform/action/read_ssh_info.rb

Overview

This action reads the SSH info for the machine and puts it into the ‘:machine_ssh_info` key in the environment.

Instance Method Summary collapse

Methods included from Util::TerraformExecute

terraform_execute

Constructor Details

#initialize(app, env) ⇒ ReadSSHInfo

Returns a new instance of ReadSSHInfo.



12
13
14
15
# File 'lib/vagrant-terraform/action/read_ssh_info.rb', line 12

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_terraform::action::read_ssh_info")
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
# File 'lib/vagrant-terraform/action/read_ssh_info.rb', line 17

def call(env)
  env[:machine_ssh_info] = read_ssh_info(env)

  @app.call(env)
end

#read_ssh_info(env) ⇒ Object

Returns a hash of SSH connection information if and only if at least one IPv4 address associated with the machine in question could be retrieved Otherwise, it returns nil.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-terraform/action/read_ssh_info.rb', line 26

def read_ssh_info(env)
  machine = env[:machine]

  ip_addr = terraform_execute(env, "terraform output -raw public_ip")
  return nil if ip_addr.nil?

  return {
    :host             => ip_addr,
    :port             => machine.config.ssh.guest_port,
    :username         => machine.config.ssh.username,
    :private_key_path => machine.config.ssh.private_key_path,
    :forward_agent    => machine.config.ssh.forward_agent,
    :forward_x11      => machine.config.ssh.forward_x11,
  }
end