Skip to content

Commit

Permalink
Refactor Cleanup of deployment to reduce extra errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JenGoldstrich committed Apr 29, 2024
1 parent e82be53 commit 8090c68
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 182 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 8090c68

Please sign in to comment.