diff --git a/modules/azure/client_factory.go b/modules/azure/client_factory.go index 42b96b9ba..9d6426b36 100644 --- a/modules/azure/client_factory.go +++ b/modules/azure/client_factory.go @@ -15,6 +15,7 @@ import ( "reflect" "github.com/Azure/azure-sdk-for-go/profiles/preview/cosmos-db/mgmt/documentdb" + "github.com/Azure/azure-sdk-for-go/profiles/preview/preview/monitor/mgmt/insights" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" kvmng "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault" @@ -233,6 +234,86 @@ func CreateAvailabilitySetClientE(subscriptionID string) (*compute.AvailabilityS return &client, nil } +// CreateVMInsightsClientE gets a VM Insights client +func CreateVMInsightsClientE(subscriptionID string) (*insights.VMInsightsClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Lookup environment URI + baseURI, err := getBaseURI() + if err != nil { + return nil, err + } + + client := insights.NewVMInsightsClientWithBaseURI(baseURI, subscriptionID) + + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + + client.Authorizer = *authorizer + + return &client, nil +} + +// CreateActivityLogAlertsClientE gets an Action Groups client in the specified Azure Subscription +func CreateActivityLogAlertsClientE(subscriptionID string) (*insights.ActivityLogAlertsClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Lookup environment URI + baseURI, err := getBaseURI() + if err != nil { + return nil, err + } + + // Get the Action Groups client + client := insights.NewActivityLogAlertsClientWithBaseURI(baseURI, subscriptionID) + + // Create an authorizer + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + + client.Authorizer = *authorizer + + return &client, nil +} + +// CreateDiagnosticsSettingsClientE returns a diagnostics settings client +func CreateDiagnosticsSettingsClientE(subscriptionID string) (*insights.DiagnosticSettingsClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Lookup environment URI + baseURI, err := getBaseURI() + if err != nil { + return nil, err + } + + client := insights.NewDiagnosticSettingsClientWithBaseURI(baseURI, subscriptionID) + + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + + client.Authorizer = *authorizer + + return &client, nil +} + // GetKeyVaultURISuffixE returns the proper KeyVault URI suffix for the configured Azure environment. // This function would fail the test if there is an error. func GetKeyVaultURISuffixE() (string, error) { diff --git a/modules/azure/monitor.go b/modules/azure/monitor.go index b500ef472..d09d8c4c3 100644 --- a/modules/azure/monitor.go +++ b/modules/azure/monitor.go @@ -46,7 +46,7 @@ func GetDiagnosticsSettingsResourceE(name string, resourceURI string, subscripti return nil, err } - client, err := GetDiagnosticsSettingsClientE(subscriptionID) + client, err := CreateDiagnosticsSettingsClientE(subscriptionID) if err != nil { return nil, err } @@ -60,6 +60,7 @@ func GetDiagnosticsSettingsResourceE(name string, resourceURI string, subscripti } // GetDiagnosticsSettingsClientE returns a diagnostics settings client +// TODO: delete in next version func GetDiagnosticsSettingsClientE(subscriptionID string) (*insights.DiagnosticSettingsClient, error) { // Validate Azure subscription ID subscriptionID, err := getTargetAzureSubscription(subscriptionID) @@ -89,7 +90,7 @@ func GetVMInsightsOnboardingStatus(t testing.TestingT, resourceURI string, subsc // GetVMInsightsOnboardingStatusE get diagnostics VM onboarding status func GetVMInsightsOnboardingStatusE(t testing.TestingT, resourceURI string, subscriptionID string) (*insights.VMInsightsOnboardingStatus, error) { - client, err := GetVMInsightsClientE(t, subscriptionID) + client, err := CreateVMInsightsClientE(subscriptionID) if err != nil { return nil, err } @@ -103,6 +104,7 @@ func GetVMInsightsOnboardingStatusE(t testing.TestingT, resourceURI string, subs } // GetVMInsightsClientE gets a VM Insights client +// TODO: delete in next version func GetVMInsightsClientE(t testing.TestingT, subscriptionID string) (*insights.VMInsightsClient, error) { // Validate Azure subscription ID subscriptionID, err := getTargetAzureSubscription(subscriptionID) @@ -140,7 +142,7 @@ func GetActivityLogAlertResourceE(activityLogAlertName string, resGroupName stri } // Get the client reference - client, err := GetActivityLogAlertsClientE(subscriptionID) + client, err := CreateActivityLogAlertsClientE(subscriptionID) if err != nil { return nil, err } @@ -155,6 +157,7 @@ func GetActivityLogAlertResourceE(activityLogAlertName string, resGroupName stri } // GetActivityLogAlertsClientE gets an Action Groups client in the specified Azure Subscription +// TODO: delete in next version func GetActivityLogAlertsClientE(subscriptionID string) (*insights.ActivityLogAlertsClient, error) { // Validate Azure subscription ID subscriptionID, err := getTargetAzureSubscription(subscriptionID)