-
Notifications
You must be signed in to change notification settings - Fork 80
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
[V2] Migrate all builders to hashicorp/go-azure-sdk #326
Conversation
591af90
to
32dd4a9
Compare
@@ -112,13 +126,14 @@ func (s *StepDeployTemplate) Cleanup(state multistep.StateBag) { | |||
} | |||
if !state.Get(constants.ArmKeepOSDisk).(bool) { | |||
ui.Say(fmt.Sprintf(" Deleting -> %s : '%s'", imageType, imageName)) | |||
err = s.deleteDisk(context.TODO(), imageName, resourceGroupName, isManagedDisk) | |||
err = s.deleteDisk(ctx, imageName, resourceGroupName, (isManagedDisk || isSIGImage), subscriptionId, armStorageAccountName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the change that fixes #315, since before SIG images would use the VHD deletion path
go.mod
Outdated
github.com/hashicorp/hcl/v2 v2.16.2 | ||
github.com/hashicorp/packer-plugin-sdk v0.5.1 | ||
github.com/hashicorp/packer-plugin-sdk v0.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had downgraded temporarily this please let me know what version I should upgrade this back to for the release!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When ready you will need github.com/hashicorp/packer-plugin-sdk v0.5.1
with the go-cty fix for the Azure plugin
go get github.com/hashicorp/packer-plugin-sdk@v0.5.1
make install-packer-sdc
packer-sdc fix .
go mod tidy
@@ -3,32 +3,32 @@ module github.com/hashicorp/packer-plugin-azure | |||
go 1.19 | |||
|
|||
require ( | |||
github.com/Azure/azure-sdk-for-go v64.0.0+incompatible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jenna this is looking good already. Thank you a 💯 times for taking on this work and doing such a great job leading the effort.
I believe most of these changes have been reviewed from the previous PRs correct?
I've slated time to go over the changes on Monday. To help with the review a bit could you rebase and squash the commits into logical PR merges? It would make it easy to cross reference.
go.mod
Outdated
github.com/hashicorp/hcl/v2 v2.16.2 | ||
github.com/hashicorp/packer-plugin-sdk v0.5.1 | ||
github.com/hashicorp/packer-plugin-sdk v0.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When ready you will need github.com/hashicorp/packer-plugin-sdk v0.5.1
with the go-cty fix for the Azure plugin
go get github.com/hashicorp/packer-plugin-sdk@v0.5.1
make install-packer-sdc
packer-sdc fix .
go mod tidy
Rebasing entire ARM builder migration on top of main Remove some missed old SDK stuff, including the autorest To package from ARM Builder Update oidc-example.json Pass SIG ID subscription through to state Use Hamilton MSGraph SDK to fetch Object ID for Windows builds Format and add comment commit generated code Switch AuthType back to private variable and use helper function to get it, switch from MeClient to ServicePrincipals client to get objectID Print MSgraph error again Don't use Hamilton, get it from the Access Token fmt and pass in correct context on cleanup Mess with backoff time while testing to see if this can be a bit smoother of a process for users Don't use context.TODOs in ARM Builder client calls Use hcl file in oidc test Use Giovanni instead of Blob Container serivce Implement new SDK environment logic Address fmt Remove unused function, go mod tidy Switch to forked release process
…eplicated to DTL/Chroot
…ing to create it Implement Lucas's feedback Make generate
======= DTL almost done! Just need to get VMID instead of capture template method and start testing Port DTL provisioner to new SDK Make generate Accidently commited playing around with this field, but was missing comma Appease the lint lord DTL never supported VHDs, it just had all the code of it, so I didn't need to port some of this Use retry config instead of an infinite loop Delete more unused code Update comments Address linter
==== EOD WIP: I've ported all the client code over, on Monday I will test that it works in a VM before porting the unit tests as the mocking strategy used is heavily reliant on auto rest, and I want to port it to stretchify mocks that don't care as much about the autorest specifics Don't use Subscription ID as Snapshot URL Large commit: Chroot unit tests passing, azure-sdk-for-go no longer imported by go.mod, remove references to device code, clear up missing pieces of DTL builder Fix linux disk attatcher Remove unnused mock that I added earlier Re-add Fetching of Tenant ID Forgot to use New Steps null check was wrong way for SDK model see above Don't try and get tenant ID if we're using CLI auth Address linter, fix linux test StepCreateNewDiskTest -> Return proper autorest future fake remove device code acceptance tests, handle flakey unit test by sorting resulting objects to insure consistant comparison Update builder/azure/chroot/step_verify_source_disk_test.go Co-authored-by: Lucas Bajolet <105649352+lbajolet-hashicorp@users.noreply.github.com> Remove CHRoot Acceptance Test && rename all hashi* imports removing prefix Make generate and fix lint Readd subscription, tenant ID fetching for CLI auth, so we know which subscription to save stuff to, this caused acceptance test failures which this commit fixes Lint
…ntext timeout throughout codebase Reset readme, version file, and workflows to state in main origin
[chroot] PollingDelay != Polling Duration >_>
… remove VHD Deprecation
@nywilken done and done! |
@@ -526,27 +526,6 @@ prevent running afoul of Azure decency controls. | |||
The password alphabet used for random values is | |||
**0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ**. | |||
|
|||
### Deprecation Warning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will post a longer clarification on the removal of the deprecation warning for VHDs in the release notes for v2.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good. I have a few suggestions to help improve readability. I'm still working through a few more of the commits.
@@ -56,7 +50,7 @@ type Artifact struct { | |||
StateData map[string]interface{} | |||
} | |||
|
|||
func NewManagedImageArtifact(osType, resourceGroup, name, location, id, osDiskSnapshotName, dataDiskSnapshotPrefix string, generatedData map[string]interface{}, keepOSDisk bool, template *CaptureTemplate, getSasUrl func(name string) string) (*Artifact, error) { | |||
func NewManagedImageArtifact(osType, resourceGroup, name, location, id, osDiskSnapshotName, dataDiskSnapshotPrefix string, generatedData map[string]interface{}, osDiskUri string) (*Artifact, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future todo - we should rethink the number of parameters for this function.
return nil, fmt.Errorf("malformed capture template, expected one resource") | ||
} | ||
func NewArtifact(vmInternalID string, storageAccountUrl string, storageAccountLocation string, osType string, additionalDiskCount int, generatedData map[string]interface{}) (*Artifact, error) { | ||
vhdUri := fmt.Sprintf("%ssystem/Microsoft.Compute/Images/images/packer-osDisk.%s.vhd", storageAccountUrl, vmInternalID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I was to create an Artifact without this constructor artifact := &Artifact{//...}
how would I know the values to be used for OSDiskUri and TemplateUri?
Should there be functions for generating these values with valid inputs?
When it comes to generating the vhdUri do we need to validate that the storageAccountUrl ends with a /
?
If so maybe we use the url
package for joining URL strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to close the loop - as we discuss internally we will hold on refactors to not introduce untested changes.
if err != nil { | ||
return nil, err | ||
} | ||
templateUri := fmt.Sprintf("%ssystem/Microsoft.Compute/Images/images/packer-vmTemplate.%s.json", storageAccountUrl, vmInternalID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto on having a generate template URI function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done. Please use the upgrade notes sections once released to communicate major breaking changes and migration steps for folks using v1 of the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few nits, but overall this looks good @JenGoldstrich! Good job on that
builder/azure/arm/config.go
Outdated
@@ -1239,6 +1245,11 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) { | |||
} | |||
if c.SharedGalleryDestination.SigDestinationImageVersion == "" { | |||
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("An image_version must be specified for shared_image_gallery_destination")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is a pattern in the codebase, but I would think we can only check for the regex match and combine the two messages in one like An image_version must be specified for shared_image_gallery_destination and must follow the Major(int).Minor(int).Patch(int) format
.
This can be done later of course as there's already a lot here, but I would think this gives a user more information on how to solve the issue while only checking once in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point, I will make that change
@@ -525,25 +525,25 @@ func TestConfigInstantiatesCorrectAzureEnvironment(t *testing.T) { | |||
"communicator": "none", | |||
} | |||
|
|||
// user input is fun :) | |||
// user input is fun :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best change of the whole PR
s.say(s.client.LastError.Error()) | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think you can return err
in the main path as you did for captureImageFromVM
if err != nil { | ||
return err | ||
} | ||
|
||
return f.WaitForCompletionRef(ctx, s.client.DeploymentsClient.Client) | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could become a return err
if you remove the error check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: I see this in several places in the code, so maybe that's a cleanup to do for later as well
This PR combines several other PRs which remove the now deprecated "track 1" SDK we were using and switching over to the same SDK that the Terraform AzureRM provider uses https://github.com/hashicorp/go-azure-sdk
Removes VHD Deprecation warning
Removes
use_interactive_auth
from ARM/DTL builders, we recommend using the Azure CLI viaaz login --use-device-code
and then using Azure CLI authadds
winrm_expiration_time
field to the ARM builder#306 - ARM Builder
JenGoldstrich#4 - DTL Builder
JenGoldstrich#5 - Chroot Builder
JenGoldstrich#3 - Unwind template capture TODO
JenGoldstrich#6 - Add Expiry Winrm Field, fail fast on in valid SIG version, and poll consistently as new SDK expects
closes #243
closes #250
closes #235
closes #187
closes #315