diff --git a/CHANGELOG.md b/CHANGELOG.md index f0c11e008..381ea92d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,8 @@ IMPROVEMENTS: - Shared folders with the same guest path will overwrite each other. No more shared folder IDs. - Shell provisioner outputs script it is running. [GH-1568] + - Automatically merge forwarded ports that share the same host + port. BUG FIXES: diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 92600b874..96f25e6c2 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -133,9 +133,21 @@ module VagrantPlugins # @param [Hash] options Options for the network. def network(type, options=nil) options ||= {} - id = options[:id] || SecureRandom.uuid + + if !options[:id] + default_id = nil + + if type == :forwarded_port + # For forwarded ports, set the default ID to the + # host port so that host ports overwrite each other. + default_id = options[:host] + end + + options[:id] = default_id || SecureRandom.uuid + end # Scope the ID by type so that different types can share IDs + id = options[:id] id = "#{type}-#{id}" # Merge in the previous settings if we have them.