Skip to content

Commit 580360c

Browse files
selzocaramprice
andcommitted
Fix azure packer plugin output parsing
A feature was added to the azure packer plugin to support multiple output formats. As part of this change, the expected "OSDiskUri" log message was namespaced to "VHDOSDiskUri". We made this code a bit more resilient, and it looks for a match instead of a exact starting string. ref: hashicorp/packer-plugin-azure#522 Co-authored-by: Aram Price <[email protected]>
1 parent 2c32446 commit 580360c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/stemcell/builder/azure.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ def parse_packer_output(packer_output)
7272
def parse_disk_uri(line)
7373
return unless line.include?("azure-arm,artifact,0") && line.include?("OSDiskUri:")
7474

75-
os_disk_uri = (line.split '\n').select do |s|
76-
s.start_with?("OSDiskUri: ")
77-
end.first.gsub("OSDiskUri: ", "").strip
75+
os_disk_uri = line.split('\n')
76+
.find { |s| s.match?("OSDiskUri") }
77+
.split(": ")
78+
.last
79+
.strip
7880

7981
create_signed_url(os_disk_uri)
8082
end

spec/stemcell/builder/azure_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
command = 'build'
2020
manifest_contents = 'manifest_contents'
2121
packer_vars = {some_var: 'some-value'}
22-
disk_image_url = 'some-disk-image-url'
22+
disk_image_url = 'https://some-disk-image-url'
2323
client_id = 'some-client-id'
2424
client_secret = 'some-client-secret'
2525
tenant_id = 'some-tenant-id'
@@ -32,7 +32,7 @@
3232
offer = 'some-offer'
3333
sku = 'some-sku'
3434
vm_prefix = 'some-vm-prefix'
35-
packer_output = "azure-arm,artifact,0\\nOSDiskUri: #{disk_image_url}"
35+
packer_output = "azure-arm,artifact,0\\nVHDOSDiskUri: #{disk_image_url}"
3636

3737
packer_config = double(:packer_config)
3838
allow(packer_config).to receive(:dump).and_return(config)

0 commit comments

Comments
 (0)