Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure] Add sovereign cloud support for monitor module #871

Merged
merged 12 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
ci-job:
runs-on: [ubuntu-latest]
steps:
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.15.1
terraform_wrapper: false
- name: checkout to repo
uses: actions/checkout@v2
with:
Expand Down
81 changes: 81 additions & 0 deletions modules/azure/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -206,6 +207,86 @@ func CreateStorageBlobContainerClientE(subscriptionID string) (*storage.BlobCont
return &blobContainerClient, 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) {
Expand Down
9 changes: 6 additions & 3 deletions modules/azure/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down