Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Template Capture from ARM Builder And Fail Fast when SIG Version already exists #3

Merged
merged 3 commits into from
Jul 6, 2023

Conversation

JenGoldstrich
Copy link
Owner

Remove Template Capture, defeating a legacy TODO from 2016!

There's a lot of history here but the TL;Dr is we had to use TemplateCapture to get the VMID a UUID that is an internal ID that is used when capturing a VHD with the plugin. We can just query the VM API now though unlike in 2016 to get this ID, removing the need for this messy solution

@@ -206,6 +203,14 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
if err != nil {
return nil, fmt.Errorf("the Shared Gallery Image '%s' to which to publish the managed image version to does not exist in the resource group '%s' or does not contain managed image '%s'", b.config.SharedGalleryDestination.SigDestinationGalleryName, b.config.SharedGalleryDestination.SigDestinationResourceGroup, b.config.SharedGalleryDestination.SigDestinationImageName)
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change allows us to fail faster when the SIG version we're already publishing to exists, this would previously fail after the creation of the Build VM when trying to create the SIG version

s.say("Capturing VHD ...")
err = s.captureVhd(ctx, vmId, vmCaptureParameters)
if err != nil {
state.Put(constants.Error, err)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is a bit messy now but I was having errors where the error was not correctly being passed into nested loops, so this felt simpler

@JenGoldstrich JenGoldstrich changed the title Remove Template Capture from ARM Builder Remove Template Capture from ARM Builder And Fail Fast when SIG Version already exists Jul 3, 2023
Copy link

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple suggestions/questions, but the code looks good to me, it's always nice to see some HACK removed :)
Good job!

return nil
}

// HACK(chrboum): This method is a hack. It was written to work around this issue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it when we remove code that starts with a comment like this one :D

vmId := vmResponse.Model.Properties.VMId
return *vmId, nil
}
return "", nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder when does that happen? Shouldn't that be an error if no ID is found in this case?

return "", err
}
if vmResponse.Model != nil {
vmId := vmResponse.Model.Properties.VMId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, don't know how likely it is to happen, but can Properties be nil here? If so this will crash upon dereferencing it.

Copy link
Owner Author

@JenGoldstrich JenGoldstrich Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I think I need to standardize this across the plugin, null checking returned Models/properties from the new SDK, so I'd like to push off figuring that out to a later PR

state.Put(constants.Error, err)
s.error(err)
return multistep.ActionHalt
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the if ends with a return statement, you can remove this else and move the contents one level up

state.Put(constants.Error, err)
s.error(err)
return multistep.ActionHalt
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this else is unnecessary since the if ends with a return

@JenGoldstrich JenGoldstrich merged commit 3dc24d9 into main Jul 6, 2023
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants