Skip to content

Commit 57fac81

Browse files
authored
Merge pull request #1754 from gruntwork-io/fix/azure-restore-deprecated-wrappers
fix(azure): restore deprecated non-Context wrappers for backward compatibility
2 parents 170548e + 65b6a39 commit 57fac81

10 files changed

Lines changed: 874 additions & 0 deletions

File tree

modules/azure/availabilityset.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12+
// AvailabilitySetExists indicates whether the specified Azure Availability Set exists.
13+
// This function would fail the test if there is an error.
14+
//
15+
// Deprecated: Use [AvailabilitySetExistsContext] instead.
16+
func AvailabilitySetExists(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) bool {
17+
t.Helper()
18+
19+
return AvailabilitySetExistsContext(t, context.Background(), avsName, resGroupName, subscriptionID)
20+
}
21+
22+
// AvailabilitySetExistsE indicates whether the specified Azure Availability Set exists.
23+
//
24+
// Deprecated: Use [AvailabilitySetExistsContextE] instead.
25+
func AvailabilitySetExistsE(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) (bool, error) {
26+
t.Helper()
27+
28+
return AvailabilitySetExistsContextE(t, context.Background(), avsName, resGroupName, subscriptionID)
29+
}
30+
1231
// AvailabilitySetExistsContext indicates whether the specified Azure Availability Set exists.
1332
// This function would fail the test if there is an error.
1433
// The ctx parameter supports cancellation and timeouts.
@@ -36,6 +55,25 @@ func AvailabilitySetExistsContextE(t testing.TestingT, ctx context.Context, avsN
3655
return true, nil
3756
}
3857

58+
// CheckAvailabilitySetContainsVM checks if the Virtual Machine is contained in the Availability Set VMs.
59+
// This function would fail the test if there is an error.
60+
//
61+
// Deprecated: Use [CheckAvailabilitySetContainsVMContext] instead.
62+
func CheckAvailabilitySetContainsVM(t testing.TestingT, vmName string, avsName string, resGroupName string, subscriptionID string) bool {
63+
t.Helper()
64+
65+
return CheckAvailabilitySetContainsVMContext(t, context.Background(), vmName, avsName, resGroupName, subscriptionID)
66+
}
67+
68+
// CheckAvailabilitySetContainsVME checks if the Virtual Machine is contained in the Availability Set VMs.
69+
//
70+
// Deprecated: Use [CheckAvailabilitySetContainsVMContextE] instead.
71+
func CheckAvailabilitySetContainsVME(t testing.TestingT, vmName string, avsName string, resGroupName string, subscriptionID string) (bool, error) {
72+
t.Helper()
73+
74+
return CheckAvailabilitySetContainsVMContextE(t, context.Background(), vmName, avsName, resGroupName, subscriptionID)
75+
}
76+
3977
// CheckAvailabilitySetContainsVMContext checks if the Virtual Machine is contained in the Availability Set VMs.
4078
// This function would fail the test if there is an error.
4179
// The ctx parameter supports cancellation and timeouts.
@@ -71,6 +109,25 @@ func CheckAvailabilitySetContainsVMContextE(t testing.TestingT, ctx context.Cont
71109
return false, NewNotFoundError("Virtual Machine", vmName, avsName)
72110
}
73111

112+
// GetAvailabilitySetVMNamesInCaps gets a list of VM names in the specified Azure Availability Set.
113+
// This function would fail the test if there is an error.
114+
//
115+
// Deprecated: Use [GetAvailabilitySetVMNamesInCapsContext] instead.
116+
func GetAvailabilitySetVMNamesInCaps(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) []string {
117+
t.Helper()
118+
119+
return GetAvailabilitySetVMNamesInCapsContext(t, context.Background(), avsName, resGroupName, subscriptionID)
120+
}
121+
122+
// GetAvailabilitySetVMNamesInCapsE gets a list of VM names in the specified Azure Availability Set.
123+
//
124+
// Deprecated: Use [GetAvailabilitySetVMNamesInCapsContextE] instead.
125+
func GetAvailabilitySetVMNamesInCapsE(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) ([]string, error) {
126+
t.Helper()
127+
128+
return GetAvailabilitySetVMNamesInCapsContextE(t, context.Background(), avsName, resGroupName, subscriptionID)
129+
}
130+
74131
// GetAvailabilitySetVMNamesInCapsContext gets a list of VM names in the specified Azure Availability Set.
75132
// This function would fail the test if there is an error.
76133
// The ctx parameter supports cancellation and timeouts.
@@ -108,6 +165,25 @@ func GetAvailabilitySetVMNamesInCapsContextE(t testing.TestingT, ctx context.Con
108165
return vms, nil
109166
}
110167

168+
// GetAvailabilitySetFaultDomainCount gets the Fault Domain Count for the specified Azure Availability Set.
169+
// This function would fail the test if there is an error.
170+
//
171+
// Deprecated: Use [GetAvailabilitySetFaultDomainCountContext] instead.
172+
func GetAvailabilitySetFaultDomainCount(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) int32 {
173+
t.Helper()
174+
175+
return GetAvailabilitySetFaultDomainCountContext(t, context.Background(), avsName, resGroupName, subscriptionID)
176+
}
177+
178+
// GetAvailabilitySetFaultDomainCountE gets the Fault Domain Count for the specified Azure Availability Set.
179+
//
180+
// Deprecated: Use [GetAvailabilitySetFaultDomainCountContextE] instead.
181+
func GetAvailabilitySetFaultDomainCountE(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) (int32, error) {
182+
t.Helper()
183+
184+
return GetAvailabilitySetFaultDomainCountContextE(t, context.Background(), avsName, resGroupName, subscriptionID)
185+
}
186+
111187
// GetAvailabilitySetFaultDomainCountContext gets the Fault Domain Count for the specified Azure Availability Set.
112188
// This function would fail the test if there is an error.
113189
// The ctx parameter supports cancellation and timeouts.
@@ -131,6 +207,15 @@ func GetAvailabilitySetFaultDomainCountContextE(t testing.TestingT, ctx context.
131207
return *avs.Properties.PlatformFaultDomainCount, nil
132208
}
133209

210+
// GetAvailabilitySetE gets an Availability Set in the specified Azure Resource Group.
211+
//
212+
// Deprecated: Use [GetAvailabilitySetContextE] instead.
213+
func GetAvailabilitySetE(t testing.TestingT, avsName string, resGroupName string, subscriptionID string) (*armcompute.AvailabilitySet, error) {
214+
t.Helper()
215+
216+
return GetAvailabilitySetContextE(t, context.Background(), avsName, resGroupName, subscriptionID)
217+
}
218+
134219
// GetAvailabilitySetContextE gets an Availability Set in the specified Azure Resource Group.
135220
// The ctx parameter supports cancellation and timeouts.
136221
func GetAvailabilitySetContextE(t testing.TestingT, ctx context.Context, avsName string, resGroupName string, subscriptionID string) (*armcompute.AvailabilitySet, error) {

modules/azure/compute.go

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ func GetVirtualMachineClientE(subscriptionID string) (*armcompute.VirtualMachine
5252
return GetVirtualMachineClientContextE(context.Background(), subscriptionID)
5353
}
5454

55+
// VirtualMachineExists indicates whether the specified Azure Virtual Machine exists.
56+
// This function would fail the test if there is an error.
57+
//
58+
// Deprecated: Use [VirtualMachineExistsContext] instead.
59+
func VirtualMachineExists(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) bool {
60+
t.Helper()
61+
62+
return VirtualMachineExistsContext(t, context.Background(), vmName, resGroupName, subscriptionID)
63+
}
64+
65+
// VirtualMachineExistsE indicates whether the specified Azure Virtual Machine exists.
66+
//
67+
// Deprecated: Use [VirtualMachineExistsContextE] instead.
68+
func VirtualMachineExistsE(vmName string, resGroupName string, subscriptionID string) (bool, error) {
69+
return VirtualMachineExistsContextE(context.Background(), vmName, resGroupName, subscriptionID)
70+
}
71+
5572
// VirtualMachineExistsContext indicates whether the specified Azure Virtual Machine exists.
5673
// This function would fail the test if there is an error.
5774
// The ctx parameter supports cancellation and timeouts.
@@ -79,6 +96,23 @@ func VirtualMachineExistsContextE(ctx context.Context, vmName string, resGroupNa
7996
return true, nil
8097
}
8198

99+
// GetVirtualMachineNics gets a list of Network Interface names for a specified Azure Virtual Machine.
100+
// This function would fail the test if there is an error.
101+
//
102+
// Deprecated: Use [GetVirtualMachineNicsContext] instead.
103+
func GetVirtualMachineNics(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) []string {
104+
t.Helper()
105+
106+
return GetVirtualMachineNicsContext(t, context.Background(), vmName, resGroupName, subscriptionID)
107+
}
108+
109+
// GetVirtualMachineNicsE gets a list of Network Interface names for a specified Azure Virtual Machine.
110+
//
111+
// Deprecated: Use [GetVirtualMachineNicsContextE] instead.
112+
func GetVirtualMachineNicsE(vmName string, resGroupName string, subscriptionID string) ([]string, error) {
113+
return GetVirtualMachineNicsContextE(context.Background(), vmName, resGroupName, subscriptionID)
114+
}
115+
82116
// GetVirtualMachineNicsContext gets a list of Network Interface names for a specified Azure Virtual Machine.
83117
// This function would fail the test if there is an error.
84118
// The ctx parameter supports cancellation and timeouts.
@@ -124,6 +158,23 @@ func extractVMNics(vm *armcompute.VirtualMachine) ([]string, error) {
124158
return nics, nil
125159
}
126160

161+
// GetVirtualMachineManagedDisks gets the list of Managed Disk names of the specified Azure Virtual Machine.
162+
// This function would fail the test if there is an error.
163+
//
164+
// Deprecated: Use [GetVirtualMachineManagedDisksContext] instead.
165+
func GetVirtualMachineManagedDisks(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) []string {
166+
t.Helper()
167+
168+
return GetVirtualMachineManagedDisksContext(t, context.Background(), vmName, resGroupName, subscriptionID)
169+
}
170+
171+
// GetVirtualMachineManagedDisksE gets the list of Managed Disk names of the specified Azure Virtual Machine.
172+
//
173+
// Deprecated: Use [GetVirtualMachineManagedDisksContextE] instead.
174+
func GetVirtualMachineManagedDisksE(vmName string, resGroupName string, subscriptionID string) ([]string, error) {
175+
return GetVirtualMachineManagedDisksContextE(context.Background(), vmName, resGroupName, subscriptionID)
176+
}
177+
127178
// GetVirtualMachineManagedDisksContext gets the list of Managed Disk names of the specified Azure Virtual Machine.
128179
// This function would fail the test if there is an error.
129180
// The ctx parameter supports cancellation and timeouts.
@@ -159,6 +210,23 @@ func extractVMManagedDisks(vm *armcompute.VirtualMachine) []string {
159210
return diskNames
160211
}
161212

213+
// GetVirtualMachineOSDiskName gets the OS Disk name of the specified Azure Virtual Machine.
214+
// This function would fail the test if there is an error.
215+
//
216+
// Deprecated: Use [GetVirtualMachineOSDiskNameContext] instead.
217+
func GetVirtualMachineOSDiskName(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) string {
218+
t.Helper()
219+
220+
return GetVirtualMachineOSDiskNameContext(t, context.Background(), vmName, resGroupName, subscriptionID)
221+
}
222+
223+
// GetVirtualMachineOSDiskNameE gets the OS Disk name of the specified Azure Virtual Machine.
224+
//
225+
// Deprecated: Use [GetVirtualMachineOSDiskNameContextE] instead.
226+
func GetVirtualMachineOSDiskNameE(vmName string, resGroupName string, subscriptionID string) (string, error) {
227+
return GetVirtualMachineOSDiskNameContextE(context.Background(), vmName, resGroupName, subscriptionID)
228+
}
229+
162230
// GetVirtualMachineOSDiskNameContext gets the OS Disk name of the specified Azure Virtual Machine.
163231
// This function would fail the test if there is an error.
164232
// The ctx parameter supports cancellation and timeouts.
@@ -187,6 +255,23 @@ func extractVMOSDiskName(vm *armcompute.VirtualMachine) string {
187255
return *vm.Properties.StorageProfile.OSDisk.Name
188256
}
189257

258+
// GetVirtualMachineAvailabilitySetID gets the Availability Set ID of the specified Azure Virtual Machine.
259+
// This function would fail the test if there is an error.
260+
//
261+
// Deprecated: Use [GetVirtualMachineAvailabilitySetIDContext] instead.
262+
func GetVirtualMachineAvailabilitySetID(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) string {
263+
t.Helper()
264+
265+
return GetVirtualMachineAvailabilitySetIDContext(t, context.Background(), vmName, resGroupName, subscriptionID)
266+
}
267+
268+
// GetVirtualMachineAvailabilitySetIDE gets the Availability Set ID of the specified Azure Virtual Machine.
269+
//
270+
// Deprecated: Use [GetVirtualMachineAvailabilitySetIDContextE] instead.
271+
func GetVirtualMachineAvailabilitySetIDE(vmName string, resGroupName string, subscriptionID string) (string, error) {
272+
return GetVirtualMachineAvailabilitySetIDContextE(context.Background(), vmName, resGroupName, subscriptionID)
273+
}
274+
190275
// GetVirtualMachineAvailabilitySetIDContext gets the Availability Set ID of the specified Azure Virtual Machine.
191276
// This function would fail the test if there is an error.
192277
// The ctx parameter supports cancellation and timeouts.
@@ -232,6 +317,23 @@ type VMImage struct {
232317
Version string
233318
}
234319

320+
// GetVirtualMachineImage gets the Image of the specified Azure Virtual Machine.
321+
// This function would fail the test if there is an error.
322+
//
323+
// Deprecated: Use [GetVirtualMachineImageContext] instead.
324+
func GetVirtualMachineImage(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) VMImage {
325+
t.Helper()
326+
327+
return GetVirtualMachineImageContext(t, context.Background(), vmName, resGroupName, subscriptionID)
328+
}
329+
330+
// GetVirtualMachineImageE gets the Image of the specified Azure Virtual Machine.
331+
//
332+
// Deprecated: Use [GetVirtualMachineImageContextE] instead.
333+
func GetVirtualMachineImageE(vmName string, resGroupName string, subscriptionID string) (VMImage, error) {
334+
return GetVirtualMachineImageContextE(context.Background(), vmName, resGroupName, subscriptionID)
335+
}
336+
235337
// GetVirtualMachineImageContext gets the Image of the specified Azure Virtual Machine.
236338
// This function would fail the test if there is an error.
237339
// The ctx parameter supports cancellation and timeouts.
@@ -281,6 +383,23 @@ func extractVMImage(vm *armcompute.VirtualMachine) VMImage {
281383
return img
282384
}
283385

386+
// GetSizeOfVirtualMachine gets the Size Type of the specified Azure Virtual Machine.
387+
// This function would fail the test if there is an error.
388+
//
389+
// Deprecated: Use [GetSizeOfVirtualMachineContext] instead.
390+
func GetSizeOfVirtualMachine(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) armcompute.VirtualMachineSizeTypes {
391+
t.Helper()
392+
393+
return GetSizeOfVirtualMachineContext(t, context.Background(), vmName, resGroupName, subscriptionID)
394+
}
395+
396+
// GetSizeOfVirtualMachineE gets the Size Type of the specified Azure Virtual Machine.
397+
//
398+
// Deprecated: Use [GetSizeOfVirtualMachineContextE] instead.
399+
func GetSizeOfVirtualMachineE(vmName string, resGroupName string, subscriptionID string) (armcompute.VirtualMachineSizeTypes, error) {
400+
return GetSizeOfVirtualMachineContextE(context.Background(), vmName, resGroupName, subscriptionID)
401+
}
402+
284403
// GetSizeOfVirtualMachineContext gets the Size Type of the specified Azure Virtual Machine.
285404
// This function would fail the test if there is an error.
286405
// The ctx parameter supports cancellation and timeouts.
@@ -309,6 +428,23 @@ func extractVMSize(vm *armcompute.VirtualMachine) armcompute.VirtualMachineSizeT
309428
return *vm.Properties.HardwareProfile.VMSize
310429
}
311430

431+
// GetVirtualMachineTags gets the Tags of the specified Virtual Machine as a map.
432+
// This function would fail the test if there is an error.
433+
//
434+
// Deprecated: Use [GetVirtualMachineTagsContext] instead.
435+
func GetVirtualMachineTags(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) map[string]string {
436+
t.Helper()
437+
438+
return GetVirtualMachineTagsContext(t, context.Background(), vmName, resGroupName, subscriptionID)
439+
}
440+
441+
// GetVirtualMachineTagsE gets the Tags of the specified Virtual Machine as a map.
442+
//
443+
// Deprecated: Use [GetVirtualMachineTagsContextE] instead.
444+
func GetVirtualMachineTagsE(vmName string, resGroupName string, subscriptionID string) (map[string]string, error) {
445+
return GetVirtualMachineTagsContextE(context.Background(), vmName, resGroupName, subscriptionID)
446+
}
447+
312448
// GetVirtualMachineTagsContext gets the Tags of the specified Virtual Machine as a map.
313449
// This function would fail the test if there is an error.
314450
// The ctx parameter supports cancellation and timeouts.
@@ -351,6 +487,23 @@ func extractVMTags(vm *armcompute.VirtualMachine) map[string]string {
351487
// Get multiple Virtual Machines from a Resource Group
352488
// ***************************************************** //
353489

490+
// ListVirtualMachinesForResourceGroup gets a list of all Virtual Machine names in the specified Resource Group.
491+
// This function would fail the test if there is an error.
492+
//
493+
// Deprecated: Use [ListVirtualMachinesForResourceGroupContext] instead.
494+
func ListVirtualMachinesForResourceGroup(t testing.TestingT, resGroupName string, subscriptionID string) []string {
495+
t.Helper()
496+
497+
return ListVirtualMachinesForResourceGroupContext(t, context.Background(), resGroupName, subscriptionID)
498+
}
499+
500+
// ListVirtualMachinesForResourceGroupE gets a list of all Virtual Machine names in the specified Resource Group.
501+
//
502+
// Deprecated: Use [ListVirtualMachinesForResourceGroupContextE] instead.
503+
func ListVirtualMachinesForResourceGroupE(resGroupName string, subscriptionID string) ([]string, error) {
504+
return ListVirtualMachinesForResourceGroupContextE(context.Background(), resGroupName, subscriptionID)
505+
}
506+
354507
// ListVirtualMachinesForResourceGroupContext gets a list of all Virtual Machine names in the specified Resource Group.
355508
// This function would fail the test if there is an error.
356509
// The ctx parameter supports cancellation and timeouts.
@@ -393,6 +546,25 @@ func listVirtualMachineNames(ctx context.Context, client *armcompute.VirtualMach
393546
return vmDetails, nil
394547
}
395548

549+
// GetVirtualMachinesForResourceGroup gets all Virtual Machine objects in the specified Resource Group. Each
550+
// VM Object represents the entire set of VM compute properties accessible by using the VM name as the map key.
551+
// This function would fail the test if there is an error.
552+
//
553+
// Deprecated: Use [GetVirtualMachinesForResourceGroupContext] instead.
554+
func GetVirtualMachinesForResourceGroup(t testing.TestingT, resGroupName string, subscriptionID string) map[string]armcompute.VirtualMachineProperties {
555+
t.Helper()
556+
557+
return GetVirtualMachinesForResourceGroupContext(t, context.Background(), resGroupName, subscriptionID)
558+
}
559+
560+
// GetVirtualMachinesForResourceGroupE gets all Virtual Machine objects in the specified Resource Group. Each
561+
// VM Object represents the entire set of VM compute properties accessible by using the VM name as the map key.
562+
//
563+
// Deprecated: Use [GetVirtualMachinesForResourceGroupContextE] instead.
564+
func GetVirtualMachinesForResourceGroupE(resGroupName string, subscriptionID string) (map[string]armcompute.VirtualMachineProperties, error) {
565+
return GetVirtualMachinesForResourceGroupContextE(context.Background(), resGroupName, subscriptionID)
566+
}
567+
396568
// GetVirtualMachinesForResourceGroupContext gets all Virtual Machine objects in the specified Resource Group. Each
397569
// VM Object represents the entire set of VM compute properties accessible by using the VM name as the map key.
398570
// This function would fail the test if there is an error.
@@ -467,6 +639,23 @@ func GetVirtualMachineContext(t testing.TestingT, ctx context.Context, vmName st
467639
return vm
468640
}
469641

642+
// GetVirtualMachine gets a Virtual Machine in the specified Azure Resource Group.
643+
// This function would fail the test if there is an error.
644+
//
645+
// Deprecated: Use [GetVirtualMachineContext] instead.
646+
func GetVirtualMachine(t testing.TestingT, vmName string, resGroupName string, subscriptionID string) *armcompute.VirtualMachine {
647+
t.Helper()
648+
649+
return GetVirtualMachineContext(t, context.Background(), vmName, resGroupName, subscriptionID)
650+
}
651+
652+
// GetVirtualMachineE gets a Virtual Machine in the specified Azure Resource Group.
653+
//
654+
// Deprecated: Use [GetVirtualMachineContextE] instead.
655+
func GetVirtualMachineE(vmName string, resGroupName string, subscriptionID string) (*armcompute.VirtualMachine, error) {
656+
return GetVirtualMachineContextE(context.Background(), vmName, resGroupName, subscriptionID)
657+
}
658+
470659
// GetVirtualMachineContextE gets a Virtual Machine in the specified Azure Resource Group.
471660
// The ctx parameter supports cancellation and timeouts.
472661
func GetVirtualMachineContextE(ctx context.Context, vmName string, resGroupName string, subscriptionID string) (*armcompute.VirtualMachine, error) {

0 commit comments

Comments
 (0)