diff --git a/CHANGELOG.md b/CHANGELOG.md index 04537e578..b4f1c8973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ IMPROVEMENTS: - Don't load plugins on any `vagrant plugin` command, so that errors are avoided. [GH-1418] + - An error will be shown if you forward a port to the same host port + multiple times. BUG FIXES: diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index bcf0ac01f..34299699c 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -1,5 +1,6 @@ require "pathname" require "securerandom" +require "set" require "vagrant" require "vagrant/config/v2/util" @@ -277,12 +278,23 @@ module VagrantPlugins # Validate networks has_fp_port_error = false + fp_host_ports = Set.new + networks.each do |type, options| if type == :forwarded_port if !has_fp_port_error && (!options[:guest] || !options[:host]) errors << I18n.t("vagrant.config.vm.network_fp_requires_ports") has_fp_port_error = true end + + if options[:host] + if fp_host_ports.include?(options[:host]) + errors << I18n.t("vagrant.config.vm.network_fp_host_not_unique", + :host => options[:host].to_s) + end + + fp_host_ports.add(options[:host]) + end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 0300b3287..ff5cb468b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -456,6 +456,8 @@ en: nfs_requires_host: |- Using NFS shared folders requires a host to be specified using `config.vagrant.host`. + network_fp_host_not_unique: |- + Forwarded port '%{host}' (host port) is declared multiple times network_fp_requires_ports: |- Forwarded port definitions require a "host" and "guest" value shared_folder_hostpath_missing: |-