Module: Azure::ARM::ARMDeploymentTemplate

Included in:
ResourceManagement::ARMInterface
Defined in:
lib/azure/resource_management/ARM_deployment_template.rb

Instance Method Summary collapse

Instance Method Details

#create_deployment_parameters(params) ⇒ Object



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/azure/resource_management/ARM_deployment_template.rb', line 581

def create_deployment_parameters(params)
  admin_user = params[:connection_user]
  admin_password = params[:connection_password]

  parameters = {
    "adminUserName" => {
      "value" => "#{admin_user}",
    },
    "adminPassword" => {
      "value" => "#{admin_password}",
    },
    "availabilitySetName" => {
        "value" => "#{params[:azure_availability_set]}",
    },
    "availabilitySetPlatformFaultDomainCount" => {
        "value" => "2",
    },
    "availabilitySetPlatformUpdateDomainCount" => {
        "value" => "5",
    },
    "dnsLabelPrefix" => {
      "value" => "#{params[:azure_vm_name]}",
    },
    "imageSKU" => {
      "value" => "#{params[:azure_image_reference_sku]}",
    },
    "numberOfInstances" => {
      "value" => "#{params[:server_count]}".to_i,
    },
    "validation_key" => {
      "value" => "#{params[:chef_extension_private_param][:validation_key]}",
    },

    "chef_server_crt" => {
      "value" => "#{params[:chef_extension_private_param][:chef_server_crt]}",
    },
    "encrypted_data_bag_secret" => {
      "value" => "#{params[:chef_extension_private_param][:encrypted_data_bag_secret]}",
    },
    "chef_server_url" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:chef_server_url]}",
    },
    "validation_client_name" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:validation_client_name]}",
    },
    "node_ssl_verify_mode" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:node_ssl_verify_mode]}",
    },
    "node_verify_api_cert" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:node_verify_api_cert]}",
    },
    "bootstrap_proxy" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:bootstrap_proxy]}",
    },
    "runlist" => {
      "value" => "#{params[:chef_extension_public_param][:runlist]}",
    },
    "environment" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:environment]}",
    },
    "chef_node_name" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:chef_node_name]}",
    },
    "client_rb" => {
      "value" => "#{params[:chef_extension_public_param][:client_rb]}",
    },
    "bootstrap_version" => {
      "value" => "#{params[:chef_extension_public_param][:bootstrap_options][:bootstrap_version]}",
    },
    "custom_json_attr" => {
      "value" => "#{params[:chef_extension_public_param][:custom_json_attr]}",
    },
    "sshKeyData" => {
      "value" => "#{params[:ssh_public_key]}",
    },
    "disablePasswordAuthentication" => {
      "value" => "#{params[:disablePasswordAuthentication]}",
    },
  }
  if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
    0.upto (params[:server_count].to_i - 1) do |count|
      parameters["client_pem#{count}"] = {
          "value" => "#{params[:chef_extension_private_param][("client_pem" + count.to_s).to_sym]}",
        }
    end
  else
    parameters["client_pem"] = {
        "value" => "#{params[:chef_extension_private_param][:client_pem]}",
      }
  end
  parameters
end

#create_deployment_template(params) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/azure/resource_management/ARM_deployment_template.rb', line 75

def create_deployment_template(params)
  if params[:chef_extension_public_param][:bootstrap_options][:chef_node_name]
    chef_node_name = "[concat(parameters('chef_node_name'),copyIndex())]"
    chef_node_name = "[parameters('chef_node_name')]" if params[:server_count].to_i == 1
  end

  if params[:server_count].to_i > 1
    # publicIPAddresses Resource Variables
    publicIPAddressName = "[concat(variables('publicIPAddressName'),copyIndex())]"
    domainNameLabel = "[concat(parameters('dnsLabelPrefix'), copyIndex())]"

    # networkInterfaces Resource Variables
    nicName = "[concat(variables('nicName'),copyIndex())]"
    depNic1 = "[concat('Microsoft.Network/publicIPAddresses/', concat(variables('publicIPAddressName'),copyIndex()))]"
    pubId = "[resourceId('Microsoft.Network/publicIPAddresses',concat(variables('publicIPAddressName'),copyIndex()))]"

    # virtualMachines Resource Variables
    vmName = "[concat(variables('vmName'),copyIndex())]"
    vmSize = "[concat(variables('vmSize'),copyIndex())]"
    vmId = "[resourceId('Microsoft.Compute/virtualMachines', concat(variables('vmName'),copyIndex()))]"
    depVm2 = "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'), copyIndex())]"
    computerName = "[concat(variables('vmName'),copyIndex())]"
    uri = "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',concat(variables('vmName'),copyIndex()),'.vhd')]"
    netid = "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nicName'), copyIndex()))]"

    # Extension Variables
    extName = "[concat(variables('vmName'),copyIndex(),'/', variables('vmExtensionName'))]"
    depExt = "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'), copyIndex())]"

  else
    # publicIPAddresses Resource Variables
    publicIPAddressName = "[variables('publicIPAddressName')]"
    domainNameLabel = "[parameters('dnsLabelPrefix')]"

    # networkInterfaces Resource Variables
    nicName = "[concat(variables('nicName'))]"
    depNic1 = "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
    pubId = "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"

    # virtualMachines Resource Variables
    vmName = "[variables('vmName')]"
    vmSize = "[variables('vmSize')]"
    vmId = "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
    depVm2 = "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
    computerName = "[variables('vmName')]"
    uri = "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('vmName'),'.vhd')]"
    netid = "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"

    # Extension Variables
    extName = "[concat(variables('vmName'),'/', variables('vmExtensionName'))]"
    depExt = "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
  end

  # NetworkSecurityGroups Resource Variables
  sec_grp_name = "[variables('secgrpname')]"
  sec_grp = "[concat('Microsoft.Network/networkSecurityGroups/', variables('secgrpname'))]"
  sec_grp_id = "[resourceId('Microsoft.Network/networkSecurityGroups/', variables('secgrpname'))]"

  resource_ids = {}
  hint_names = params[:chef_extension_public_param][:hints]

  hint_names.each do |hint_name|
    case hint_name
    when "public_fqdn"
      resource_ids["pubId"] = pubId.delete("[").delete("]") unless resource_ids.key? "pubId"
    when "vm_name", "platform"
      resource_ids["vmId"] = vmId.delete("[").delete("]") unless resource_ids.key? "vmId"
    end
  end

  hints_json = ohai_hints(hint_names, resource_ids)

  template = {
    "$schema" => "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion" => "1.0.0.0",
    "parameters" => {
      "adminUserName" => {
        "type" => "string",
        "metadata" => {
          "description" => "User name for the Virtual Machine.",
        },
      },
      "adminPassword" => {
        "type" => "securestring",
        "metadata" => {
          "description" => "Password for the Virtual Machine.",
        },
      },
      "availabilitySetName" => {
        "type" => "string",
      },
      "availabilitySetPlatformFaultDomainCount" => {
        "type" => "string",
      },
      "availabilitySetPlatformUpdateDomainCount" => {
        "type" => "string",
      },
      "numberOfInstances" => {
        "type" => "int",
        "defaultValue" => 1,
        "metadata" => {
          "description" => "Number of VM instances to create. Default is 1",
        },
      },
      "dnsLabelPrefix" => {
        "type" => "string",
        "metadata" => {
          "description" => "Unique DNS Name for the Public IP used to access the Virtual Machine.",
        },
      },
      "imageSKU" => {
        "type" => "string",
        "metadata" => {
          "description" => "Version of the image",
        },
      },
      "imageVersion" => {
        "type" => "string",
        "defaultValue" => "latest",
        "metadata" => {
          "description" => "Azure image reference version.",
        },
      },
      "validation_key" => {
        "type" => "string",
        "metadata" => {
          "description" => "JSON Escaped Validation Key",
        },
      },

      "chef_server_crt" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. SSL cerificate provided by user.",
        },
      },
      "chef_server_url" => {
        "type" => "string",
        "metadata" => {
          "description" => "Organization URL for the Chef Server. Example https://ChefServerDnsName.cloudapp.net/organizations/Orgname",
        },
      },
      "validation_client_name" => {
        "type" => "string",
        "metadata" => {
          "description" => "Validator key name for the organization. Example : MyOrg-validator",
        },
      },
      "runlist" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional Run List to Execute",
        },
      },
      "environment" => {
        "type" => "string",
        "metadata" => {
          "description" => "Chef environment for the node (VM) in the Chef Organization",
        },
      },
      "chef_node_name" => {
        "type" => "string",
        "metadata" => {
          "description" => "The name for the node (VM) in the Chef Organization",
        },
      },
      "validation_key_format" => {
        "type" => "string",
        "allowedValues" => %w{plaintext base64encoded},
        "defaultValue" => "plaintext",
        "metadata" => {
          "description" => "Format in which Validation Key is given. e.g. plaintext, base64encoded",
        },
      },
      "client_rb" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. Path to a client.rb file for use by the bootstrapped node.",
        },
      },
      "bootstrap_version" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. The version of Chef to install.",
        },
      },
      "custom_json_attr" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. A JSON string to be added to the first run of chef-client.",
        },
      },
      "node_ssl_verify_mode" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. Whether or not to verify the SSL cert for all HTTPS requests.",
        },
      },
      "node_verify_api_cert" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. Verify the SSL cert for HTTPS requests to the Chef server API.",
        },
      },
      "encrypted_data_bag_secret" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. The secret key to use to encrypt data bag item values.",
        },
      },
      "bootstrap_proxy" => {
        "type" => "string",
        "metadata" => {
          "description" => "Optional. The proxy server for the node being bootstrapped.",
        },
      },
      "sshKeyData" => {
        "type" => "string",
        "metadata" => {
          "description" => "SSH rsa public key file as a string.",
        },
      },
      "disablePasswordAuthentication" => {
        "type" => "string",
        "metadata" => {
          "description" => "Set to true if using ssh key for authentication.",
        },
      },
    },
    "variables" => {
      "storageAccountName" => "[concat(uniquestring(resourceGroup().id), '#{params[:azure_storage_account]}')]",
      "imagePublisher" => "#{params[:azure_image_reference_publisher]}",
      "imageOffer" => "#{params[:azure_image_reference_offer]}",
      "OSDiskName" => "#{params[:azure_os_disk_name]}",
      "nicName" => "#{params[:azure_vm_name]}",
      "subnetName" => "#{params[:azure_vnet_subnet_name]}",
      "storageAccountType" => "#{params[:azure_storage_account_type]}",
      "publicIPAddressName" => "#{params[:azure_vm_name]}",
      "publicIPAddressType" => "Dynamic",
      "vmStorageAccountContainerName" => "#{params[:azure_vm_name]}",
      "vmName" => "#{params[:azure_vm_name]}",
      "vmSize" => "#{params[:vm_size]}",
      "virtualNetworkName" => "#{params[:vnet_config][:virtualNetworkName]}",
      "secgrpname" => "#{params[:azure_sec_group_name]}",
      "vnetID" => "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
      "subnetRef" => "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
      "apiVersion" => "2015-06-15",
      "vmExtensionName" => "#{params[:chef_extension]}",
      "sshKeyPath" => "[concat('/home/',parameters('adminUserName'),'/.ssh/authorized_keys')]",
    },
    "resources" => [
      {
        "type" => "Microsoft.Storage/storageAccounts",
        "name" => "[variables('storageAccountName')]",
        "apiVersion" => "[variables('apiVersion')]",
        "location" => "[resourceGroup().location]",
        "properties" => {
          "accountType" => "[variables('storageAccountType')]",
        },
      },
      {
        "apiVersion" => "[variables('apiVersion')]",
        "type" => "Microsoft.Network/publicIPAddresses",
        "name" => publicIPAddressName,
        "location" => "[resourceGroup().location]",
        "copy" => {
          "name" => "publicIPLoop",
          "count" => "[parameters('numberOfInstances')]",
        },
        "properties" => {
          "publicIPAllocationMethod" => "[variables('publicIPAddressType')]",
          "dnsSettings" => {
            "domainNameLabel" => domainNameLabel,
          },
        },
      },
      {
        "apiVersion" => "[variables('apiVersion')]",
        "type" => "Microsoft.Network/virtualNetworks",
        "name" => "[variables('virtualNetworkName')]",
        "location" => "[resourceGroup().location]",
        "properties" => {
          "addressSpace" => {
            "addressPrefixes" => params[:vnet_config][:addressPrefixes],
          },
          "subnets" => params[:vnet_config][:subnets],
        },
      },
      {
        "apiVersion" => "[variables('apiVersion')]",
        "type" => "Microsoft.Network/networkInterfaces",
        "name" => nicName,
        "location" => "[resourceGroup().location]",
        "copy" => {
          "name" => "nicLoop",
          "count" => "[parameters('numberOfInstances')]",
        },
        "dependsOn" => [
          depNic1,
          "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
        ],
        "properties" => {
          "ipConfigurations" => [
            {
              "name" => "ipconfig1",
              "properties" => {
                "privateIPAllocationMethod" => "Dynamic",
                "publicIPAddress" => {
                  "id" => pubId,
                },
                "subnet" => {
                  "id" => "[variables('subnetRef')]",
                },
              },
            },
          ],
        },
      },
      {
        "apiVersion" => "[variables('apiVersion')]",
        "type" => "Microsoft.Compute/virtualMachines",
        "name" => vmName,
        "location" => "[resourceGroup().location]",
        "copy" => {
          "name" => "vmLoop",
          "count" => "[parameters('numberOfInstances')]",
        },
        "dependsOn" => [
          "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
          depVm2,
        ],
        "properties" => {
          "hardwareProfile" => {
            "vmSize" => "[variables('vmSize')]",
          },
          "osProfile" => {
            "computerName" => computerName,
            "adminUserName" => "[parameters('adminUserName')]",
            "adminPassword" => "[parameters('adminPassword')]",
            "linuxConfiguration" => ( if params[:disablePasswordAuthentication] == "true"
                                        {  "disablePasswordAuthentication" => "[parameters('disablePasswordAuthentication')]",
                                           "ssh" => {
                                             "publicKeys" => [{
                                               "path" => "[variables('sshKeyPath')]",
                                               "keyData" => "[parameters('sshKeyData')]",
                                             }],
                                           },
                                        }
                                      end),
          },
          "storageProfile" => {
            "imageReference" => {
              "publisher" => "[variables('imagePublisher')]",
              "offer" => "[variables('imageOffer')]",
              "sku" => "[parameters('imageSKU')]",
              "version" => "[parameters('imageVersion')]",
            },
            "osDisk" => {
              "name" => "[variables('OSDiskName')]",
              "vhd" => {
                "uri" => uri,
              },
              "caching" => "ReadWrite",
              "createOption" => "FromImage",
            },
          },
          "networkProfile" => {
            "networkInterfaces" => [
              {
                "id" => netid,
              },
            ],
          },
          "diagnosticsProfile" => {
            "bootDiagnostics" => {
              "enabled" => "true",
              "storageUri" => "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]",
            },
          },
        },
      },
      {
        "type" => "Microsoft.Compute/virtualMachines/extensions",
        "name" => extName,
        "apiVersion" => "2015-05-01-preview",
        "location" => "[resourceGroup().location]",
        "copy" => {
          "name" => "extensionLoop",
          "count" => "[parameters('numberOfInstances')]",
        },
        "dependsOn" => [
          depExt,
        ],
        "properties" => {
          "publisher" => "#{params[:chef_extension_publisher]}",
          "type" => "#{params[:chef_extension]}",
          "typeHandlerVersion" => "#{params[:chef_extension_version]}",
          "autoUpgradeMinorVersion" => "#{params[:auto_upgrade_minor_version]}",
          "settings" => {
            "bootstrap_version" => "[parameters('bootstrap_version')]",
            "bootstrap_options" => {
              "chef_node_name" => chef_node_name,
              "chef_server_url" => "[parameters('chef_server_url')]",
              "validation_client_name" => "[parameters('validation_client_name')]",
              "node_ssl_verify_mode" => "[parameters('node_ssl_verify_mode')]",
              "node_verify_api_cert" => "[parameters('node_verify_api_cert')]",
              "bootstrap_proxy" => "[parameters('bootstrap_proxy')]",
              "environment" => "[parameters('environment')]",
            },
            "runlist" => "[parameters('runlist')]",
            "validation_key_format" => "[parameters('validation_key_format')]",
            "hints" => hints_json,
            "client_rb" => "[parameters('client_rb')]",
            "custom_json_attr" => "[parameters('custom_json_attr')]",
          },
          "protectedSettings" => {
            "validation_key" => "[parameters('validation_key')]",
            "chef_server_crt" => "[parameters('chef_server_crt')]",
            "encrypted_data_bag_secret" => "[parameters('encrypted_data_bag_secret')]",
          },
        },
      },
    ],
  }

  if params[:azure_availability_set]
    set_val = {
      "name" => "[parameters('availabilitySetName')]",
      "type" => "Microsoft.Compute/availabilitySets",
      "apiVersion" => "[variables('apiVersion')]",
      "location" => "[resourceGroup().location]",
      "properties" => {
        "platformFaultDomainCount" => "[parameters('availabilitySetPlatformFaultDomainCount')]",
        "platformUpdateDomainCount" => "[parameters('availabilitySetPlatformUpdateDomainCount')]",
      },
    }

    length = template["resources"].length.to_i - 1
    for i in 0..length do
      if template["resources"][i]["type"] == "Microsoft.Compute/virtualMachines"
        template["resources"][i]["dependsOn"] << "[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]"
        template["resources"][i]["properties"]["availabilitySet"] = { "id" => "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySetName'))]" }
      end
    end
    template["resources"].insert(length, set_val)
  end

  if params[:tcp_endpoints]
    sec_grp_json = tcp_ports(params[:tcp_endpoints], params[:azure_vm_name])
    template["resources"].insert(1, sec_grp_json)
    length = template["resources"].length.to_i - 1
    for i in 0..length do
      if template["resources"][i]["type"] == "Microsoft.Network/virtualNetworks"
        template["resources"][i] = template["resources"][i].merge({ "dependsOn" => [sec_grp] })
      end
      if template["resources"][i]["type"] == "Microsoft.Network/networkInterfaces"
        template["resources"][i]["properties"] = template["resources"][i]["properties"].merge({ "networkSecurityGroup" => { "id" => sec_grp_id } })
      end
    end
  end

  if params[:chef_extension_public_param][:extendedLogs] == "true"
    template["resources"].each do |resource|
      if resource["type"] == "Microsoft.Compute/virtualMachines/extensions"
        resource["properties"]["settings"]["extendedLogs"] = params[:chef_extension_public_param][:extendedLogs]
      end
    end
  end

  if params[:chef_extension_public_param][:chef_daemon_interval]
    template["resources"].each do |resource|
      if resource["type"] == "Microsoft.Compute/virtualMachines/extensions"
        resource["properties"]["settings"]["chef_daemon_interval"] = params[:chef_extension_public_param][:chef_daemon_interval]
      end
    end
  end

  if params[:chef_extension_public_param][:daemon]
    template["resources"].each do |resource|
      if resource["type"] == "Microsoft.Compute/virtualMachines/extensions"
        resource["properties"]["settings"]["daemon"] = params[:chef_extension_public_param][:daemon]
      end
    end
  end
  if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
    template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters(concat('client_pem',copyIndex()))]"
    0.upto (params[:server_count].to_i - 1) do |count|
      template["parameters"]["client_pem" + count.to_s] = {
        "type" => "string",
        "metadata" => {
          "description" => "Required for validtorless bootstrap.",
        },
      }
    end
  else
    template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters('client_pem')]"
    template["parameters"]["client_pem"] = {
      "type" => "string",
      "metadata" => {
        "description" => "Required for validtorless bootstrap.",
      },
    }
  end
  template
end

#ohai_hints(hint_names, resource_ids) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/azure/resource_management/ARM_deployment_template.rb', line 21

def ohai_hints(hint_names, resource_ids)
  hints_json = {}

  hint_names.each do |hint_name|
    case hint_name
    when "vm_name"
      hints_json["vm_name"] = "[reference(#{resource_ids["vmId"]}).osProfile.computerName]" unless hints_json.key? "vm_name"
    when "public_fqdn"
      hints_json["public_fqdn"] = "[reference(#{resource_ids["pubId"]}).dnsSettings.fqdn]" unless hints_json.key? "public_fqdn"
    when "platform"
      hints_json["platform"] = "[concat(reference(#{resource_ids["vmId"]}).storageProfile.imageReference.offer, concat(' ', reference(#{resource_ids["vmId"]}).storageProfile.imageReference.sku))]" unless hints_json.key? "platform"
    end
  end

  hints_json
end

#tcp_ports(tcp_ports, vm_name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/azure/resource_management/ARM_deployment_template.rb', line 38

def tcp_ports(tcp_ports, vm_name)
  tcp_ports = tcp_ports.split(",")
  sec_grp_json =
    {
      "apiVersion" => "[variables('apiVersion')]",
      "type" => "Microsoft.Network/networkSecurityGroups",
      "name" => "[variables('secgrpname')]",
      "location" => "[resourceGroup().location]",
      "properties" => {
        "securityRules" => [
        ],
      },
    }
  # Security Rule priority can be set between 100 and 4096
  rule_no = 300
  incremental = 0
  for port in tcp_ports
    rule_no += 2
    sec_grp_json["properties"]["securityRules"].push(
      "name" => vm_name + "_rule_" + incremental.to_s,
      "properties" => {
        "description" => "Port Provided by user",
        "protocol" => "Tcp",
        "sourcePortRange" => "*",
        "destinationPortRange" => port,
        "sourceAddressPrefix" => "*",
        "destinationAddressPrefix" => "*",
        "access" => "Allow",
        "priority" => rule_no,
        "direction" => "Inbound",
      }
    )
    incremental += 1
  end
  sec_grp_json
end