From a1a135587b51464c554c9787cad6570c3c8abfa7 Mon Sep 17 00:00:00 2001 From: Dan Danciu Date: Fri, 17 Feb 2017 01:34:21 +0200 Subject: [PATCH] #161 Allow the creation of custom (opened) TCP endpoints. --- .gitignore | 2 ++ README.md | 1 + lib/vagrant-azure/action/run_instance.rb | 7 +++++++ templates/arm/deployment.json.erb | 21 +++++++++++++++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f53167c..00a7b59 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ modules/ .ruby-version *.ps1 .env +.bundle + diff --git a/README.md b/README.md index d60ab4a..5f87429 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ For instructions on how to setup an Azure Active Directory Application see: . diff --git a/lib/vagrant-azure/action/run_instance.rb b/lib/vagrant-azure/action/run_instance.rb index 74bb7dc..84929e8 100644 --- a/lib/vagrant-azure/action/run_instance.rb +++ b/lib/vagrant-azure/action/run_instance.rb @@ -124,6 +124,13 @@ module VagrantPlugins deployment_params.merge!(windows_params) end + unless tcp_endpoints.nil? || tcp_endpoints.empty? + endpoints = tcp_endpoints.split(',') + else + endpoints = {} + end + template_params.merge!(endpoints: endpoints) + env[:ui].info(" -- Create or Update of Resource Group: #{resource_group_name}") env[:metrics]['put_resource_group'] = Util::Timer.time do put_resource_group(azure, resource_group_name, location) diff --git a/templates/arm/deployment.json.erb b/templates/arm/deployment.json.erb index fe2fc77..b0bbdf1 100644 --- a/templates/arm/deployment.json.erb +++ b/templates/arm/deployment.json.erb @@ -173,7 +173,24 @@ "direction": "Inbound" } } - <% end %> + <% end %> + <% endpoints.each_with_index do |ports, index| %> + , + { + "name": "custom_rule_<%= index %>", + "properties": { + "description": "Custom opened ports.", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "<%= ports %>", + "sourceAddressPrefix": "*", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": <%= 133 + index %>, + "direction": "Inbound" + } + } + <% end %> ] } }, @@ -319,4 +336,4 @@ } } ] -} \ No newline at end of file +}