Skip to content

Commit

Permalink
Refactor Cleanup of deployment to reduce extra errors
Browse files Browse the repository at this point in the history
Also fix storage account incorrect storage URI on VHD builds

Ensure VM is always deleted first

Remove extaenous print statements introduced in v2.0.0

Update builder/azure/arm/step_deploy_template.go

Co-authored-by: Lucas Bajolet <105649352+lbajolet-hashicorp@users.noreply.github.com>

Fix Lucas's suggested commit

whoops

refactor step deploy template for easier unit testing

Fix additional disk error

Fix incorrect unit test case, this was checking if a variable we set as 1 was 1, without ever changing it

Implement Lucas's feedback

wip

Finish using shared function for deleting singular resources with retries

Lucas's final feedback
  • Loading branch information
JenGoldstrich committed Apr 29, 2024
1 parent e82be53 commit a542433
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 180 deletions.
7 changes: 3 additions & 4 deletions builder/azure/arm/azure_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func errorCapture(client *AzureClient) client.ResponseMiddleware {
}

// Returns an Azure Client used for the Azure Resource Manager
func NewAzureClient(ctx context.Context, isVHDBuild bool, cloud *environments.Environment, sharedGalleryTimeout time.Duration, pollingDuration time.Duration, authOptions commonclient.AzureAuthOptions) (*AzureClient, error) {
func NewAzureClient(ctx context.Context, storageAccountName string, cloud *environments.Environment, sharedGalleryTimeout time.Duration, pollingDuration time.Duration, authOptions commonclient.AzureAuthOptions) (*AzureClient, error) {

var azureClient = &AzureClient{}

Expand Down Expand Up @@ -230,13 +230,12 @@ func NewAzureClient(ctx context.Context, isVHDBuild bool, cloud *environments.En
azureClient.GalleryImagesClient = *galleryImagesClient

// We only need the Blob Client to delete the OS VHD during VHD builds
if isVHDBuild {
if storageAccountName != "" {
storageAccountAuthorizer, err := commonclient.BuildStorageAuthorizer(ctx, authOptions, *cloud)
if err != nil {
return nil, err
}

blobClient, err := giovanniBlobStorageSDK.NewWithBaseUri(cloud.Storage.Name())
blobClient, err := giovanniBlobStorageSDK.NewWithBaseUri(fmt.Sprintf("https://%s.blob.core.windows.net", storageAccountName))
if err != nil {
return nil, err
}
Expand Down
6 changes: 1 addition & 5 deletions builder/azure/arm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
}

ui.Message("Creating Azure Resource Manager (ARM) client ...")
// For VHD Builds we need to enable the Blob Azure Storage client
configureBlobClient := (b.config.ResourceGroupName != "" || b.config.StorageAccount != "")
azureClient, err := NewAzureClient(
ctx,
configureBlobClient,
b.config.StorageAccount,
b.config.ClientConfig.CloudEnvironment(),
b.config.SharedGalleryTimeout,
b.config.PollingDurationTimeout,
Expand Down Expand Up @@ -474,8 +472,6 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
if b.config.isPublishToSIG() {
return b.sharedImageArtifact(stateData)
}
ui.Say(b.config.storageAccountBlobEndpoint)
ui.Say(fmt.Sprintf("%d", len(b.config.AdditionalDiskSize)))
return NewArtifact(
b.stateBag.Get(constants.ArmBuildVMInternalId).(string),
b.config.CaptureNamePrefix,
Expand Down
Loading

0 comments on commit a542433

Please sign in to comment.