kitchen-azurerm 2.1.2 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d34cb889a331fa1622ad6e3729fe3ee619c06b5ab830ccc067ca6e17441be01
4
- data.tar.gz: a507483fd57dd9ac42ca96e2379d926bd6ad7aa924960374e6bd86298c196f3d
3
+ metadata.gz: 65f0cc54a62e738484f2f5469a37e476e0323bdd0ac59ef180e99a05de3fa0c8
4
+ data.tar.gz: dce34ba2cec4675d575aa4607f9b00874d4e504f8d5c7ee1ce1b18d1311b4434
5
5
  SHA512:
6
- metadata.gz: 995c517ffd324584166c51a7463b2bc9588754828c231351224474713b34bc19d0d9ca0714c93fb5c3cdb7d9409911034a7af5a2200ab90fdb89ec3d4f019c74
7
- data.tar.gz: 4d79344aba476cc4caf04ca35f785a47eeba4de4758d883f26bf0e7bc912c846cc91def32cbdd1fb5325d3bbfe6b9fe6a4adb1bd0c717054283dd6e580f5ed36
6
+ metadata.gz: cdf17e7f3013d461390749209072afbf0a7f8ef7969853467a66cd7b90471226b9848a36d89212c7148681cfcb27aa96bb5ac7d3e2e9e9ca38ac3d8839d7d987
7
+ data.tar.gz: 25d1728326d14b31470120ee867263fbf814ffe6758946705b64391c7948031fbefbbafc123baa23ea4f404089d16d30cecf3117c2bc9867a1e0dfab2fac33d3
@@ -67,10 +67,18 @@ module Kitchen
67
67
  # Requests deletion of a resource group, returning as soon as ARM
68
68
  # accepts the request rather than waiting for it to finish.
69
69
  #
70
+ # A group that is already gone counts as deleted: that is the outcome
71
+ # the caller asked for, and ARM answers 404. Treating that as an error
72
+ # wedged +kitchen destroy+ permanently for any instance whose resource
73
+ # group had been removed out of band - deleted in the portal to save
74
+ # money, or never created because +kitchen create+ failed early. Every
75
+ # subsequent destroy failed the same way, so the instance could only be
76
+ # cleared by hand-deleting its state file.
77
+ #
70
78
  # @param name [String] resource group name.
71
79
  # @return [void]
72
80
  def delete_resource_group(name)
73
- call(:delete, resource_group_path(name), api_version: RESOURCES_API_VERSION)
81
+ call(:delete, resource_group_path(name), api_version: RESOURCES_API_VERSION, allow: [404])
74
82
  nil
75
83
  end
76
84
 
@@ -302,7 +302,7 @@ module Kitchen
302
302
  dnsNameForPublicIP: "kitchen-#{state[:uuid]}",
303
303
  vmName: state[:vm_name],
304
304
  systemAssignedIdentity: config[:system_assigned_identity],
305
- userAssignedIdentities: config[:user_assigned_identities].to_h { |identity| [identity, {}] },
305
+ userAssignedIdentities: Array(config[:user_assigned_identities]).to_h { |identity| [identity, {}] },
306
306
  secretUrl: config[:secret_url],
307
307
  vaultName: config[:vault_name],
308
308
  vaultResourceGroup: config[:vault_resource_group],
@@ -315,7 +315,7 @@ module Kitchen
315
315
 
316
316
  parameters["nicName"] = nic_name(state)
317
317
  parameters["customData"] = prepared_custom_data unless config[:custom_data].to_s.empty?
318
- parameters["osDiskSizeGb"] = config[:os_disk_size_gb] unless config[:os_disk_size_gb].to_s.empty?
318
+ parameters["osDiskSizeGb"] = os_disk_size_gb unless config[:os_disk_size_gb].to_s.empty?
319
319
  parameters["nsgId"] = config[:nsg_id] unless config[:nsg_id].to_s.empty?
320
320
 
321
321
  parameters.merge(image_parameters)
@@ -333,6 +333,28 @@ module Kitchen
333
333
  { "imagePublisher" => publisher, "imageOffer" => offer, "imageSku" => sku, "imageVersion" => version }
334
334
  end
335
335
 
336
+ # The OS disk size, as a number ARM will accept.
337
+ #
338
+ # YAML makes +os_disk_size_gb: 64+ an Integer and +os_disk_size_gb: "64"+
339
+ # a String, and the ARM parameter is typed +int+ - Azure rejects the
340
+ # String outright rather than coercing it:
341
+ #
342
+ # The provided value for the template parameter 'osDiskSizeGb' is not
343
+ # valid. Expected a value of type 'Integer', but received a value of
344
+ # type 'String'.
345
+ #
346
+ # Quoting a number in kitchen.yml is an easy thing to do, and the driver
347
+ # already tolerates the same ambiguity for +boot_diagnostics_enabled+.
348
+ #
349
+ # @return [Integer]
350
+ # @raise [Kitchen::UserError] if the value is not a whole number.
351
+ def os_disk_size_gb
352
+ Integer(config[:os_disk_size_gb])
353
+ rescue ArgumentError, TypeError
354
+ raise Kitchen::UserError,
355
+ "os_disk_size_gb must be a whole number of gigabytes, but was #{config[:os_disk_size_gb].inspect}."
356
+ end
357
+
336
358
  # Whether managed boot diagnostics should be switched on.
337
359
  #
338
360
  # Historically this setting defaulted to the *string* +"true"+, and plenty
@@ -561,26 +583,47 @@ module Kitchen
561
583
  template["resources"].select { |resource| resource["type"] == "Microsoft.Compute/virtualMachines" }
562
584
  end
563
585
 
586
+ # Serializes the generate-and-write below.
587
+ #
588
+ # Test Kitchen runs instances as threads inside one process, so
589
+ # +kitchen create -c+ had every thread reach the "does the key exist?"
590
+ # check before any of them had written one. Each generated its own pair
591
+ # and wrote it over the last, so only the instance whose key happened to
592
+ # land on disk last was reachable - the rest were deployed with a public
593
+ # key nobody held the private half of, and failed at converge with
594
+ # +Permission denied (publickey)+.
595
+ #
596
+ # @return [Mutex]
597
+ KEY_GENERATION_MUTEX = Mutex.new
598
+
564
599
  # Returns the public key to inject into the deployment, generating a new
565
600
  # key pair on disk when the configured private key does not yet exist.
566
601
  #
567
602
  # @param private_key_filename [String] path to the transport's private key.
568
603
  # @return [String] the OpenSSH-format public key, stripped of whitespace.
569
604
  def public_key_for_deployment(private_key_filename)
570
- unless File.file?(private_key_filename)
571
- key = SSHKey.generate
605
+ KEY_GENERATION_MUTEX.synchronize do
606
+ generate_key_pair(private_key_filename) unless File.file?(private_key_filename)
572
607
 
573
- ::FileUtils.mkdir_p(File.dirname(private_key_filename))
574
- File.write(private_key_filename, key.private_key)
575
- File.chmod(0600, private_key_filename)
576
- File.write("#{private_key_filename}.pub", key.ssh_public_key)
577
- File.chmod(0600, "#{private_key_filename}.pub")
578
-
579
- return key.ssh_public_key.strip
608
+ public_key_filename = instance.transport[:ssh_public_key] || "#{private_key_filename}.pub"
609
+ File.read(public_key_filename).strip
580
610
  end
611
+ end
612
+
613
+ # Writes a fresh SSH key pair to disk.
614
+ #
615
+ # Always called with {KEY_GENERATION_MUTEX} held.
616
+ #
617
+ # @param private_key_filename [String] path to write the private key to.
618
+ # @return [void]
619
+ def generate_key_pair(private_key_filename)
620
+ key = SSHKey.generate
581
621
 
582
- public_key_filename = instance.transport[:ssh_public_key] || "#{private_key_filename}.pub"
583
- File.read(public_key_filename).strip
622
+ ::FileUtils.mkdir_p(File.dirname(private_key_filename))
623
+ File.write(private_key_filename, key.private_key)
624
+ File.chmod(0600, private_key_filename)
625
+ File.write("#{private_key_filename}.pub", key.ssh_public_key)
626
+ File.chmod(0600, "#{private_key_filename}.pub")
584
627
  end
585
628
 
586
629
  # Builds the pre-deployment from a caller-supplied ARM template file.
@@ -940,8 +983,11 @@ module Kitchen
940
983
  data = {
941
984
  vm_tags: vm_tag_string(config[:vm_tags]),
942
985
  storage_account_type: config[:storage_account_type],
943
- image_id: config[:image_id],
944
- custom_data: config[:custom_data],
986
+ # A setting written with no value is nil, not "". The templates ask
987
+ # these two whether they are empty, so give them something that can
988
+ # answer.
989
+ image_id: config[:image_id].to_s,
990
+ custom_data: config[:custom_data].to_s,
945
991
  os_disk_size_gb: config[:os_disk_size_gb],
946
992
  data_disks_for_vm_json:,
947
993
  use_ephemeral_osdisk: config[:use_ephemeral_osdisk],
@@ -6,6 +6,6 @@ module Kitchen
6
6
  # driver and, with it, the whole Azure SDK.
7
7
  #
8
8
  # @return [String]
9
- AZURERM_VERSION = "2.1.2".freeze
9
+ AZURERM_VERSION = "2.1.4".freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-azurerm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Preston
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '1.20'
59
+ version: '3.0'
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '5.0'
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '1.20'
69
+ version: '3.0'
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '5.0'