kitchen-azurerm 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8faa0eea59a7410da85cbdac7f77786361b84f49
4
- data.tar.gz: 58cff5b62510c6aacc03a885ec2cfeaf3802f88f
3
+ metadata.gz: 2bdc1fdf5f92aa6e66d2e70dea9b8ec191f82f33
4
+ data.tar.gz: 8459a815ab0a4bf77e806841c09821ac35e52eaa
5
5
  SHA512:
6
- metadata.gz: be224e4ad2628d374df1d2c752a58f24e8b0583cfb65517917a323e39e4472455547127f71e2703a28680ac0f17b1a37709e4e8f38140b44c63287b775ddcbe0
7
- data.tar.gz: 127bf050a655c568739a96662a09df699355448052f60577ae8bd26357fd4f1a49f202896f6e753093843ac73a808c6198814421a51865f61237c4e88177c0b7
6
+ metadata.gz: 0fce37482ad1c3a879257c58b0e1f14501f4365913d793cddc01c74a1858d0c259d302caa4c5a41b641573124c8ea0a2b9b350bc8820f992e6cc5f38a33a95b1
7
+ data.tar.gz: 0a0617b0908c820a7d961788a87df5b1f5bf96fdd6d9c49b0b62bc0edb97fc5b18e4ac4612fbe4916181dc1fac09fe74e67d56b8eecd7aa64336edb54d9a98b2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # kitchen-azurerm Changelog
2
2
 
3
+ ## [0.12.0] - 2017-09-01
4
+ - Additional managed disks can be specified in configuration and left unformatted or formatted on Windows(@stuartpreston)
5
+ - Added `azure_resource_group_prefix` and `azure_resource_group_suffix` parameter (@stuartpreston)
6
+
3
7
  ## [0.11.0] - 2017-07-20
4
8
  - Pin to latest ARM SDK and constants [#59](https://github.com/test-kitchen/kitchen-azurerm/pull/59) (@smurawski)
5
9
 
data/README.md CHANGED
@@ -367,6 +367,45 @@ suites:
367
367
  attributes:
368
368
  ```
369
369
 
370
+ ### .kitchen.yml example 8 - Windows 2016 VM with additional data disks:
371
+
372
+ This example demonstrates how to add 3 additional Managed data disks to a Windows Server 2016 VM. Not supported with legacy (pre-managed disk) storage accounts.
373
+
374
+ Note the availability of a `format_data_disks` option (default: `false`). When set to true, a PowerShell script will execute at first boot to initialize and format the disks with an NTFS filesystem. This option has no effect on Linux machines.
375
+
376
+ ```yaml
377
+ ---
378
+ driver:
379
+ name: azurerm
380
+
381
+ driver_config:
382
+ subscription_id: '4801fa9d-YOUR-GUID-HERE-b265ff49ce21'
383
+ location: 'West Europe'
384
+ machine_size: 'Standard_F2s'
385
+
386
+ provisioner:
387
+ name: chef_zero
388
+
389
+ platforms:
390
+ - name: windows2016-noformat
391
+ driver_config:
392
+ image_urn: MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest
393
+ data_disks:
394
+ - lun: 0
395
+ disk_size_gb: 128
396
+ - lun: 1
397
+ disk_size_gb: 128
398
+ - lun: 2
399
+ disk_size_gb: 128
400
+ # format_data_disks: false
401
+
402
+ suites:
403
+ - name: default
404
+ run_list:
405
+ - recipe[kitchentesting::default]
406
+ attributes:
407
+ ```
408
+
370
409
  ## Support for Government and Sovereign Clouds (China and Germany)
371
410
 
372
411
  Starting with v0.9.0 this driver has support for Azure Government and Sovereign Clouds via the use of the ```azure_environment``` setting. Valid Azure environments are ```Azure```, ```AzureUSGovernment```, ```AzureChina``` and ```AzureGermanCloud```
@@ -451,6 +490,7 @@ info: vm image list command OK
451
490
  - The ```existing_storage_account_blob_url``` can be specified to specify an url to an existing storage account (needed for ```image_url```)
452
491
  - The ```custom_data``` parameter can be used to specify custom data to provide to the instance. This can be a file or the data itself. This module handles base64 encoding for you.
453
492
  - The ```os_disk_size_gb``` parameter can be used to specify a custom os disk size.
493
+ - The ```azure_resource_group_prefix``` and ```azure_resource_group_suffix``` can be used to further disambiguate Azure resource group names created by the driver.
454
494
 
455
495
  ## Contributing
456
496
 
@@ -18,8 +18,16 @@ module Kitchen
18
18
  class Azurerm < Kitchen::Driver::Base
19
19
  attr_accessor :resource_management_client
20
20
 
21
+ default_config(:azure_resource_group_prefix) do |_config|
22
+ 'kitchen-'
23
+ end
24
+
25
+ default_config(:azure_resource_group_suffix) do |_config|
26
+ ''
27
+ end
28
+
21
29
  default_config(:azure_resource_group_name) do |config|
22
- "kitchen-#{config.instance.name}"
30
+ config.instance.name.to_s
23
31
  end
24
32
 
25
33
  default_config(:image_urn) do |_config|
@@ -110,6 +118,18 @@ module Kitchen
110
118
  true
111
119
  end
112
120
 
121
+ default_config(:data_disks) do |_config|
122
+ nil
123
+ end
124
+
125
+ default_config(:format_data_disks) do |_config|
126
+ false
127
+ end
128
+
129
+ default_config(:format_data_disks_powershell_script) do |_config|
130
+ false
131
+ end
132
+
113
133
  def create(state)
114
134
  state = validate_state(state)
115
135
  deployment_parameters = {
@@ -161,7 +181,7 @@ module Kitchen
161
181
 
162
182
  credentials = Kitchen::Driver::Credentials.new.azure_credentials_for_subscription(config[:subscription_id], config[:azure_environment])
163
183
  management_endpoint = resource_manager_endpoint_url(config[:azure_environment])
164
- info "Azure environment: #{config[:azure_environment]}"
184
+ debug "Azure environment: #{config[:azure_environment]}"
165
185
  @resource_management_client = ::Azure::ARM::Resources::ResourceManagementClient.new(credentials, management_endpoint)
166
186
  @resource_management_client.subscription_id = config[:subscription_id]
167
187
 
@@ -187,6 +207,13 @@ module Kitchen
187
207
  deployment_name = "deploy-#{state[:uuid]}"
188
208
  info "Creating deployment: #{deployment_name}"
189
209
  resource_management_client.deployments.begin_create_or_update_async(state[:azure_resource_group_name], deployment_name, deployment(deployment_parameters)).value!
210
+ follow_deployment_until_end_state(state[:azure_resource_group_name], deployment_name)
211
+ if File.file?(config[:pre_deployment_template])
212
+ pre_deployment_name = "pre-deploy-#{state[:uuid]}"
213
+ info "Creating deployment: #{pre_deployment_name}"
214
+ resource_management_client.deployments.begin_create_or_update_async(state[:azure_resource_group_name], pre_deployment_name, pre_deployment(config[:pre_deployment_template], config[:pre_deployment_parameters])).value!
215
+ follow_deployment_until_end_state(state[:azure_resource_group_name], post_deployment_name)
216
+ end
190
217
  rescue ::MsRestAzure::AzureOperationError => operation_error
191
218
  rest_error = operation_error.body['error']
192
219
  deployment_active = rest_error['code'] == 'DeploymentActive'
@@ -199,9 +226,6 @@ module Kitchen
199
226
  end
200
227
  end
201
228
 
202
- # Monitor all operations until completion
203
- follow_deployment_until_end_state(state[:azure_resource_group_name], deployment_name)
204
-
205
229
  network_management_client = ::Azure::ARM::Network::NetworkManagementClient.new(credentials, management_endpoint)
206
230
  network_management_client.subscription_id = config[:subscription_id]
207
231
 
@@ -236,7 +260,22 @@ module Kitchen
236
260
 
237
261
  def azure_resource_group_name
238
262
  formatted_time = Time.now.utc.strftime '%Y%m%dT%H%M%S'
239
- "#{config[:azure_resource_group_name]}-#{formatted_time}"
263
+ "#{config[:azure_resource_group_prefix]}#{config[:azure_resource_group_name]}-#{formatted_time}#{config[:azure_resource_group_suffix]}"
264
+ end
265
+
266
+ def data_disks_for_vm_json
267
+ return nil if config[:data_disks].nil?
268
+ disks = []
269
+
270
+ if config[:use_managed_disks]
271
+ config[:data_disks].each do |data_disk|
272
+ disks << { name: "datadisk#{data_disk[:lun]}", lun: data_disk[:lun], diskSizeGB: data_disk[:disk_size_gb], createOption: 'Empty' }
273
+ end
274
+ debug "Additional disks being added to configuration: #{disks.inspect}"
275
+ else
276
+ warn 'Data disks are only supported when used with the "use_managed_disks" option. No additional disks were added to the configuration.'
277
+ end
278
+ disks.to_json
240
279
  end
241
280
 
242
281
  def template_for_transport_name
@@ -244,7 +283,7 @@ module Kitchen
244
283
  if instance.transport.name.casecmp('winrm').zero?
245
284
  if instance.platform.name.index('nano').nil?
246
285
  info 'Adding WinRM configuration to provisioning profile.'
247
- encoded_command = Base64.strict_encode64(enable_winrm_powershell_script)
286
+ encoded_command = Base64.strict_encode64(custom_data_script_windows)
248
287
  template['resources'].select { |h| h['type'] == 'Microsoft.Compute/virtualMachines' }.each do |resource|
249
288
  resource['properties']['osProfile']['customData'] = encoded_command
250
289
  resource['properties']['osProfile']['windowsConfiguration'] = windows_unattend_content
@@ -399,10 +438,46 @@ winrm set winrm/config/service/auth '@{Basic="true";Kerberos="false";Negotiate="
399
438
  New-NetFirewallRule -DisplayName "Windows Remote Management (HTTPS-In)" -Name "Windows Remote Management (HTTPS-In)" -Profile Any -LocalPort 5986 -Protocol TCP
400
439
  winrm set winrm/config/service '@{AllowUnencrypted="true"}'
401
440
  New-NetFirewallRule -DisplayName "Windows Remote Management (HTTP-In)" -Name "Windows Remote Management (HTTP-In)" -Profile Any -LocalPort 5985 -Protocol TCP
402
- logoff
403
441
  PS1
404
442
  end
405
443
 
444
+ def format_data_disks_powershell_script
445
+ return unless config[:format_data_disks]
446
+ info 'Data disks will be initialized and formatted NTFS automatically.' unless config[:data_disks].nil?
447
+ config[:format_data_disks_powershell_script] || <<-PS1
448
+ Write-Host "Initializing and formatting raw disks"
449
+ $disks = Get-Disk | where partitionstyle -eq 'raw'
450
+ $letters = New-Object System.Collections.ArrayList
451
+ $letters.AddRange( ('F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z') )
452
+ Function AvailableVolumes() {
453
+ $currentDrives = get-volume
454
+ ForEach ($v in $currentDrives) {
455
+ if ($letters -contains $v.DriveLetter.ToString()) {
456
+ Write-Host "Drive letter $($v.DriveLetter) is taken, moving to next letter"
457
+ $letters.Remove($v.DriveLetter.ToString())
458
+ }
459
+ }
460
+ }
461
+ ForEach ($d in $disks) {
462
+ AvailableVolumes
463
+ $driveLetter = $letters[0]
464
+ Write-Host "Creating volume $($driveLetter)"
465
+ $d | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -DriveLetter $driveLetter -UseMaximumSize
466
+ # Prevent error ' Cannot perform the requested operation while the drive is read only'
467
+ Start-Sleep 1
468
+ Format-Volume -FileSystem NTFS -NewFileSystemLabel "datadisk" -DriveLetter $driveLetter -Confirm:$false
469
+ }
470
+ PS1
471
+ end
472
+
473
+ def custom_data_script_windows
474
+ <<-EOH
475
+ #{enable_winrm_powershell_script}
476
+ #{format_data_disks_powershell_script}
477
+ logoff
478
+ EOH
479
+ end
480
+
406
481
  def custom_linux_configuration(public_key)
407
482
  <<-EOH
408
483
  {
@@ -440,10 +515,10 @@ logoff
440
515
 
441
516
  def virtual_machine_deployment_template
442
517
  if config[:vnet_id] == ''
443
- virtual_machine_deployment_template_file('public.erb', vm_tags: vm_tag_string(config[:vm_tags]), use_managed_disks: config[:use_managed_disks], image_url: config[:image_url], existing_storage_account_blob_url: config[:existing_storage_account_blob_url], image_id: config[:image_id], existing_storage_account_container: config[:existing_storage_account_container], custom_data: config[:custom_data], os_disk_size_gb: config[:os_disk_size_gb])
518
+ virtual_machine_deployment_template_file('public.erb', vm_tags: vm_tag_string(config[:vm_tags]), use_managed_disks: config[:use_managed_disks], image_url: config[:image_url], existing_storage_account_blob_url: config[:existing_storage_account_blob_url], image_id: config[:image_id], existing_storage_account_container: config[:existing_storage_account_container], custom_data: config[:custom_data], os_disk_size_gb: config[:os_disk_size_gb], data_disks_for_vm_json: data_disks_for_vm_json)
444
519
  else
445
520
  info "Using custom vnet: #{config[:vnet_id]}"
446
- virtual_machine_deployment_template_file('internal.erb', vnet_id: config[:vnet_id], subnet_id: config[:subnet_id], public_ip: config[:public_ip], vm_tags: vm_tag_string(config[:vm_tags]), use_managed_disks: config[:use_managed_disks], image_url: config[:image_url], existing_storage_account_blob_url: config[:existing_storage_account_blob_url], image_id: config[:image_id], existing_storage_account_container: config[:existing_storage_account_container], custom_data: config[:custom_data], os_disk_size_gb: config[:os_disk_size_gb])
521
+ virtual_machine_deployment_template_file('internal.erb', vnet_id: config[:vnet_id], subnet_id: config[:subnet_id], public_ip: config[:public_ip], vm_tags: vm_tag_string(config[:vm_tags]), use_managed_disks: config[:use_managed_disks], image_url: config[:image_url], existing_storage_account_blob_url: config[:existing_storage_account_blob_url], image_id: config[:image_id], existing_storage_account_container: config[:existing_storage_account_container], custom_data: config[:custom_data], os_disk_size_gb: config[:os_disk_size_gb], data_disks_for_vm_json: data_disks_for_vm_json)
447
522
  end
448
523
  end
449
524
 
@@ -236,7 +236,7 @@
236
236
  }
237
237
  },
238
238
  {
239
- "apiVersion": "2016-04-30-preview",
239
+ "apiVersion": "2017-03-30",
240
240
  "type": "Microsoft.Compute/virtualMachines",
241
241
  "name": "[variables('vmName')]",
242
242
  "location": "[variables('location')]",
@@ -327,6 +327,10 @@
327
327
  <%- end -%>
328
328
  }
329
329
  <%- end -%>
330
+ <%- unless data_disks_for_vm_json.nil? -%>
331
+ ,"dataDisks":
332
+ <%= data_disks_for_vm_json %>
333
+ <%- end -%>
330
334
  }
331
335
  },
332
336
  "tags": {
data/templates/public.erb CHANGED
@@ -255,7 +255,7 @@
255
255
  }
256
256
  },
257
257
  {
258
- "apiVersion": "2016-04-30-preview",
258
+ "apiVersion": "2017-03-30",
259
259
  "type": "Microsoft.Compute/virtualMachines",
260
260
  "name": "[variables('vmName')]",
261
261
  "location": "[variables('location')]",
@@ -327,6 +327,10 @@
327
327
  "createOption": "FromImage"
328
328
  }
329
329
  <%- end -%>
330
+ <%- unless data_disks_for_vm_json.nil? -%>
331
+ ,"dataDisks":
332
+ <%= data_disks_for_vm_json %>
333
+ <%- end -%>
330
334
  },
331
335
  "networkProfile": {
332
336
  "networkInterfaces": [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-azurerm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Preston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-20 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile