Skip to content

Commit

Permalink
Update loganalytics to `/preview/operationalinsights/mgmt/2020-03-0…
Browse files Browse the repository at this point in the history
…1-preview/operationalinsights` (#8234)
  • Loading branch information
mbfrahry authored Aug 27, 2020
1 parent f89b1ab commit 44f5b3c
Show file tree
Hide file tree
Showing 36 changed files with 8,066 additions and 2,201 deletions.
7 changes: 6 additions & 1 deletion azurerm/internal/services/loganalytics/client/client.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2020-03-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
DataSourcesClient *operationalinsights.DataSourcesClient
LinkedServicesClient *operationalinsights.LinkedServicesClient
SharedKeysClient *operationalinsights.SharedKeysClient
SolutionsClient *operationsmanagement.SolutionsClient
WorkspacesClient *operationalinsights.WorkspacesClient
}
Expand All @@ -20,6 +21,9 @@ func NewClient(o *common.ClientOptions) *Client {
WorkspacesClient := operationalinsights.NewWorkspacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&WorkspacesClient.Client, o.ResourceManagerAuthorizer)

SharedKeysClient := operationalinsights.NewSharedKeysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&SharedKeysClient.Client, o.ResourceManagerAuthorizer)

SolutionsClient := operationsmanagement.NewSolutionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, "Microsoft.OperationsManagement", "solutions", "testing")
o.ConfigureClient(&SolutionsClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -29,6 +33,7 @@ func NewClient(o *common.ClientOptions) *Client {
return &Client{
DataSourcesClient: &DataSourcesClient,
LinkedServicesClient: &LinkedServicesClient,
SharedKeysClient: &SharedKeysClient,
SolutionsClient: &SolutionsClient,
WorkspacesClient: &WorkspacesClient,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package loganalytics
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2020-03-01-preview/operationalinsights"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import (
"log"
"time"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/state"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2020-03-01-preview/operationalinsights"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/parse"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/state"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2020-03-01-preview/operationalinsights"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2020-03-01-preview/operationalinsights"
"github.com/hashicorp/go-azure-helpers/response"
"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/azure"
Expand Down Expand Up @@ -175,13 +176,15 @@ func resourceArmLogAnalyticsLinkedServiceDelete(d *schema.ResourceData, meta int
workspaceName := id.Path["workspaces"]
lsName := id.Path["linkedservices"]

resp, err := client.Delete(ctx, resGroup, workspaceName, lsName)
future, err := client.Delete(ctx, resGroup, workspaceName, lsName)
if err != nil {
if utils.ResponseWasNotFound(resp) {
return nil
}
return fmt.Errorf("error deleting Log Analytics Linked Service %q (Workspace %q / Resource Group %q): %+v", lsName, workspaceName, resGroup, err)
}

return fmt.Errorf("Error deleting Linked Service %q (Workspace %q / Resource Group %q): %+v", lsName, workspaceName, resGroup, err)
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
if !response.WasNotFound(future.Response()) {
return fmt.Errorf("waiting for deletion of Log Analytics Linked Service %q (Workspace %q / Resource Group %q): %+v", lsName, workspaceName, resGroup, err)
}
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func dataSourceLogAnalyticsWorkspace() *schema.Resource {
},

"portal_url": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Deprecated: "this property has been removed from the API and will be removed in version 3.0 of the provider",
},

"primary_shared_key": {
Expand All @@ -70,6 +71,7 @@ func dataSourceLogAnalyticsWorkspace() *schema.Resource {

func dataSourceLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).LogAnalytics.WorkspacesClient
sharedKeysClient := meta.(*clients.Client).LogAnalytics.SharedKeysClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -93,13 +95,13 @@ func dataSourceLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface{
}

d.Set("workspace_id", resp.CustomerID)
d.Set("portal_url", resp.PortalURL)
d.Set("portal_url", "")
if sku := resp.Sku; sku != nil {
d.Set("sku", sku.Name)
}
d.Set("retention_in_days", resp.RetentionInDays)

sharedKeys, err := client.GetSharedKeys(ctx, resGroup, name)
sharedKeys, err := sharedKeysClient.GetSharedKeys(ctx, resGroup, name)
if err != nil {
log.Printf("[ERROR] Unable to List Shared keys for Log Analytics workspaces %s: %+v", name, err)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"regexp"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2020-03-01-preview/operationalinsights"
"github.com/hashicorp/go-azure-helpers/response"
"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/azure"
Expand Down Expand Up @@ -54,12 +55,12 @@ func resourceArmLogAnalyticsWorkspace() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(operationalinsights.Free),
string(operationalinsights.PerGB2018),
string(operationalinsights.PerNode),
string(operationalinsights.Premium),
string(operationalinsights.Standalone),
string(operationalinsights.Standard),
string(operationalinsights.WorkspaceSkuNameEnumFree),
string(operationalinsights.WorkspaceSkuNameEnumPerGB2018),
string(operationalinsights.WorkspaceSkuNameEnumPerNode),
string(operationalinsights.WorkspaceSkuNameEnumPremium),
string(operationalinsights.WorkspaceSkuNameEnumStandalone),
string(operationalinsights.WorkspaceSkuNameEnumStandard),
"Unlimited", // TODO check if this is actually no longer valid, removed in v28.0.0 of the SDK
}, true),
DiffSuppressFunc: suppress.CaseDifference,
Expand All @@ -78,8 +79,9 @@ func resourceArmLogAnalyticsWorkspace() *schema.Resource {
},

"portal_url": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Deprecated: "this property has been removed from the API and will be removed in version 3.0 of the provider",
},

"primary_shared_key": {
Expand Down Expand Up @@ -123,8 +125,8 @@ func resourceArmLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta i

location := azure.NormalizeLocation(d.Get("location").(string))
skuName := d.Get("sku").(string)
sku := &operationalinsights.Sku{
Name: operationalinsights.SkuNameEnum(skuName),
sku := &operationalinsights.WorkspaceSku{
Name: operationalinsights.WorkspaceSkuNameEnum(skuName),
}

retentionInDays := int32(d.Get("retention_in_days").(int))
Expand Down Expand Up @@ -166,6 +168,7 @@ func resourceArmLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta i

func resourceArmLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).LogAnalytics.WorkspacesClient
sharedKeysClient := meta.(*clients.Client).LogAnalytics.SharedKeysClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
id, err := parse.LogAnalyticsWorkspaceID(d.Id())
Expand All @@ -189,13 +192,13 @@ func resourceArmLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface
}

d.Set("workspace_id", resp.CustomerID)
d.Set("portal_url", resp.PortalURL)
d.Set("portal_url", "")
if sku := resp.Sku; sku != nil {
d.Set("sku", sku.Name)
}
d.Set("retention_in_days", resp.RetentionInDays)

sharedKeys, err := client.GetSharedKeys(ctx, id.ResourceGroup, id.Name)
sharedKeys, err := sharedKeysClient.GetSharedKeys(ctx, id.ResourceGroup, id.Name)
if err != nil {
log.Printf("[ERROR] Unable to List Shared keys for Log Analytics workspaces %s: %+v", id.Name, err)
} else {
Expand All @@ -214,14 +217,17 @@ func resourceArmLogAnalyticsWorkspaceDelete(d *schema.ResourceData, meta interfa
if err != nil {
return err
}
resp, err := client.Delete(ctx, id.ResourceGroup, id.Name)

force := false
future, err := client.Delete(ctx, id.ResourceGroup, id.Name, utils.Bool(force))
if err != nil {
if utils.ResponseWasNotFound(resp) {
return nil
}
return fmt.Errorf("issuing AzureRM delete request for Log Analytics Workspaces '%s': %+v", id.Name, err)
}

return fmt.Errorf("Error issuing AzureRM delete request for Log Analytics Workspaces '%s': %+v", id.Name, err)
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
if !response.WasNotFound(future.Response()) {
return fmt.Errorf("waiting for deletion of Log Analytics Worspace %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}
}

return nil
Expand Down

This file was deleted.

Loading

0 comments on commit 44f5b3c

Please sign in to comment.