Skip to content

Commit

Permalink
Upgrade version of the security center client to v3
Browse files Browse the repository at this point in the history
To avoid using multiple versions of the API.
  • Loading branch information
beandrad committed Sep 29, 2020
1 parent 341bcf5 commit c69d063
Show file tree
Hide file tree
Showing 39 changed files with 17 additions and 23,364 deletions.
19 changes: 9 additions & 10 deletions azurerm/internal/services/securitycenter/client/client.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package client

import (
securityv1 "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v1.0/security"
securityv3 "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
ContactsClient *securityv1.ContactsClient
PricingClient *securityv3.PricingsClient
WorkspaceClient *securityv1.WorkspaceSettingsClient
AdvancedThreatProtectionClient *securityv1.AdvancedThreatProtectionClient
ContactsClient *security.ContactsClient
PricingClient *security.PricingsClient
WorkspaceClient *security.WorkspaceSettingsClient
AdvancedThreatProtectionClient *security.AdvancedThreatProtectionClient
}

func NewClient(o *common.ClientOptions) *Client {
ascLocation := "Global"

ContactsClient := securityv1.NewContactsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
ContactsClient := security.NewContactsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
o.ConfigureClient(&ContactsClient.Client, o.ResourceManagerAuthorizer)

PricingClient := securityv3.NewPricingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
PricingClient := security.NewPricingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
o.ConfigureClient(&PricingClient.Client, o.ResourceManagerAuthorizer)

WorkspaceClient := securityv1.NewWorkspaceSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
WorkspaceClient := security.NewWorkspaceSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
o.ConfigureClient(&WorkspaceClient.Client, o.ResourceManagerAuthorizer)

AdvancedThreatProtectionClient := securityv1.NewAdvancedThreatProtectionClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
AdvancedThreatProtectionClient := security.NewAdvancedThreatProtectionClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation)
o.ConfigureClient(&AdvancedThreatProtectionClient.Client, o.ResourceManagerAuthorizer)

return &Client{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v1.0/security"
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v1.0/security"
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"log"
"time"

securityv1 "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v1.0/security"
securityv3 "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -89,8 +88,8 @@ func resourceArmSecurityCenterWorkspaceCreateUpdate(d *schema.ResourceData, meta
return fmt.Errorf("Security Center Subscription workspace cannot be set when pricing tier is `Free`")
}

contact := securityv1.WorkspaceSetting{
WorkspaceSettingProperties: &securityv1.WorkspaceSettingProperties{
contact := security.WorkspaceSetting{
WorkspaceSettingProperties: &security.WorkspaceSettingProperties{
Scope: utils.String(d.Get("scope").(string)),
WorkspaceID: utils.String(d.Get("workspace_id").(string)),
},
Expand Down Expand Up @@ -137,13 +136,13 @@ func resourceArmSecurityCenterWorkspaceCreateUpdate(d *schema.ResourceData, meta
}

if d.IsNewResource() {
d.SetId(*resp.(securityv1.WorkspaceSetting).ID)
d.SetId(*resp.(security.WorkspaceSetting).ID)
}

return resourceArmSecurityCenterWorkspaceRead(d, meta)
}

func isPricingStandard(ctx context.Context, priceClient *securityv3.PricingsClient) (bool, error) {
func isPricingStandard(ctx context.Context, priceClient *security.PricingsClient) (bool, error) {
prices, err := priceClient.List(ctx)
if err != nil {
return false, fmt.Errorf("Error listing Security Center Subscription pricing: %+v", err)
Expand All @@ -155,7 +154,7 @@ func isPricingStandard(ctx context.Context, priceClient *securityv3.PricingsClie
return false, fmt.Errorf("%v Security Center Subscription pricing propertier is nil", *resourcePrice.Type)
}

if resourcePrice.PricingProperties.PricingTier == securityv3.Standard {
if resourcePrice.PricingProperties.PricingTier == security.Standard {
return true, nil
}
}
Expand Down
Loading

0 comments on commit c69d063

Please sign in to comment.