Skip to content

Commit a8f796f

Browse files
committed
fix(azure)!: migrate frontdoor, monitor, actiongroup, recoveryservices to new ARM SDK
Migrate the last 4 Azure module files still on the archived azure-sdk-for-go/services/ and profiles/ packages to the actively maintained azure-sdk-for-go/sdk/resourcemanager/ packages. Modules migrated: - frontdoor.go: frontdoor (profiles/latest) → armfrontdoor - monitor.go: insights (profiles/preview) → armmonitor - actiongroup.go: insights (profiles/preview) → armmonitor - recoveryservices.go: recoveryservices + backup → armrecoveryservices + armrecoveryservicesbackup/v4 Breaking changes: - Return types change to new SDK types - Fields nested under .Properties - Old iterator pattern replaced with pager (recoveryservices backup lists) - backup.AzureIaaSComputeVMProtectedItem type assertion replaces AsAzureIaaSComputeVMProtectedItem() Other changes: - client_factory.go: migrated frontdoor + monitor client factories to ARM SDK - Integration tests updated for new SDK field access patterns - Added WithClient variants and azfake unit tests for all migrated modules
1 parent 57fac81 commit a8f796f

14 files changed

Lines changed: 1074 additions & 291 deletions

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ require (
5353
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6 v6.4.0
5454
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v3 v3.4.0
5555
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v9 v9.1.0
56+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/frontdoor/armfrontdoor v1.4.0
5657
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.5.0
58+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0
5759
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysql v1.2.0
5860
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 v6.2.0
5961
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql v1.2.0
6062
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.3.0
63+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservices v1.6.0
64+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4 v4.2.0
6165
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0
6266
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/servicebus/armservicebus/v2 v2.0.0-beta.3
6367
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql v1.2.0

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v3 v3.4.0
5252
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v3 v3.4.0/go.mod h1:Bb7kqorvA2acMCNFac+2ldoQWi7QrcMdH+9Gg9C7fSM=
5353
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v9 v9.1.0 h1:82oTC4oB/7AjVmPR8KMvlyHZgZ8PGdboh8c0Jol/XWY=
5454
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v9 v9.1.0/go.mod h1:nuDWiSqiFv4Bo8LX99dl+Ecl9o1iNSLJDBsrl8iRWr4=
55+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/frontdoor/armfrontdoor v1.4.0 h1:dz5II+dFuMkrdpIkO9f/Ht3f8hnRUURiQdLj1hwKO5Q=
56+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/frontdoor/armfrontdoor v1.4.0/go.mod h1:0tuwjeZbMwLV7h1bcyfTlnXUH6GBKkPml8ukX6EoS3o=
5557
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E=
5658
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk=
5759
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do=
@@ -62,6 +64,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.5.
6264
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.5.0/go.mod h1:4YIVtzMFVsPwBvitCDX7J9sqthSj43QD1sP6fYc1egc=
6365
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o=
6466
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0/go.mod h1:mLfWfj8v3jfWKsL9G4eoBoXVcsqcIUTapmdKy7uGOp0=
67+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0 h1:Ds0KRF8ggpEGg4Vo42oX1cIt/IfOhHWJBikksZbVxeg=
68+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0/go.mod h1:jj6P8ybImR+5topJ+eH6fgcemSFBmU6/6bFF8KkwuDI=
6569
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysql v1.2.0 h1:dhywcZH9yPDIje9aTqwy6psZSPzI6CJLYEprDahIBSQ=
6670
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/mysql/armmysql v1.2.0/go.mod h1:6z3b+JdBLH0eMzfBex/cvEIoEFVEwXuB0wbgdfN11iM=
6771
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 v6.2.0 h1:HYGD75g0bQ3VO/Omedm54v4LrD3B1cGImuRF3AJ5wLo=
@@ -70,6 +74,10 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql v
7074
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql v1.2.0/go.mod h1:bvZZor36Jg9q9kouuMyfJ+ay77+qK+YUfThXH1FdXjU=
7175
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.3.0 h1:yzrctSl9GMIQ5lHu7jc8olOsGjWDCsBpJhWqfGa/YIM=
7276
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.3.0/go.mod h1:GE4m0rnnfwLGX0Y9A9A25Zx5N/90jneT5ABevqzhuFQ=
77+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservices v1.6.0 h1:tyFbORs8iNJGoD4DCRTweqLRCS8PiWqyoj8TqLFZZfo=
78+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservices v1.6.0/go.mod h1:D01KTLlDky2hIhRbX5NjyDb84O6jflookw6b+Gd5h/U=
79+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4 v4.2.0 h1:GOtQKZTIc4/HnWIEqGqtkMHLXIlwa4GpT8BB5JGH+tc=
80+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4 v4.2.0/go.mod h1:o1BW30aoyqKYcQKAMNWs0UAkT30Z2FZzmCNo7hrGHjM=
7381
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 h1:Dd+RhdJn0OTtVGaeDLZpcumkIVCtA/3/Fo42+eoYvVM=
7482
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0/go.mod h1:5kakwfW5CjC9KK+Q4wjXAg+ShuIm2mBMua0ZFj2C8PE=
7583
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/servicebus/armservicebus/v2 v2.0.0-beta.3 h1:JLPf82byRFgfB0f2feJMmRfCCFV0W9/GayiiewTvjlw=

modules/azure/actiongroup.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package azure
33
import (
44
"context"
55

6-
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/monitor/mgmt/insights"
6+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
77
"github.com/gruntwork-io/terratest/modules/testing"
88
"github.com/stretchr/testify/require"
99
)
@@ -14,7 +14,7 @@ import (
1414
// ruleName - required to find the ActionGroupResource.
1515
// resGroupName - use an empty string if you have the AZURE_RES_GROUP_NAME environment variable set
1616
// subscriptionId - use an empty string if you have the ARM_SUBSCRIPTION_ID environment variable set
17-
func GetActionGroupResourceContext(t testing.TestingT, ctx context.Context, ruleName string, resGroupName string, subscriptionID string) *insights.ActionGroupResource {
17+
func GetActionGroupResourceContext(t testing.TestingT, ctx context.Context, ruleName string, resGroupName string, subscriptionID string) *armmonitor.ActionGroupResource {
1818
actionGroupResource, err := GetActionGroupResourceContextE(ctx, ruleName, resGroupName, subscriptionID)
1919
require.NoError(t, err)
2020

@@ -26,7 +26,7 @@ func GetActionGroupResourceContext(t testing.TestingT, ctx context.Context, rule
2626
// ruleName - required to find the ActionGroupResource.
2727
// resGroupName - use an empty string if you have the AZURE_RES_GROUP_NAME environment variable set
2828
// subscriptionId - use an empty string if you have the ARM_SUBSCRIPTION_ID environment variable set
29-
func GetActionGroupResourceContextE(ctx context.Context, ruleName string, resGroupName string, subscriptionID string) (*insights.ActionGroupResource, error) {
29+
func GetActionGroupResourceContextE(ctx context.Context, ruleName string, resGroupName string, subscriptionID string) (*armmonitor.ActionGroupResource, error) {
3030
rgName, err := getTargetAzureResourceGroupName(resGroupName)
3131
if err != nil {
3232
return nil, err
@@ -37,12 +37,7 @@ func GetActionGroupResourceContextE(ctx context.Context, ruleName string, resGro
3737
return nil, err
3838
}
3939

40-
actionGroup, err := client.Get(ctx, rgName, ruleName)
41-
if err != nil {
42-
return nil, err
43-
}
44-
45-
return &actionGroup, nil
40+
return GetActionGroupResourceWithClient(ctx, client, rgName, ruleName)
4641
}
4742

4843
// GetActionGroupResource gets the ActionGroupResource.
@@ -52,8 +47,8 @@ func GetActionGroupResourceContextE(ctx context.Context, ruleName string, resGro
5247
// subscriptionId - use an empty string if you have the ARM_SUBSCRIPTION_ID environment variable set
5348
//
5449
// Deprecated: Use [GetActionGroupResourceContext] instead.
55-
func GetActionGroupResource(t testing.TestingT, ruleName string, resGroupName string, subscriptionID string) *insights.ActionGroupResource {
56-
return GetActionGroupResourceContext(t, context.Background(), ruleName, resGroupName, subscriptionID) //nolint:staticcheck
50+
func GetActionGroupResource(t testing.TestingT, ruleName string, resGroupName string, subscriptionID string) *armmonitor.ActionGroupResource {
51+
return GetActionGroupResourceContext(t, context.Background(), ruleName, resGroupName, subscriptionID)
5752
}
5853

5954
// GetActionGroupResourceE gets the ActionGroupResource.
@@ -62,6 +57,16 @@ func GetActionGroupResource(t testing.TestingT, ruleName string, resGroupName st
6257
// subscriptionId - use an empty string if you have the ARM_SUBSCRIPTION_ID environment variable set
6358
//
6459
// Deprecated: Use [GetActionGroupResourceContextE] instead.
65-
func GetActionGroupResourceE(ruleName string, resGroupName string, subscriptionID string) (*insights.ActionGroupResource, error) {
60+
func GetActionGroupResourceE(ruleName string, resGroupName string, subscriptionID string) (*armmonitor.ActionGroupResource, error) {
6661
return GetActionGroupResourceContextE(context.Background(), ruleName, resGroupName, subscriptionID)
6762
}
63+
64+
// GetActionGroupResourceWithClient gets the ActionGroupResource using the provided client.
65+
func GetActionGroupResourceWithClient(ctx context.Context, client *armmonitor.ActionGroupsClient, resGroupName string, ruleName string) (*armmonitor.ActionGroupResource, error) {
66+
resp, err := client.Get(ctx, resGroupName, ruleName, nil)
67+
if err != nil {
68+
return nil, err
69+
}
70+
71+
return &resp.ActionGroupResource, nil
72+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package azure_test
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
8+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
9+
azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake"
10+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
11+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
12+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
13+
monitorfake "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor/fake"
14+
"github.com/gruntwork-io/terratest/modules/azure"
15+
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
17+
)
18+
19+
func newFakeActionGroupsClient(t *testing.T, srv *monitorfake.ActionGroupsServer) *armmonitor.ActionGroupsClient {
20+
t.Helper()
21+
22+
transport := monitorfake.NewActionGroupsServerTransport(srv)
23+
client, err := armmonitor.NewActionGroupsClient("fake-sub", &azfake.TokenCredential{}, &arm.ClientOptions{
24+
ClientOptions: policy.ClientOptions{Transport: transport},
25+
})
26+
require.NoError(t, err)
27+
28+
return client
29+
}
30+
31+
func TestGetActionGroupResourceWithClient(t *testing.T) {
32+
t.Parallel()
33+
34+
tests := []struct {
35+
server monitorfake.ActionGroupsServer
36+
name string
37+
wantErr bool
38+
}{
39+
{
40+
name: "Success",
41+
server: monitorfake.ActionGroupsServer{
42+
Get: func(_ context.Context, _ string, actionGroupName string, _ *armmonitor.ActionGroupsClientGetOptions) (resp azfake.Responder[armmonitor.ActionGroupsClientGetResponse], errResp azfake.ErrorResponder) {
43+
resp.SetResponse(http.StatusOK, armmonitor.ActionGroupsClientGetResponse{
44+
ActionGroupResource: armmonitor.ActionGroupResource{
45+
Name: to.Ptr(actionGroupName),
46+
},
47+
}, nil)
48+
49+
return
50+
},
51+
},
52+
},
53+
{
54+
name: "NotFound",
55+
server: monitorfake.ActionGroupsServer{
56+
Get: func(_ context.Context, _ string, _ string, _ *armmonitor.ActionGroupsClientGetOptions) (resp azfake.Responder[armmonitor.ActionGroupsClientGetResponse], errResp azfake.ErrorResponder) {
57+
errResp.SetResponseError(http.StatusNotFound, "ResourceNotFound")
58+
return
59+
},
60+
},
61+
wantErr: true,
62+
},
63+
}
64+
65+
for _, tc := range tests {
66+
t.Run(tc.name, func(t *testing.T) {
67+
t.Parallel()
68+
69+
srv := tc.server
70+
client := newFakeActionGroupsClient(t, &srv)
71+
72+
resource, err := azure.GetActionGroupResourceWithClient(t.Context(), client, "rg", "my-action-group")
73+
if tc.wantErr {
74+
require.Error(t, err)
75+
return
76+
}
77+
78+
require.NoError(t, err)
79+
assert.Equal(t, "my-action-group", *resource.Name)
80+
})
81+
}
82+
}

0 commit comments

Comments
 (0)