From eeb97341bb135a33c47d1d96a372147fdd2e0f50 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 8 Aug 2023 16:42:11 +0200 Subject: [PATCH] r/windows_virtual_machine: fixing the test when generating a vm --- .../windows_virtual_machine_resource_images_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/services/compute/windows_virtual_machine_resource_images_test.go b/internal/services/compute/windows_virtual_machine_resource_images_test.go index 5f234d20de063..2d3f3fbb7e379 100644 --- a/internal/services/compute/windows_virtual_machine_resource_images_test.go +++ b/internal/services/compute/windows_virtual_machine_resource_images_test.go @@ -475,6 +475,12 @@ func (WindowsVirtualMachineResource) generalizeVirtualMachine(ctx context.Contex return err } + if _, ok := ctx.Deadline(); !ok { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, 15*time.Minute) + defer cancel() + } + command := []string{ "$cmd = \"$Env:SystemRoot\\system32\\sysprep\\sysprep.exe\"", "$args = \"/generalize /oobe /mode:vm /quit\"", @@ -504,8 +510,11 @@ func (r WindowsVirtualMachineResource) cancelExistingAgreement(publisher string, return func(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) error { client := clients.Compute.MarketplaceAgreementsClient subscriptionId := clients.Account.SubscriptionId - ctx, cancel := context.WithDeadline(ctx, time.Now().Add(15*time.Minute)) - defer cancel() + if _, ok := ctx.Deadline(); !ok { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, 15*time.Minute) + defer cancel() + } idGet := agreements.NewOfferPlanID(subscriptionId, publisher, offer, sku) idCancel := agreements.NewPlanID(subscriptionId, publisher, offer, sku)