Skip to content

Commit

Permalink
Merge pull request #156 from utdrmac/master
Browse files Browse the repository at this point in the history
Allow SSH Over Private IP
  • Loading branch information
erjohnso committed Nov 9, 2016
2 parents 4b245e3 + df2935e commit d84647c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -191,7 +191,8 @@ This provider exposes quite a few provider-specific configuration options:
* `tags` - An array of tags to apply to this instance.
* `zone` - The zone name where the instance will be created.
* `can_ip_forward` - Boolean whether to enable IP Forwarding.
* `external_ip` - The external IP address to use (supports names).
* `external_ip` - The external IP address to use (supports names). Set to `false` to not assign an external address.
* `use_private_ip` - Boolean whether to use private IP for SSH/provisioning. Default is false.
* `preemptible` - Boolean whether to enable preemptibility. Default is false.
* `auto_restart` - Boolean whether to enable auto_restart. Default is true.
* `on_host_maintenance` - What to do on host maintenance. Default is "MIGRATE".
Expand Down
17 changes: 15 additions & 2 deletions lib/vagrant-google/action/read_ssh_info.rb
Expand Up @@ -42,11 +42,24 @@ def read_ssh_info(google, machine)
return nil
end

# Read SSH network info
return {
# Get private_ip setting
use_private_ip = machine.provider_config.get_zone_config(zone).use_private_ip

# Default to use public ip address
ssh_info = {
:host => server.public_ip_address,
:port => 22
}

if use_private_ip then
ssh_info = {
:host => server.private_ip_address,
:port => 22
}
end

# Return SSH network info
return ssh_info
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/vagrant-google/action/run_instance.rb
Expand Up @@ -53,6 +53,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
metadata = zone_config.metadata
tags = zone_config.tags
can_ip_forward = zone_config.can_ip_forward
use_private_ip = zone_config.use_private_ip
external_ip = zone_config.external_ip
preemptible = zone_config.preemptible
auto_restart = zone_config.auto_restart
Expand All @@ -74,6 +75,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
env[:ui].info(" -- Metadata: '#{metadata}'")
env[:ui].info(" -- Tags: '#{tags}'")
env[:ui].info(" -- IP Forward: #{can_ip_forward}")
env[:ui].info(" -- Use private IP: #{use_private_ip}")
env[:ui].info(" -- External IP: #{external_ip}")
env[:ui].info(" -- Preemptible: #{preemptible}")
env[:ui].info(" -- Auto Restart: #{auto_restart}")
Expand Down Expand Up @@ -127,6 +129,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
:metadata => metadata,
:tags => tags,
:can_ip_forward => can_ip_forward,
:use_private_ip => use_private_ip,
:external_ip => external_ip,
:preemptible => preemptible,
:auto_restart => auto_restart,
Expand Down
9 changes: 9 additions & 0 deletions lib/vagrant-google/config.rb
Expand Up @@ -97,6 +97,11 @@ class Config < Vagrant.plugin("2", :config) # rubocop:disable Metrics/ClassLengt
# @return String
attr_accessor :external_ip

# Use private ip address
#
# @return Boolean
attr_accessor :use_private_ip

# whether to autodelete disk on instance delete
#
# @return Boolean
Expand Down Expand Up @@ -157,6 +162,7 @@ def initialize(zone_specific=false)
@tags = []
@can_ip_forward = UNSET_VALUE
@external_ip = UNSET_VALUE
@use_private_ip = UNSET_VALUE
@autodelete_disk = UNSET_VALUE
@preemptible = UNSET_VALUE
@auto_restart = UNSET_VALUE
Expand Down Expand Up @@ -281,6 +287,9 @@ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
# external_ip defaults to nil
@external_ip = nil if @external_ip == UNSET_VALUE

# use_private_ip defaults to false
@use_private_ip = false if @use_private_ip == UNSET_VALUE

# preemptible defaults to false
@preemptible = false if @preemptible == UNSET_VALUE

Expand Down

0 comments on commit d84647c

Please sign in to comment.