From 64d9826107863c5035aa177101b26df758a8bddf Mon Sep 17 00:00:00 2001 From: Engin Polat Date: Mon, 5 Apr 2021 20:47:52 +0300 Subject: [PATCH 1/6] Update ci.yml --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1be3b7c5b..27dc1dbe9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,8 @@ name: ci-workflow # target_pr: pr number on the source repo (e.g. 14, 25, etc.) on: + push: + branches: master workflow_dispatch: inputs: repo: From 8110cccb5f8451b85b09959586e57e5519a330c9 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Wed, 21 Apr 2021 19:36:39 -0400 Subject: [PATCH 2/6] Add CreateVMInsightsClientE, CreateActivityLogAlertsClientE, CreateDiagnosticsSettingsClientE --- modules/azure/client_factory.go | 81 +++++++++++++++++++++++++++++++++ modules/azure/monitor.go | 9 ++-- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/modules/azure/client_factory.go b/modules/azure/client_factory.go index 906967976..eed85aeb2 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" @@ -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) { 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) From fc29e9d1c84f9d7aa2e31b56f195a543015bcc21 Mon Sep 17 00:00:00 2001 From: Hattan Shobokshi Date: Wed, 28 Apr 2021 16:14:53 -0700 Subject: [PATCH 3/6] Adding action to set up Terraform 14.9 --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27dc1dbe9..a482d9b87 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,10 @@ jobs: ci-job: runs-on: [ubuntu-latest] steps: + - uses: hashicorp/setup-terraform@v1 + with: + terraform_version: 0.14.9 + terraform_wrapper: false - name: checkout to repo uses: actions/checkout@v2 with: From fd6fc4260491da88755c37a1abc0865a8043aaaf Mon Sep 17 00:00:00 2001 From: Hattan Shobokshi Date: Wed, 28 Apr 2021 17:43:17 -0700 Subject: [PATCH 4/6] Update CI to pin to terraform 15.1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a482d9b87..51fcc71ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: steps: - uses: hashicorp/setup-terraform@v1 with: - terraform_version: 0.14.9 + terraform_version: 0.15.1 terraform_wrapper: false - name: checkout to repo uses: actions/checkout@v2 From 5b1f7bb295c51f04020e49368ed047e7f3ee28e9 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Wed, 21 Apr 2021 19:36:39 -0400 Subject: [PATCH 5/6] Add CreateVMInsightsClientE, CreateActivityLogAlertsClientE, CreateDiagnosticsSettingsClientE --- modules/azure/client_factory.go | 81 +++++++++++++++++++++++++++++++++ modules/azure/monitor.go | 9 ++-- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/modules/azure/client_factory.go b/modules/azure/client_factory.go index 906967976..eed85aeb2 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" @@ -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) { 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) From f03cac5681fa797dbad40af36831cf33fefaed15 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Wed, 21 Apr 2021 19:36:39 -0400 Subject: [PATCH 6/6] Add CreateVMInsightsClientE, CreateActivityLogAlertsClientE, CreateDiagnosticsSettingsClientE --- modules/azure/client_factory.go | 81 +++++++++++++++++++++++++++++++++ modules/azure/monitor.go | 9 ++-- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/modules/azure/client_factory.go b/modules/azure/client_factory.go index 906967976..eed85aeb2 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" @@ -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) { 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)