Skip to content

Commit

Permalink
refactor: VirtualmachineProperties needs a default for time created
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-Soghigian committed Jan 28, 2025
1 parent fe0c4a0 commit 3d0b0b9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions pkg/test/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package test

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
"github.com/imdario/mergo"
Expand Down Expand Up @@ -52,24 +53,17 @@ func VirtualMachine(overrides ...VirtualMachineOptions) *armcompute.VirtualMachi
if options.Properties == nil {
options.Properties = &armcompute.VirtualMachineProperties{}
}
if options.Properties.TimeCreated == nil {
options.Properties.TimeCreated = lo.ToPtr(time.Now())
}

// Construct the basic VM
vm := &armcompute.VirtualMachine{
ID: lo.ToPtr(fmt.Sprintf("/subscriptions/subscriptionID/resourceGroups/test-resourceGroup/providers/Microsoft.Compute/virtualMachines/%s", options.Name)),
Name: lo.ToPtr(options.Name),
Location: lo.ToPtr(options.Location),
Properties: &armcompute.VirtualMachineProperties{
// Minimal default properties can be set here if you like:
// HardwareProfile: &armcompute.HardwareProfile{
// VMSize: lo.ToPtr(armcompute.VirtualMachineSizeTypesStandardDS1V2),
// },
},
Tags: options.Tags,
}

// If the user wants to override the entire VirtualMachineProperties, apply it here
if options.Properties != nil {
vm.Properties = options.Properties
Properties: options.Properties,
Tags: options.Tags,
}

return vm
Expand Down

0 comments on commit 3d0b0b9

Please sign in to comment.