knife-azure 1.8.7 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/azure_interface.rb +79 -81
  3. data/lib/azure/custom_errors.rb +34 -35
  4. data/lib/azure/helpers.rb +43 -44
  5. data/lib/azure/resource_management/ARM_deployment_template.rb +679 -678
  6. data/lib/azure/resource_management/ARM_interface.rb +513 -515
  7. data/lib/azure/resource_management/vnet_config.rb +43 -43
  8. data/lib/azure/resource_management/windows_credentials.rb +181 -184
  9. data/lib/azure/service_management/ASM_interface.rb +309 -317
  10. data/lib/azure/service_management/ag.rb +16 -16
  11. data/lib/azure/service_management/certificate.rb +30 -31
  12. data/lib/azure/service_management/connection.rb +31 -31
  13. data/lib/azure/service_management/deploy.rb +40 -38
  14. data/lib/azure/service_management/disk.rb +14 -10
  15. data/lib/azure/service_management/host.rb +28 -24
  16. data/lib/azure/service_management/image.rb +23 -22
  17. data/lib/azure/service_management/loadbalancer.rb +12 -12
  18. data/lib/azure/service_management/rest.rb +20 -19
  19. data/lib/azure/service_management/role.rb +274 -273
  20. data/lib/azure/service_management/storageaccount.rb +29 -25
  21. data/lib/azure/service_management/utility.rb +6 -7
  22. data/lib/azure/service_management/vnet.rb +44 -44
  23. data/lib/chef/knife/azure_ag_create.rb +18 -18
  24. data/lib/chef/knife/azure_ag_list.rb +3 -3
  25. data/lib/chef/knife/azure_base.rb +56 -56
  26. data/lib/chef/knife/azure_image_list.rb +8 -10
  27. data/lib/chef/knife/azure_internal-lb_create.rb +15 -15
  28. data/lib/chef/knife/azure_internal-lb_list.rb +3 -3
  29. data/lib/chef/knife/azure_server_create.rb +49 -50
  30. data/lib/chef/knife/azure_server_delete.rb +22 -24
  31. data/lib/chef/knife/azure_server_list.rb +4 -4
  32. data/lib/chef/knife/azure_server_show.rb +5 -5
  33. data/lib/chef/knife/azure_vnet_create.rb +17 -17
  34. data/lib/chef/knife/azure_vnet_list.rb +3 -3
  35. data/lib/chef/knife/azurerm_base.rb +58 -60
  36. data/lib/chef/knife/azurerm_server_create.rb +23 -22
  37. data/lib/chef/knife/azurerm_server_delete.rb +30 -34
  38. data/lib/chef/knife/azurerm_server_list.rb +42 -42
  39. data/lib/chef/knife/azurerm_server_show.rb +1 -1
  40. data/lib/chef/knife/bootstrap/bootstrap_options.rb +7 -8
  41. data/lib/chef/knife/bootstrap/bootstrapper.rb +65 -65
  42. data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +3 -4
  43. data/lib/chef/knife/bootstrap_azure.rb +13 -13
  44. data/lib/chef/knife/bootstrap_azurerm.rb +106 -106
  45. data/lib/knife-azure/version.rb +2 -2
  46. metadata +43 -76
  47. data/lib/azure/resource_management/ARM_base.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4f9a3c08e0a36f36d8120486145d30621eedaf4888e19f1ed7fe0dfaefcf70c
4
- data.tar.gz: 2495ae7f3e8c346447ab3026b58897c7b625920c94a18519431971252b102bf1
3
+ metadata.gz: 8bc419ff395adbbe39c51a8d1eaf3534df6e518026102fd3a295ea843bede060
4
+ data.tar.gz: be1a3359b55940c8f5461754eefad9fa03af780e5f46f5f51be5f87680158765
5
5
  SHA512:
6
- metadata.gz: ba99a2356113d4bda21473906b18c698d56ac24863145fe1f29bcb1e985694864a1c0ca8ce766338083f8f6f5a5a5202b03424269b2bb6d16ae4bb1b7041a4a2
7
- data.tar.gz: 6b36e5c074563b57be76ad25e921d88d1bbd227e077a5f2bbc87190c303fae69392bdc90e2d7268ba91ba1043edbeae8d1e7c356b5cd47dad41b58760fda8bfd
6
+ metadata.gz: c990a0a17420b5c9e82c4ec8350deee4f954ada8113545b51bb74775b98af8b1e8110e34c23d89ca4141902543bf1720be952aaeb4d9c5b67125bc9677bf4bb9
7
+ data.tar.gz: 1c7089b5c10bed855987c4eb794866186d9061cb3e42ea4ed95bbf6a774e1fa6ba4e8951f13ad4b6ebfb752ee35d5527d32ae7c60e8c974805ace4ed76928cc2
@@ -1,81 +1,79 @@
1
- #
2
- # Author::
3
- # Copyright:: Copyright (c) 2016 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'azure/custom_errors'
20
- require 'azure/helpers'
21
-
22
-
23
- module Azure
24
- class AzureInterface
25
- include CustomErrors
26
- include Helpers
27
-
28
- attr_accessor :ui
29
-
30
- def initialize(options = {})
31
- end
32
-
33
- def create_server(params = {})
34
- AzureInterface.api_not_implemented(self)
35
- end
36
-
37
- def list_servers
38
- AzureInterface.api_not_implemented(self)
39
- end
40
-
41
- def delete_server(server_name)
42
- AzureInterface.api_not_implemented(self)
43
- end
44
-
45
- def list_images
46
- AzureInterface.api_not_implemented(self)
47
- end
48
-
49
- def show_server(server_name, resource_group = "")
50
- AzureInterface.api_not_implemented(self)
51
- end
52
-
53
- def create_vnet(params = {})
54
- AzureInterface.api_not_implemented(self)
55
- end
56
-
57
- def list_vnets
58
- AzureInterface.api_not_implemented(self)
59
- end
60
-
61
- def list_internal_lb
62
- AzureInterface.api_not_implemented(self)
63
- end
64
-
65
- def create_internal_lb(params = {})
66
- AzureInterface.api_not_implemented(self)
67
- end
68
-
69
- def list_affinity_groups
70
- AzureInterface.api_not_implemented(self)
71
- end
72
-
73
- def create_affinity_group(params = {})
74
- AzureInterface.api_not_implemented(self)
75
- end
76
-
77
- def find_server(server_name)
78
- AzureInterface.api_not_implemented(self)
79
- end
80
- end
81
- end
1
+ #
2
+ # Copyright:: Copyright 2016-2018 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "azure/custom_errors"
19
+ require "azure/helpers"
20
+
21
+ module Azure
22
+ class AzureInterface
23
+ include CustomErrors
24
+ include Helpers
25
+
26
+ attr_accessor :ui
27
+
28
+ def initialize(options = {})
29
+ end
30
+
31
+ def create_server(params = {})
32
+ AzureInterface.api_not_implemented(self)
33
+ end
34
+
35
+ def list_servers
36
+ AzureInterface.api_not_implemented(self)
37
+ end
38
+
39
+ def delete_server(server_name)
40
+ AzureInterface.api_not_implemented(self)
41
+ end
42
+
43
+ def list_images
44
+ AzureInterface.api_not_implemented(self)
45
+ end
46
+
47
+ def show_server(server_name, resource_group = "")
48
+ AzureInterface.api_not_implemented(self)
49
+ end
50
+
51
+ def create_vnet(params = {})
52
+ AzureInterface.api_not_implemented(self)
53
+ end
54
+
55
+ def list_vnets
56
+ AzureInterface.api_not_implemented(self)
57
+ end
58
+
59
+ def list_internal_lb
60
+ AzureInterface.api_not_implemented(self)
61
+ end
62
+
63
+ def create_internal_lb(params = {})
64
+ AzureInterface.api_not_implemented(self)
65
+ end
66
+
67
+ def list_affinity_groups
68
+ AzureInterface.api_not_implemented(self)
69
+ end
70
+
71
+ def create_affinity_group(params = {})
72
+ AzureInterface.api_not_implemented(self)
73
+ end
74
+
75
+ def find_server(server_name)
76
+ AzureInterface.api_not_implemented(self)
77
+ end
78
+ end
79
+ end
@@ -1,35 +1,34 @@
1
- #
2
- # Author::
3
- # Copyright:: Copyright (c) 2016 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- module CustomErrors
20
- class InterfaceNotImplementedError < NoMethodError
21
- end
22
-
23
- def self.included(klass)
24
- klass.send(:include, CustomErrors::Methods)
25
- klass.send(:extend, CustomErrors::Methods)
26
- end
27
-
28
- module Methods
29
- def api_not_implemented(klass)
30
- caller.first.match(/in \`(.+)\'/)
31
- method_name = $1
32
- raise CustomErrors::InterfaceNotImplementedError.new("#{klass.class.name} needs to implement '#{method_name}' for interface #{self.name}!")
33
- end
34
- end
35
- end
1
+ #
2
+ # Copyright:: Copyright 2016-2018 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module CustomErrors
19
+ class InterfaceNotImplementedError < NoMethodError
20
+ end
21
+
22
+ def self.included(klass)
23
+ klass.send(:include, CustomErrors::Methods)
24
+ klass.send(:extend, CustomErrors::Methods)
25
+ end
26
+
27
+ module Methods
28
+ def api_not_implemented(klass)
29
+ caller.first =~ /in \`(.+)\'/
30
+ method_name = $1
31
+ raise CustomErrors::InterfaceNotImplementedError.new("#{klass.class.name} needs to implement '#{method_name}' for interface #{name}!")
32
+ end
33
+ end
34
+ end
@@ -1,44 +1,43 @@
1
- #
2
- # Author:: vasundhara.jagdale@clogeny.com
3
- # Copyright:: Copyright (c) 2016 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- module Azure
20
- module Helpers
21
-
22
- def random_string(len=10)
23
- (0...len).map{65.+(rand(25)).chr}.join
24
- end
25
-
26
- def strip_non_ascii(string)
27
- string.gsub(/[^0-9a-z ]/i, '')
28
- end
29
-
30
- def display_list(ui=nil, columns=[], rows=[])
31
- columns = columns.map{ |col| ui.color(col, :bold) }
32
- count = columns.count
33
- rows = columns.concat(rows)
34
- puts ''
35
- puts ui.list(rows, :uneven_columns_across, count)
36
- end
37
-
38
- def msg_pair(ui=nil, label=nil, value=nil, color=:cyan)
39
- if value && !value.to_s.empty?
40
- puts "#{ui.color(label, color)}: #{value}"
41
- end
42
- end
43
- end
44
- end
1
+ #
2
+ # Author:: vasundhara.jagdale@clogeny.com
3
+ # Copyright:: Copyright 2016-2018 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module Azure
20
+ module Helpers
21
+ def random_string(len = 10)
22
+ (0...len).map { 65.+(rand(25)).chr }.join
23
+ end
24
+
25
+ def strip_non_ascii(string)
26
+ string.gsub(/[^0-9a-z ]/i, "")
27
+ end
28
+
29
+ def display_list(ui = nil, columns = [], rows = [])
30
+ columns = columns.map { |col| ui.color(col, :bold) }
31
+ count = columns.count
32
+ rows = columns.concat(rows)
33
+ puts ""
34
+ puts ui.list(rows, :uneven_columns_across, count)
35
+ end
36
+
37
+ def msg_pair(ui = nil, label = nil, value = nil, color = :cyan)
38
+ if value && !value.to_s.empty?
39
+ puts "#{ui.color(label, color)}: #{value}"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,678 +1,679 @@
1
- #
2
- # Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
3
- # Copyright:: Copyright (c) 2015-2016 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- module Azure::ARM
20
- module ARMDeploymentTemplate
21
-
22
- def ohai_hints(hint_names, resource_ids)
23
- hints_json = {}
24
-
25
- hint_names.each do |hint_name|
26
- case hint_name
27
- when 'vm_name'
28
- hints_json['vm_name'] = "[reference(#{resource_ids['vmId']}).osProfile.computerName]" if !hints_json.has_key? 'vm_name'
29
- when 'public_fqdn'
30
- hints_json['public_fqdn'] = "[reference(#{resource_ids['pubId']}).dnsSettings.fqdn]" if !hints_json.has_key? 'public_fqdn'
31
- when 'platform'
32
- hints_json['platform'] = "[concat(reference(#{resource_ids['vmId']}).storageProfile.imageReference.offer, concat(' ', reference(#{resource_ids['vmId']}).storageProfile.imageReference.sku))]" if !hints_json.has_key? 'platform'
33
- end
34
- end
35
-
36
- hints_json
37
- end
38
-
39
- def tcp_ports(tcp_ports, vm_name)
40
- tcp_ports = tcp_ports.split(",")
41
- sec_grp_json =
42
- {
43
- "apiVersion" => "[variables('apiVersion')]",
44
- "type" => "Microsoft.Network/networkSecurityGroups",
45
- "name" => "[variables('secgrpname')]",
46
- "location" => "[resourceGroup().location]",
47
- "properties" => {
48
- "securityRules" => [
49
- ]
50
- }
51
- }
52
- #Security Rule priority can be set between 100 and 4096
53
- rule_no = 300
54
- incremental=0
55
- for port in tcp_ports
56
- rule_no = rule_no + 2
57
- sec_grp_json["properties"]["securityRules"].push(
58
- {
59
- "name" => vm_name + '_rule_' + incremental.to_s,
60
- "properties"=> {
61
- "description" => "Port Provided by user",
62
- "protocol" => "Tcp",
63
- "sourcePortRange" => "*",
64
- "destinationPortRange" => port,
65
- "sourceAddressPrefix" => "*",
66
- "destinationAddressPrefix" => "*",
67
- "access" => "Allow",
68
- "priority" => rule_no,
69
- "direction" => "Inbound"
70
- }
71
- }
72
- )
73
- incremental=incremental+1
74
- end
75
- sec_grp_json
76
- end
77
-
78
- def create_deployment_template(params)
79
- if params[:chef_extension_public_param][:bootstrap_options][:chef_node_name]
80
- chef_node_name = "[concat(parameters('chef_node_name'),copyIndex())]"
81
- chef_node_name = "[parameters('chef_node_name')]" if params[:server_count].to_i==1
82
- end
83
-
84
- if(params[:server_count].to_i > 1)
85
- # publicIPAddresses Resource Variables
86
- publicIPAddressName = "[concat(variables('publicIPAddressName'),copyIndex())]"
87
- domainNameLabel = "[concat(parameters('dnsLabelPrefix'), copyIndex())]"
88
-
89
- # networkInterfaces Resource Variables
90
- nicName = "[concat(variables('nicName'),copyIndex())]"
91
- depNic1 = "[concat('Microsoft.Network/publicIPAddresses/', concat(variables('publicIPAddressName'),copyIndex()))]"
92
- pubId = "[resourceId('Microsoft.Network/publicIPAddresses',concat(variables('publicIPAddressName'),copyIndex()))]"
93
-
94
- # virtualMachines Resource Variables
95
- vmName = "[concat(variables('vmName'),copyIndex())]"
96
- vmId = "[resourceId('Microsoft.Compute/virtualMachines', concat(variables('vmName'),copyIndex()))]"
97
- depVm2="[concat('Microsoft.Network/networkInterfaces/', variables('nicName'), copyIndex())]"
98
- computerName = "[concat(variables('vmName'),copyIndex())]"
99
- uri = "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',concat(variables('vmName'),copyIndex()),'.vhd')]"
100
- netid = "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nicName'), copyIndex()))]"
101
-
102
- # Extension Variables
103
- extName = "[concat(variables('vmName'),copyIndex(),'/', variables('vmExtensionName'))]"
104
- depExt = "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'), copyIndex())]"
105
-
106
- else
107
- # publicIPAddresses Resource Variables
108
- publicIPAddressName = "[variables('publicIPAddressName')]"
109
- domainNameLabel = "[parameters('dnsLabelPrefix')]"
110
-
111
- # networkInterfaces Resource Variables
112
- nicName = "[concat(variables('nicName'))]"
113
- depNic1 = "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
114
- pubId = "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
115
-
116
- # virtualMachines Resource Variables
117
- vmName = "[variables('vmName')]"
118
- vmId = "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
119
- depVm2="[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
120
- computerName = "[variables('vmName')]"
121
- uri = "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('vmName'),'.vhd')]"
122
- netid = "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
123
-
124
- # Extension Variables
125
- extName = "[concat(variables('vmName'),'/', variables('vmExtensionName'))]"
126
- depExt = "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
127
- end
128
-
129
- # NetworkSecurityGroups Resource Variables
130
- sec_grp_name = "[variables('secgrpname')]"
131
- sec_grp = "[concat('Microsoft.Network/networkSecurityGroups/', variables('secgrpname'))]"
132
- sec_grp_id = "[resourceId('Microsoft.Network/networkSecurityGroups/', variables('secgrpname'))]"
133
-
134
- resource_ids = {}
135
- hint_names = params[:chef_extension_public_param][:hints]
136
-
137
- hint_names.each do |hint_name|
138
- case hint_name
139
- when 'public_fqdn'
140
- resource_ids['pubId'] = pubId.gsub('[','').gsub(']','') if !resource_ids.has_key? 'pubId'
141
- when 'vm_name', 'platform'
142
- resource_ids['vmId'] = vmId.gsub('[','').gsub(']','') if !resource_ids.has_key? 'vmId'
143
- end
144
- end
145
-
146
- hints_json = ohai_hints(hint_names, resource_ids)
147
-
148
- template = {
149
- "$schema"=> "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
150
- "contentVersion"=> "1.0.0.0",
151
- "parameters"=> {
152
- "adminUserName"=> {
153
- "type"=> "string",
154
- "metadata"=> {
155
- "description"=> "User name for the Virtual Machine."
156
- }
157
- },
158
- "adminPassword"=> {
159
- "type"=> "securestring",
160
- "metadata"=> {
161
- "description"=> "Password for the Virtual Machine."
162
- }
163
- },
164
- "availabilitySetName" => {
165
- "type" => "string"
166
- },
167
- "availabilitySetPlatformFaultDomainCount" => {
168
- "type" => "string"
169
- },
170
- "availabilitySetPlatformUpdateDomainCount" => {
171
- "type" => "string"
172
- },
173
- "numberOfInstances" => {
174
- "type" => "int",
175
- "defaultValue" => 1,
176
- "metadata" => {
177
- "description" => "Number of VM instances to create. Default is 1"
178
- }
179
- },
180
- "dnsLabelPrefix"=> {
181
- "type"=> "string",
182
- "metadata"=> {
183
- "description"=> "Unique DNS Name for the Public IP used to access the Virtual Machine."
184
- }
185
- },
186
- "imageSKU"=> {
187
- "type"=> "string",
188
- "metadata"=> {
189
- "description"=> "Version of the image"
190
- }
191
- },
192
- "imageVersion" => {
193
- "type"=> "string",
194
- "defaultValue" => "latest",
195
- "metadata" => {
196
- "description" => "Azure image reference version."
197
- }
198
- },
199
- "validation_key" => {
200
- "type"=> "string",
201
- "metadata"=> {
202
- "description"=> "JSON Escaped Validation Key"
203
- }
204
- },
205
-
206
- "chef_server_crt" => {
207
- "type"=> "string",
208
- "metadata"=> {
209
- "description"=> "Optional. SSL cerificate provided by user."
210
- }
211
- },
212
- "chef_server_url"=> {
213
- "type"=> "string",
214
- "metadata"=> {
215
- "description"=> "Organization URL for the Chef Server. Example https://ChefServerDnsName.cloudapp.net/organizations/Orgname"
216
- }
217
- },
218
- "validation_client_name"=> {
219
- "type"=> "string",
220
- "metadata"=> {
221
- "description"=> "Validator key name for the organization. Example : MyOrg-validator"
222
- }
223
- },
224
- "runlist"=> {
225
- "type"=> "string",
226
- "metadata"=> {
227
- "description"=> "Optional Run List to Execute"
228
- }
229
- },
230
- "environment"=> {
231
- "type"=> "string",
232
- "metadata"=> {
233
- "description"=> "Chef environment for the node (VM) in the Chef Organization"
234
- }
235
- },
236
- "chef_node_name" => {
237
- "type" => "string",
238
- "metadata" => {
239
- "description" => "The name for the node (VM) in the Chef Organization"
240
- }
241
- },
242
- "validation_key_format" => {
243
- "type"=> "string",
244
- "allowedValues"=> ["plaintext", "base64encoded"],
245
- "defaultValue"=> "plaintext",
246
- "metadata" => {
247
- "description"=> "Format in which Validation Key is given. e.g. plaintext, base64encoded"
248
- }
249
- },
250
- "client_rb" => {
251
- "type" => "string",
252
- "metadata" => {
253
- "description" => "Optional. Path to a client.rb file for use by the bootstrapped node."
254
- }
255
- },
256
- "bootstrap_version" => {
257
- "type" => "string",
258
- "metadata" => {
259
- "description" => "Optional. The version of Chef to install."
260
- }
261
- },
262
- "custom_json_attr" => {
263
- "type" => "string",
264
- "metadata" => {
265
- "description" => "Optional. A JSON string to be added to the first run of chef-client."
266
- }
267
- },
268
- "node_ssl_verify_mode" => {
269
- "type" => "string",
270
- "metadata" => {
271
- "description" => "Optional. Whether or not to verify the SSL cert for all HTTPS requests."
272
- }
273
- },
274
- "node_verify_api_cert" => {
275
- "type" => "string",
276
- "metadata" => {
277
- "description" => "Optional. Verify the SSL cert for HTTPS requests to the Chef server API."
278
- }
279
- },
280
- "encrypted_data_bag_secret" => {
281
- "type" => "string",
282
- "metadata" => {
283
- "description" => "Optional. The secret key to use to encrypt data bag item values."
284
- }
285
- },
286
- "bootstrap_proxy" => {
287
- "type" => "string",
288
- "metadata" => {
289
- "description" => "Optional. The proxy server for the node being bootstrapped."
290
- }
291
- },
292
- "sshKeyData" => {
293
- "type" => "string",
294
- "metadata" => {
295
- "description" => "SSH rsa public key file as a string."
296
- }
297
- },
298
- "disablePasswordAuthentication" => {
299
- "type" => "string",
300
- "metadata" => {
301
- "description" => "Set to true if using ssh key for authentication."
302
- }
303
- }
304
- },
305
- "variables"=> {
306
- "storageAccountName"=> "[concat(uniquestring(resourceGroup().id), '#{params[:azure_storage_account]}')]",
307
- "imagePublisher"=> "#{params[:azure_image_reference_publisher]}",
308
- "imageOffer"=> "#{params[:azure_image_reference_offer]}",
309
- "OSDiskName"=> "#{params[:azure_os_disk_name]}",
310
- "nicName"=> "#{params[:azure_vm_name]}",
311
- "subnetName"=> "#{params[:azure_vnet_subnet_name]}",
312
- "storageAccountType"=> "#{params[:azure_storage_account_type]}",
313
- "publicIPAddressName"=> "#{params[:azure_vm_name]}",
314
- "publicIPAddressType"=> "Dynamic",
315
- "vmStorageAccountContainerName"=> "#{params[:azure_vm_name]}",
316
- "vmName"=> "#{params[:azure_vm_name]}",
317
- "vmSize"=> "#{params[:vm_size]}",
318
- "virtualNetworkName"=> "#{params[:vnet_config][:virtualNetworkName]}",
319
- "secgrpname" => "#{params[:azure_sec_group_name]}",
320
- "vnetID"=> "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
321
- "subnetRef"=> "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
322
- "apiVersion"=> "2015-06-15",
323
- "vmExtensionName"=> "#{params[:chef_extension]}",
324
- "sshKeyPath" => "[concat('/home/',parameters('adminUserName'),'/.ssh/authorized_keys')]"
325
- },
326
- "resources"=> [
327
- {
328
- "type"=> "Microsoft.Storage/storageAccounts",
329
- "name"=> "[variables('storageAccountName')]",
330
- "apiVersion"=> "[variables('apiVersion')]",
331
- "location"=> "[resourceGroup().location]",
332
- "properties"=> {
333
- "accountType"=> "[variables('storageAccountType')]"
334
- }
335
- },
336
- {
337
- "apiVersion"=> "[variables('apiVersion')]",
338
- "type" => "Microsoft.Network/publicIPAddresses",
339
- "name" => publicIPAddressName,
340
- "location"=> "[resourceGroup().location]",
341
- "copy"=> {
342
- "name" => "publicIPLoop",
343
- "count"=> "[parameters('numberOfInstances')]"
344
- },
345
- "properties" => {
346
- "publicIPAllocationMethod" => "[variables('publicIPAddressType')]",
347
- "dnsSettings" => {
348
- "domainNameLabel" => domainNameLabel
349
- }
350
- }
351
- },
352
- {
353
- "apiVersion"=> "[variables('apiVersion')]",
354
- "type"=> "Microsoft.Network/virtualNetworks",
355
- "name"=> "[variables('virtualNetworkName')]",
356
- "location"=> "[resourceGroup().location]",
357
- "properties"=> {
358
- "addressSpace"=> {
359
- "addressPrefixes"=> params[:vnet_config][:addressPrefixes]
360
- },
361
- "subnets"=> params[:vnet_config][:subnets]
362
- }
363
- },
364
- {
365
- "apiVersion"=> "[variables('apiVersion')]",
366
- "type"=> "Microsoft.Network/networkInterfaces",
367
- "name"=> nicName,
368
- "location"=> "[resourceGroup().location]",
369
- "copy" => {
370
- "name" => "nicLoop",
371
- "count" => "[parameters('numberOfInstances')]"
372
- },
373
- "dependsOn" => [
374
- depNic1,
375
- "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
376
- ],
377
- "properties"=> {
378
- "ipConfigurations"=> [
379
- {
380
- "name"=> "ipconfig1",
381
- "properties"=> {
382
- "privateIPAllocationMethod"=> "Dynamic",
383
- "publicIPAddress"=> {
384
- "id"=> pubId
385
- },
386
- "subnet"=> {
387
- "id"=> "[variables('subnetRef')]"
388
- }
389
- }
390
- }
391
- ]
392
- }
393
- },
394
- {
395
- "apiVersion"=> "[variables('apiVersion')]",
396
- "type"=> "Microsoft.Compute/virtualMachines",
397
- "name"=> vmName,
398
- "location"=> "[resourceGroup().location]",
399
- "copy" => {
400
- "name" => "vmLoop",
401
- "count" => "[parameters('numberOfInstances')]"
402
- },
403
- "dependsOn"=> [
404
- "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
405
- depVm2,
406
- ],
407
- "properties"=> {
408
- "hardwareProfile"=> {
409
- "vmSize"=> "[variables('vmSize')]"
410
- },
411
- "osProfile"=> {
412
- "computerName"=> computerName,
413
- "adminUserName"=> "[parameters('adminUserName')]",
414
- "adminPassword"=> "[parameters('adminPassword')]",
415
- "linuxConfiguration" => ( {
416
- "disablePasswordAuthentication" => "[parameters('disablePasswordAuthentication')]",
417
- "ssh" => {
418
- "publicKeys" => [ {
419
- "path" => "[variables('sshKeyPath')]",
420
- "keyData" => "[parameters('sshKeyData')]"
421
- } ]
422
- }
423
- } if params[:disablePasswordAuthentication] == "true")
424
- },
425
- "storageProfile"=> {
426
- "imageReference"=> {
427
- "publisher"=> "[variables('imagePublisher')]",
428
- "offer"=> "[variables('imageOffer')]",
429
- "sku"=> "[parameters('imageSKU')]",
430
- "version"=> "[parameters('imageVersion')]"
431
- },
432
- "osDisk"=> {
433
- "name"=> "[variables('OSDiskName')]",
434
- "vhd"=> {
435
- "uri"=> uri },
436
- "caching"=> "ReadWrite",
437
- "createOption"=> "FromImage"
438
- }
439
- },
440
- "networkProfile"=> {
441
- "networkInterfaces"=> [
442
- {
443
- "id"=> netid
444
- }
445
- ]
446
- },
447
- "diagnosticsProfile"=> {
448
- "bootDiagnostics"=> {
449
- "enabled"=> "true",
450
- "storageUri"=> "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]"
451
- }
452
- }
453
- }
454
- },
455
- {
456
- "type" => "Microsoft.Compute/virtualMachines/extensions",
457
- "name" => extName,
458
- "apiVersion" => "2015-05-01-preview",
459
- "location" => "[resourceGroup().location]",
460
- "copy" => {
461
- "name" => "extensionLoop",
462
- "count" => "[parameters('numberOfInstances')]"
463
- },
464
- "dependsOn" => [
465
- depExt
466
- ],
467
- "properties" => {
468
- "publisher" => "#{params[:chef_extension_publisher]}",
469
- "type" => "#{params[:chef_extension]}",
470
- "typeHandlerVersion" => "#{params[:chef_extension_version]}",
471
- "autoUpgradeMinorVersion" => "#{params[:auto_upgrade_minor_version]}",
472
- "settings" => {
473
- "bootstrap_version" => "[parameters('bootstrap_version')]",
474
- "bootstrap_options" => {
475
- "chef_node_name" => chef_node_name,
476
- "chef_server_url" => "[parameters('chef_server_url')]",
477
- "validation_client_name" => "[parameters('validation_client_name')]",
478
- "node_ssl_verify_mode" => "[parameters('node_ssl_verify_mode')]",
479
- "node_verify_api_cert" => "[parameters('node_verify_api_cert')]",
480
- "bootstrap_proxy" => "[parameters('bootstrap_proxy')]",
481
- "environment" => "[parameters('environment')]"
482
- },
483
- "runlist" => "[parameters('runlist')]",
484
- "validation_key_format" => "[parameters('validation_key_format')]",
485
- "hints" => hints_json,
486
- "client_rb" => "[parameters('client_rb')]",
487
- "custom_json_attr" => "[parameters('custom_json_attr')]"
488
- },
489
- "protectedSettings" => {
490
- "validation_key" => "[parameters('validation_key')]",
491
- "chef_server_crt" => "[parameters('chef_server_crt')]",
492
- "encrypted_data_bag_secret" => "[parameters('encrypted_data_bag_secret')]"
493
- }
494
- }
495
- }
496
- ]
497
- }
498
-
499
- if params[:azure_availability_set]
500
- set_val = {
501
- "name" => "[parameters('availabilitySetName')]",
502
- "type" => "Microsoft.Compute/availabilitySets",
503
- "apiVersion" => "[variables('apiVersion')]",
504
- "location" => "[resourceGroup().location]",
505
- "properties" => {
506
- "platformFaultDomainCount" => "[parameters('availabilitySetPlatformFaultDomainCount')]",
507
- "platformUpdateDomainCount" => "[parameters('availabilitySetPlatformUpdateDomainCount')]"
508
- }
509
- }
510
-
511
- length = template['resources'].length.to_i - 1
512
- for i in 0..length do
513
- if template['resources'][i]['type'] == "Microsoft.Compute/virtualMachines"
514
- template['resources'][i]['dependsOn'] << "[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]"
515
- template['resources'][i]['properties'].merge!({"availabilitySet" => { "id" => "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySetName'))]"}})
516
- end
517
- end
518
- template['resources'].insert(length, set_val)
519
- end
520
-
521
- if params[:tcp_endpoints]
522
- sec_grp_json = tcp_ports(params[:tcp_endpoints], params[:azure_vm_name])
523
- template['resources'].insert(1,sec_grp_json)
524
- length = template['resources'].length.to_i - 1
525
- for i in 0..length do
526
- if template['resources'][i]['type'] == "Microsoft.Network/virtualNetworks"
527
- template['resources'][i] = template['resources'][i].merge({"dependsOn" => [sec_grp]})
528
- end
529
- if template['resources'][i]['type'] == "Microsoft.Network/networkInterfaces"
530
- template['resources'][i]['properties'] = template['resources'][i]['properties'].merge({"networkSecurityGroup" => {"id" => sec_grp_id}})
531
- end
532
- end
533
- end
534
-
535
- if params[:chef_extension_public_param][:extendedLogs] == "true"
536
- template['resources'].each do |resource|
537
- if resource['type'] == 'Microsoft.Compute/virtualMachines/extensions'
538
- resource['properties']['settings']['extendedLogs'] = params[:chef_extension_public_param][:extendedLogs]
539
- end
540
- end
541
- end
542
-
543
- if params[:chef_extension_public_param][:chef_daemon_interval]
544
- template['resources'].each do |resource|
545
- if resource['type'] == 'Microsoft.Compute/virtualMachines/extensions'
546
- resource['properties']['settings']['chef_daemon_interval'] = params[:chef_extension_public_param][:chef_daemon_interval]
547
- end
548
- end
549
- end
550
-
551
- if params[:chef_extension_public_param][:daemon]
552
- template['resources'].each do |resource|
553
- if resource['type'] == 'Microsoft.Compute/virtualMachines/extensions'
554
- resource['properties']['settings']['daemon'] = params[:chef_extension_public_param][:daemon]
555
- end
556
- end
557
- end
558
- if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
559
- template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters(concat('client_pem',copyIndex()))]"
560
- 0.upto (params[:server_count].to_i-1) do |count|
561
- template["parameters"]["client_pem" + count.to_s] = {
562
- "type"=> "string",
563
- "metadata"=> {
564
- "description"=> "Required for validtorless bootstrap."
565
- }
566
- }
567
- end
568
- else
569
- template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters('client_pem')]"
570
- template["parameters"]["client_pem"] = {
571
- "type"=> "string",
572
- "metadata"=> {
573
- "description"=> "Required for validtorless bootstrap."
574
- }
575
- }
576
- end
577
- template
578
- end
579
-
580
- def create_deployment_parameters(params, platform)
581
- if platform == 'Windows'
582
- admin_user = params[:winrm_user]
583
- admin_password = params[:admin_password]
584
- else
585
- admin_user = params[:ssh_user]
586
- admin_password = params[:ssh_password]
587
- end
588
-
589
- parameters = {
590
- "adminUserName" => {
591
- "value" => "#{admin_user}"
592
- },
593
- "adminPassword"=> {
594
- "value"=> "#{admin_password}"
595
- },
596
- "availabilitySetName" => {
597
- "value" => "#{params[:azure_availability_set]}"
598
- },
599
- "availabilitySetPlatformFaultDomainCount" => {
600
- "value" => "2"
601
- },
602
- "availabilitySetPlatformUpdateDomainCount" => {
603
- "value" => "5"
604
- },
605
- "dnsLabelPrefix"=> {
606
- "value"=> "#{params[:azure_vm_name]}"
607
- },
608
- "imageSKU"=> {
609
- "value"=> "#{params[:azure_image_reference_sku]}"
610
- },
611
- "numberOfInstances" => {
612
- "value" => "#{params[:server_count]}".to_i
613
- },
614
- "validation_key"=> {
615
- "value"=> "#{params[:chef_extension_private_param][:validation_key]}"
616
- },
617
-
618
- "chef_server_crt" => {
619
- "value" => "#{params[:chef_extension_private_param][:chef_server_crt]}"
620
- },
621
- "encrypted_data_bag_secret" => {
622
- "value" => "#{params[:chef_extension_private_param][:encrypted_data_bag_secret]}"
623
- },
624
- "chef_server_url"=> {
625
- "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:chef_server_url]}"
626
- },
627
- "validation_client_name"=> {
628
- "value"=> "#{params[:chef_extension_public_param][:bootstrap_options][:validation_client_name]}"
629
- },
630
- "node_ssl_verify_mode" => {
631
- "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:node_ssl_verify_mode]}"
632
- },
633
- "node_verify_api_cert" => {
634
- "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:node_verify_api_cert]}"
635
- },
636
- "bootstrap_proxy" => {
637
- "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:bootstrap_proxy]}"
638
- },
639
- "runlist" => {
640
- "value" => "#{params[:chef_extension_public_param][:runlist]}"
641
- },
642
- "environment" => {
643
- "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:environment]}"
644
- },
645
- "chef_node_name" => {
646
- "value"=> "#{params[:chef_extension_public_param][:bootstrap_options][:chef_node_name]}"
647
- },
648
- "client_rb" => {
649
- "value" => "#{params[:chef_extension_public_param][:client_rb]}"
650
- },
651
- "bootstrap_version" => {
652
- "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:bootstrap_version]}"
653
- },
654
- "custom_json_attr" => {
655
- "value" => "#{params[:chef_extension_public_param][:custom_json_attr]}"
656
- },
657
- "sshKeyData" => {
658
- "value" => "#{params[:ssh_key]}"
659
- },
660
- "disablePasswordAuthentication" => {
661
- "value" => "#{params[:disablePasswordAuthentication]}"
662
- }
663
- }
664
- if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
665
- 0.upto (params[:server_count].to_i-1) do |count|
666
- parameters["client_pem#{count.to_s}"] = {
667
- "value" => "#{params[:chef_extension_private_param][("client_pem" + count.to_s).to_sym]}"
668
- }
669
- end
670
- else
671
- parameters["client_pem"] = {
672
- "value" => "#{params[:chef_extension_private_param][:client_pem]}"
673
- }
674
- end
675
- parameters
676
- end
677
- end
678
- end
1
+ #
2
+ # Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
3
+ # Copyright:: Copyright 2015-2018 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module Azure::ARM
20
+ module ARMDeploymentTemplate
21
+ def ohai_hints(hint_names, resource_ids)
22
+ hints_json = {}
23
+
24
+ hint_names.each do |hint_name|
25
+ case hint_name
26
+ when "vm_name"
27
+ hints_json["vm_name"] = "[reference(#{resource_ids['vmId']}).osProfile.computerName]" if !hints_json.has_key? "vm_name"
28
+ when "public_fqdn"
29
+ hints_json["public_fqdn"] = "[reference(#{resource_ids['pubId']}).dnsSettings.fqdn]" if !hints_json.has_key? "public_fqdn"
30
+ when "platform"
31
+ hints_json["platform"] = "[concat(reference(#{resource_ids['vmId']}).storageProfile.imageReference.offer, concat(' ', reference(#{resource_ids['vmId']}).storageProfile.imageReference.sku))]" if !hints_json.has_key? "platform"
32
+ end
33
+ end
34
+
35
+ hints_json
36
+ end
37
+
38
+ def tcp_ports(tcp_ports, vm_name)
39
+ tcp_ports = tcp_ports.split(",")
40
+ sec_grp_json =
41
+ {
42
+ "apiVersion" => "[variables('apiVersion')]",
43
+ "type" => "Microsoft.Network/networkSecurityGroups",
44
+ "name" => "[variables('secgrpname')]",
45
+ "location" => "[resourceGroup().location]",
46
+ "properties" => {
47
+ "securityRules" => [
48
+ ]
49
+ }
50
+ }
51
+ # Security Rule priority can be set between 100 and 4096
52
+ rule_no = 300
53
+ incremental = 0
54
+ for port in tcp_ports
55
+ rule_no += 2
56
+ sec_grp_json["properties"]["securityRules"].push(
57
+ "name" => vm_name + "_rule_" + incremental.to_s,
58
+ "properties" => {
59
+ "description" => "Port Provided by user",
60
+ "protocol" => "Tcp",
61
+ "sourcePortRange" => "*",
62
+ "destinationPortRange" => port,
63
+ "sourceAddressPrefix" => "*",
64
+ "destinationAddressPrefix" => "*",
65
+ "access" => "Allow",
66
+ "priority" => rule_no,
67
+ "direction" => "Inbound"
68
+ }
69
+ )
70
+ incremental += 1
71
+ end
72
+ sec_grp_json
73
+ end
74
+
75
+ def create_deployment_template(params)
76
+ if params[:chef_extension_public_param][:bootstrap_options][:chef_node_name]
77
+ chef_node_name = "[concat(parameters('chef_node_name'),copyIndex())]"
78
+ chef_node_name = "[parameters('chef_node_name')]" if params[:server_count].to_i == 1
79
+ end
80
+
81
+ if params[:server_count].to_i > 1
82
+ # publicIPAddresses Resource Variables
83
+ publicIPAddressName = "[concat(variables('publicIPAddressName'),copyIndex())]"
84
+ domainNameLabel = "[concat(parameters('dnsLabelPrefix'), copyIndex())]"
85
+
86
+ # networkInterfaces Resource Variables
87
+ nicName = "[concat(variables('nicName'),copyIndex())]"
88
+ depNic1 = "[concat('Microsoft.Network/publicIPAddresses/', concat(variables('publicIPAddressName'),copyIndex()))]"
89
+ pubId = "[resourceId('Microsoft.Network/publicIPAddresses',concat(variables('publicIPAddressName'),copyIndex()))]"
90
+
91
+ # virtualMachines Resource Variables
92
+ vmName = "[concat(variables('vmName'),copyIndex())]"
93
+ vmSize = "[concat(variables('vmSize'),copyIndex())]"
94
+ vmId = "[resourceId('Microsoft.Compute/virtualMachines', concat(variables('vmName'),copyIndex()))]"
95
+ depVm2 = "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'), copyIndex())]"
96
+ computerName = "[concat(variables('vmName'),copyIndex())]"
97
+ uri = "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',concat(variables('vmName'),copyIndex()),'.vhd')]"
98
+ netid = "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nicName'), copyIndex()))]"
99
+
100
+ # Extension Variables
101
+ extName = "[concat(variables('vmName'),copyIndex(),'/', variables('vmExtensionName'))]"
102
+ depExt = "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'), copyIndex())]"
103
+
104
+ else
105
+ # publicIPAddresses Resource Variables
106
+ publicIPAddressName = "[variables('publicIPAddressName')]"
107
+ domainNameLabel = "[parameters('dnsLabelPrefix')]"
108
+
109
+ # networkInterfaces Resource Variables
110
+ nicName = "[concat(variables('nicName'))]"
111
+ depNic1 = "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
112
+ pubId = "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
113
+
114
+ # virtualMachines Resource Variables
115
+ vmName = "[variables('vmName')]"
116
+ vmSize = "[variables('vmSize')]"
117
+ vmId = "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
118
+ depVm2 = "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
119
+ computerName = "[variables('vmName')]"
120
+ uri = "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('vmName'),'.vhd')]"
121
+ netid = "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
122
+
123
+ # Extension Variables
124
+ extName = "[concat(variables('vmName'),'/', variables('vmExtensionName'))]"
125
+ depExt = "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
126
+ end
127
+
128
+ # NetworkSecurityGroups Resource Variables
129
+ sec_grp_name = "[variables('secgrpname')]"
130
+ sec_grp = "[concat('Microsoft.Network/networkSecurityGroups/', variables('secgrpname'))]"
131
+ sec_grp_id = "[resourceId('Microsoft.Network/networkSecurityGroups/', variables('secgrpname'))]"
132
+
133
+ resource_ids = {}
134
+ hint_names = params[:chef_extension_public_param][:hints]
135
+
136
+ hint_names.each do |hint_name|
137
+ case hint_name
138
+ when "public_fqdn"
139
+ resource_ids["pubId"] = pubId.delete("[").delete("]") unless resource_ids.key? "pubId"
140
+ when "vm_name", "platform"
141
+ resource_ids["vmId"] = vmId.delete("[").delete("]") unless resource_ids.key? "vmId"
142
+ end
143
+ end
144
+
145
+ hints_json = ohai_hints(hint_names, resource_ids)
146
+
147
+ template = {
148
+ "$schema" => "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
149
+ "contentVersion" => "1.0.0.0",
150
+ "parameters" => {
151
+ "adminUserName" => {
152
+ "type" => "string",
153
+ "metadata" => {
154
+ "description" => "User name for the Virtual Machine."
155
+ }
156
+ },
157
+ "adminPassword" => {
158
+ "type" => "securestring",
159
+ "metadata" => {
160
+ "description" => "Password for the Virtual Machine."
161
+ }
162
+ },
163
+ "availabilitySetName" => {
164
+ "type" => "string"
165
+ },
166
+ "availabilitySetPlatformFaultDomainCount" => {
167
+ "type" => "string"
168
+ },
169
+ "availabilitySetPlatformUpdateDomainCount" => {
170
+ "type" => "string"
171
+ },
172
+ "numberOfInstances" => {
173
+ "type" => "int",
174
+ "defaultValue" => 1,
175
+ "metadata" => {
176
+ "description" => "Number of VM instances to create. Default is 1"
177
+ }
178
+ },
179
+ "dnsLabelPrefix" => {
180
+ "type" => "string",
181
+ "metadata" => {
182
+ "description" => "Unique DNS Name for the Public IP used to access the Virtual Machine."
183
+ }
184
+ },
185
+ "imageSKU" => {
186
+ "type" => "string",
187
+ "metadata" => {
188
+ "description" => "Version of the image"
189
+ }
190
+ },
191
+ "imageVersion" => {
192
+ "type" => "string",
193
+ "defaultValue" => "latest",
194
+ "metadata" => {
195
+ "description" => "Azure image reference version."
196
+ }
197
+ },
198
+ "validation_key" => {
199
+ "type" => "string",
200
+ "metadata" => {
201
+ "description" => "JSON Escaped Validation Key"
202
+ }
203
+ },
204
+
205
+ "chef_server_crt" => {
206
+ "type" => "string",
207
+ "metadata" => {
208
+ "description" => "Optional. SSL cerificate provided by user."
209
+ }
210
+ },
211
+ "chef_server_url" => {
212
+ "type" => "string",
213
+ "metadata" => {
214
+ "description" => "Organization URL for the Chef Server. Example https://ChefServerDnsName.cloudapp.net/organizations/Orgname"
215
+ }
216
+ },
217
+ "validation_client_name" => {
218
+ "type" => "string",
219
+ "metadata" => {
220
+ "description" => "Validator key name for the organization. Example : MyOrg-validator"
221
+ }
222
+ },
223
+ "runlist" => {
224
+ "type" => "string",
225
+ "metadata" => {
226
+ "description" => "Optional Run List to Execute"
227
+ }
228
+ },
229
+ "environment" => {
230
+ "type" => "string",
231
+ "metadata" => {
232
+ "description" => "Chef environment for the node (VM) in the Chef Organization"
233
+ }
234
+ },
235
+ "chef_node_name" => {
236
+ "type" => "string",
237
+ "metadata" => {
238
+ "description" => "The name for the node (VM) in the Chef Organization"
239
+ }
240
+ },
241
+ "validation_key_format" => {
242
+ "type" => "string",
243
+ "allowedValues" => %w{plaintext base64encoded},
244
+ "defaultValue" => "plaintext",
245
+ "metadata" => {
246
+ "description" => "Format in which Validation Key is given. e.g. plaintext, base64encoded"
247
+ }
248
+ },
249
+ "client_rb" => {
250
+ "type" => "string",
251
+ "metadata" => {
252
+ "description" => "Optional. Path to a client.rb file for use by the bootstrapped node."
253
+ }
254
+ },
255
+ "bootstrap_version" => {
256
+ "type" => "string",
257
+ "metadata" => {
258
+ "description" => "Optional. The version of Chef to install."
259
+ }
260
+ },
261
+ "custom_json_attr" => {
262
+ "type" => "string",
263
+ "metadata" => {
264
+ "description" => "Optional. A JSON string to be added to the first run of chef-client."
265
+ }
266
+ },
267
+ "node_ssl_verify_mode" => {
268
+ "type" => "string",
269
+ "metadata" => {
270
+ "description" => "Optional. Whether or not to verify the SSL cert for all HTTPS requests."
271
+ }
272
+ },
273
+ "node_verify_api_cert" => {
274
+ "type" => "string",
275
+ "metadata" => {
276
+ "description" => "Optional. Verify the SSL cert for HTTPS requests to the Chef server API."
277
+ }
278
+ },
279
+ "encrypted_data_bag_secret" => {
280
+ "type" => "string",
281
+ "metadata" => {
282
+ "description" => "Optional. The secret key to use to encrypt data bag item values."
283
+ }
284
+ },
285
+ "bootstrap_proxy" => {
286
+ "type" => "string",
287
+ "metadata" => {
288
+ "description" => "Optional. The proxy server for the node being bootstrapped."
289
+ }
290
+ },
291
+ "sshKeyData" => {
292
+ "type" => "string",
293
+ "metadata" => {
294
+ "description" => "SSH rsa public key file as a string."
295
+ }
296
+ },
297
+ "disablePasswordAuthentication" => {
298
+ "type" => "string",
299
+ "metadata" => {
300
+ "description" => "Set to true if using ssh key for authentication."
301
+ }
302
+ }
303
+ },
304
+ "variables" => {
305
+ "storageAccountName" => "[concat(uniquestring(resourceGroup().id), '#{params[:azure_storage_account]}')]",
306
+ "imagePublisher" => "#{params[:azure_image_reference_publisher]}",
307
+ "imageOffer" => "#{params[:azure_image_reference_offer]}",
308
+ "OSDiskName" => "#{params[:azure_os_disk_name]}",
309
+ "nicName" => "#{params[:azure_vm_name]}",
310
+ "subnetName" => "#{params[:azure_vnet_subnet_name]}",
311
+ "storageAccountType" => "#{params[:azure_storage_account_type]}",
312
+ "publicIPAddressName" => "#{params[:azure_vm_name]}",
313
+ "publicIPAddressType" => "Dynamic",
314
+ "vmStorageAccountContainerName" => "#{params[:azure_vm_name]}",
315
+ "vmName" => "#{params[:azure_vm_name]}",
316
+ "vmSize" => "#{params[:vm_size]}",
317
+ "virtualNetworkName" => "#{params[:vnet_config][:virtualNetworkName]}",
318
+ "secgrpname" => "#{params[:azure_sec_group_name]}",
319
+ "vnetID" => "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
320
+ "subnetRef" => "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
321
+ "apiVersion" => "2015-06-15",
322
+ "vmExtensionName" => "#{params[:chef_extension]}",
323
+ "sshKeyPath" => "[concat('/home/',parameters('adminUserName'),'/.ssh/authorized_keys')]"
324
+ },
325
+ "resources" => [
326
+ {
327
+ "type" => "Microsoft.Storage/storageAccounts",
328
+ "name" => "[variables('storageAccountName')]",
329
+ "apiVersion" => "[variables('apiVersion')]",
330
+ "location" => "[resourceGroup().location]",
331
+ "properties" => {
332
+ "accountType" => "[variables('storageAccountType')]"
333
+ }
334
+ },
335
+ {
336
+ "apiVersion" => "[variables('apiVersion')]",
337
+ "type" => "Microsoft.Network/publicIPAddresses",
338
+ "name" => publicIPAddressName,
339
+ "location" => "[resourceGroup().location]",
340
+ "copy" => {
341
+ "name" => "publicIPLoop",
342
+ "count" => "[parameters('numberOfInstances')]"
343
+ },
344
+ "properties" => {
345
+ "publicIPAllocationMethod" => "[variables('publicIPAddressType')]",
346
+ "dnsSettings" => {
347
+ "domainNameLabel" => domainNameLabel
348
+ }
349
+ }
350
+ },
351
+ {
352
+ "apiVersion" => "[variables('apiVersion')]",
353
+ "type" => "Microsoft.Network/virtualNetworks",
354
+ "name" => "[variables('virtualNetworkName')]",
355
+ "location" => "[resourceGroup().location]",
356
+ "properties" => {
357
+ "addressSpace" => {
358
+ "addressPrefixes" => params[:vnet_config][:addressPrefixes]
359
+ },
360
+ "subnets" => params[:vnet_config][:subnets]
361
+ }
362
+ },
363
+ {
364
+ "apiVersion" => "[variables('apiVersion')]",
365
+ "type" => "Microsoft.Network/networkInterfaces",
366
+ "name" => nicName,
367
+ "location" => "[resourceGroup().location]",
368
+ "copy" => {
369
+ "name" => "nicLoop",
370
+ "count" => "[parameters('numberOfInstances')]"
371
+ },
372
+ "dependsOn" => [
373
+ depNic1,
374
+ "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
375
+ ],
376
+ "properties" => {
377
+ "ipConfigurations" => [
378
+ {
379
+ "name" => "ipconfig1",
380
+ "properties" => {
381
+ "privateIPAllocationMethod" => "Dynamic",
382
+ "publicIPAddress" => {
383
+ "id" => pubId
384
+ },
385
+ "subnet" => {
386
+ "id" => "[variables('subnetRef')]"
387
+ }
388
+ }
389
+ }
390
+ ]
391
+ }
392
+ },
393
+ {
394
+ "apiVersion" => "[variables('apiVersion')]",
395
+ "type" => "Microsoft.Compute/virtualMachines",
396
+ "name" => vmName,
397
+ "location" => "[resourceGroup().location]",
398
+ "copy" => {
399
+ "name" => "vmLoop",
400
+ "count" => "[parameters('numberOfInstances')]"
401
+ },
402
+ "dependsOn" => [
403
+ "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
404
+ depVm2,
405
+ ],
406
+ "properties" => {
407
+ "hardwareProfile" => {
408
+ "vmSize" => "[variables('vmSize')]"
409
+ },
410
+ "osProfile" => {
411
+ "computerName" => computerName,
412
+ "adminUserName" => "[parameters('adminUserName')]",
413
+ "adminPassword" => "[parameters('adminPassword')]",
414
+ "linuxConfiguration" => ( if params[:disablePasswordAuthentication] == "true"
415
+ {
416
+ "disablePasswordAuthentication" => "[parameters('disablePasswordAuthentication')]",
417
+ "ssh" => {
418
+ "publicKeys" => [ {
419
+ "path" => "[variables('sshKeyPath')]",
420
+ "keyData" => "[parameters('sshKeyData')]"
421
+ } ]
422
+ }
423
+ }
424
+ end)
425
+ },
426
+ "storageProfile" => {
427
+ "imageReference" => {
428
+ "publisher" => "[variables('imagePublisher')]",
429
+ "offer" => "[variables('imageOffer')]",
430
+ "sku" => "[parameters('imageSKU')]",
431
+ "version" => "[parameters('imageVersion')]"
432
+ },
433
+ "osDisk" => {
434
+ "name" => "[variables('OSDiskName')]",
435
+ "vhd" => {
436
+ "uri" => uri },
437
+ "caching" => "ReadWrite",
438
+ "createOption" => "FromImage"
439
+ }
440
+ },
441
+ "networkProfile" => {
442
+ "networkInterfaces" => [
443
+ {
444
+ "id" => netid
445
+ }
446
+ ]
447
+ },
448
+ "diagnosticsProfile" => {
449
+ "bootDiagnostics" => {
450
+ "enabled" => "true",
451
+ "storageUri" => "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]"
452
+ }
453
+ }
454
+ }
455
+ },
456
+ {
457
+ "type" => "Microsoft.Compute/virtualMachines/extensions",
458
+ "name" => extName,
459
+ "apiVersion" => "2015-05-01-preview",
460
+ "location" => "[resourceGroup().location]",
461
+ "copy" => {
462
+ "name" => "extensionLoop",
463
+ "count" => "[parameters('numberOfInstances')]"
464
+ },
465
+ "dependsOn" => [
466
+ depExt
467
+ ],
468
+ "properties" => {
469
+ "publisher" => "#{params[:chef_extension_publisher]}",
470
+ "type" => "#{params[:chef_extension]}",
471
+ "typeHandlerVersion" => "#{params[:chef_extension_version]}",
472
+ "autoUpgradeMinorVersion" => "#{params[:auto_upgrade_minor_version]}",
473
+ "settings" => {
474
+ "bootstrap_version" => "[parameters('bootstrap_version')]",
475
+ "bootstrap_options" => {
476
+ "chef_node_name" => chef_node_name,
477
+ "chef_server_url" => "[parameters('chef_server_url')]",
478
+ "validation_client_name" => "[parameters('validation_client_name')]",
479
+ "node_ssl_verify_mode" => "[parameters('node_ssl_verify_mode')]",
480
+ "node_verify_api_cert" => "[parameters('node_verify_api_cert')]",
481
+ "bootstrap_proxy" => "[parameters('bootstrap_proxy')]",
482
+ "environment" => "[parameters('environment')]"
483
+ },
484
+ "runlist" => "[parameters('runlist')]",
485
+ "validation_key_format" => "[parameters('validation_key_format')]",
486
+ "hints" => hints_json,
487
+ "client_rb" => "[parameters('client_rb')]",
488
+ "custom_json_attr" => "[parameters('custom_json_attr')]"
489
+ },
490
+ "protectedSettings" => {
491
+ "validation_key" => "[parameters('validation_key')]",
492
+ "chef_server_crt" => "[parameters('chef_server_crt')]",
493
+ "encrypted_data_bag_secret" => "[parameters('encrypted_data_bag_secret')]"
494
+ }
495
+ }
496
+ }
497
+ ]
498
+ }
499
+
500
+ if params[:azure_availability_set]
501
+ set_val = {
502
+ "name" => "[parameters('availabilitySetName')]",
503
+ "type" => "Microsoft.Compute/availabilitySets",
504
+ "apiVersion" => "[variables('apiVersion')]",
505
+ "location" => "[resourceGroup().location]",
506
+ "properties" => {
507
+ "platformFaultDomainCount" => "[parameters('availabilitySetPlatformFaultDomainCount')]",
508
+ "platformUpdateDomainCount" => "[parameters('availabilitySetPlatformUpdateDomainCount')]"
509
+ }
510
+ }
511
+
512
+ length = template["resources"].length.to_i - 1
513
+ for i in 0..length do
514
+ if template["resources"][i]["type"] == "Microsoft.Compute/virtualMachines"
515
+ template["resources"][i]["dependsOn"] << "[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]"
516
+ template["resources"][i]["properties"]["availabilitySet"] = { "id" => "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySetName'))]" }
517
+ end
518
+ end
519
+ template["resources"].insert(length, set_val)
520
+ end
521
+
522
+ if params[:tcp_endpoints]
523
+ sec_grp_json = tcp_ports(params[:tcp_endpoints], params[:azure_vm_name])
524
+ template["resources"].insert(1, sec_grp_json)
525
+ length = template["resources"].length.to_i - 1
526
+ for i in 0..length do
527
+ if template["resources"][i]["type"] == "Microsoft.Network/virtualNetworks"
528
+ template["resources"][i] = template["resources"][i].merge({ "dependsOn" => [sec_grp] })
529
+ end
530
+ if template["resources"][i]["type"] == "Microsoft.Network/networkInterfaces"
531
+ template["resources"][i]["properties"] = template["resources"][i]["properties"].merge({ "networkSecurityGroup" => { "id" => sec_grp_id } })
532
+ end
533
+ end
534
+ end
535
+
536
+ if params[:chef_extension_public_param][:extendedLogs] == "true"
537
+ template["resources"].each do |resource|
538
+ if resource["type"] == "Microsoft.Compute/virtualMachines/extensions"
539
+ resource["properties"]["settings"]["extendedLogs"] = params[:chef_extension_public_param][:extendedLogs]
540
+ end
541
+ end
542
+ end
543
+
544
+ if params[:chef_extension_public_param][:chef_daemon_interval]
545
+ template["resources"].each do |resource|
546
+ if resource["type"] == "Microsoft.Compute/virtualMachines/extensions"
547
+ resource["properties"]["settings"]["chef_daemon_interval"] = params[:chef_extension_public_param][:chef_daemon_interval]
548
+ end
549
+ end
550
+ end
551
+
552
+ if params[:chef_extension_public_param][:daemon]
553
+ template["resources"].each do |resource|
554
+ if resource["type"] == "Microsoft.Compute/virtualMachines/extensions"
555
+ resource["properties"]["settings"]["daemon"] = params[:chef_extension_public_param][:daemon]
556
+ end
557
+ end
558
+ end
559
+ if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
560
+ template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters(concat('client_pem',copyIndex()))]"
561
+ 0.upto (params[:server_count].to_i - 1) do |count|
562
+ template["parameters"]["client_pem" + count.to_s] = {
563
+ "type" => "string",
564
+ "metadata" => {
565
+ "description" => "Required for validtorless bootstrap."
566
+ }
567
+ }
568
+ end
569
+ else
570
+ template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters('client_pem')]"
571
+ template["parameters"]["client_pem"] = {
572
+ "type" => "string",
573
+ "metadata" => {
574
+ "description" => "Required for validtorless bootstrap."
575
+ }
576
+ }
577
+ end
578
+ template
579
+ end
580
+
581
+ def create_deployment_parameters(params, platform)
582
+ if platform == "Windows"
583
+ admin_user = params[:winrm_user]
584
+ admin_password = params[:admin_password]
585
+ else
586
+ admin_user = params[:ssh_user]
587
+ admin_password = params[:ssh_password]
588
+ end
589
+
590
+ parameters = {
591
+ "adminUserName" => {
592
+ "value" => "#{admin_user}"
593
+ },
594
+ "adminPassword" => {
595
+ "value" => "#{admin_password}"
596
+ },
597
+ "availabilitySetName" => {
598
+ "value" => "#{params[:azure_availability_set]}"
599
+ },
600
+ "availabilitySetPlatformFaultDomainCount" => {
601
+ "value" => "2"
602
+ },
603
+ "availabilitySetPlatformUpdateDomainCount" => {
604
+ "value" => "5"
605
+ },
606
+ "dnsLabelPrefix" => {
607
+ "value" => "#{params[:azure_vm_name]}"
608
+ },
609
+ "imageSKU" => {
610
+ "value" => "#{params[:azure_image_reference_sku]}"
611
+ },
612
+ "numberOfInstances" => {
613
+ "value" => "#{params[:server_count]}".to_i
614
+ },
615
+ "validation_key" => {
616
+ "value" => "#{params[:chef_extension_private_param][:validation_key]}"
617
+ },
618
+
619
+ "chef_server_crt" => {
620
+ "value" => "#{params[:chef_extension_private_param][:chef_server_crt]}"
621
+ },
622
+ "encrypted_data_bag_secret" => {
623
+ "value" => "#{params[:chef_extension_private_param][:encrypted_data_bag_secret]}"
624
+ },
625
+ "chef_server_url" => {
626
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:chef_server_url]}"
627
+ },
628
+ "validation_client_name" => {
629
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:validation_client_name]}"
630
+ },
631
+ "node_ssl_verify_mode" => {
632
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:node_ssl_verify_mode]}"
633
+ },
634
+ "node_verify_api_cert" => {
635
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:node_verify_api_cert]}"
636
+ },
637
+ "bootstrap_proxy" => {
638
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:bootstrap_proxy]}"
639
+ },
640
+ "runlist" => {
641
+ "value" => "#{params[:chef_extension_public_param][:runlist]}"
642
+ },
643
+ "environment" => {
644
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:environment]}"
645
+ },
646
+ "chef_node_name" => {
647
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:chef_node_name]}"
648
+ },
649
+ "client_rb" => {
650
+ "value" => "#{params[:chef_extension_public_param][:client_rb]}"
651
+ },
652
+ "bootstrap_version" => {
653
+ "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:bootstrap_version]}"
654
+ },
655
+ "custom_json_attr" => {
656
+ "value" => "#{params[:chef_extension_public_param][:custom_json_attr]}"
657
+ },
658
+ "sshKeyData" => {
659
+ "value" => "#{params[:ssh_key]}"
660
+ },
661
+ "disablePasswordAuthentication" => {
662
+ "value" => "#{params[:disablePasswordAuthentication]}"
663
+ }
664
+ }
665
+ if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
666
+ 0.upto (params[:server_count].to_i - 1) do |count|
667
+ parameters["client_pem#{count}"] = {
668
+ "value" => "#{params[:chef_extension_private_param][("client_pem" + count.to_s).to_sym]}"
669
+ }
670
+ end
671
+ else
672
+ parameters["client_pem"] = {
673
+ "value" => "#{params[:chef_extension_private_param][:client_pem]}"
674
+ }
675
+ end
676
+ parameters
677
+ end
678
+ end
679
+ end