From 2f558edafa1eb43b101aa902a949650950e62ae7 Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Thu, 8 Dec 2022 10:49:16 +0800 Subject: [PATCH 1/5] `azurerm_log_analytics_workspace` - fix workaround when `sku` is `LACluster` --- .../log_analytics_linked_service_resource_test.go | 6 ++++++ .../loganalytics/log_analytics_workspace_resource.go | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go index 9bbe32413f41..1cb33d87b2ea 100644 --- a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go +++ b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go @@ -163,6 +163,12 @@ resource "azurerm_log_analytics_workspace" "test" { resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" retention_in_days = 30 + + lifecycle { + ignore_changes = [ + sku + ] + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/internal/services/loganalytics/log_analytics_workspace_resource.go b/internal/services/loganalytics/log_analytics_workspace_resource.go index 6956cc9737ef..278f38045511 100644 --- a/internal/services/loganalytics/log_analytics_workspace_resource.go +++ b/internal/services/loganalytics/log_analytics_workspace_resource.go @@ -144,14 +144,13 @@ func resourceLogAnalyticsWorkspaceCustomDiff(ctx context.Context, d *pluginsdk.R // custom diff here because when you link the workspace to a cluster the // cluster changes the sku to LACluster, so we need to ignore the change // if it is LACluster else invoke the ForceNew as before... - // - // NOTE: Since LACluster is not in our enum the value is returned as "" + if d.HasChange("sku") { old, new := d.GetChange("sku") log.Printf("[INFO] Log Analytics Workspace SKU: OLD: %q, NEW: %q", old, new) // If the old value is not LACluster(e.g. "") return ForceNew because they are // really changing the sku... - if !strings.EqualFold(old.(string), "") { + if !strings.EqualFold(old.(string), string(workspaces.WorkspaceSkuNameEnumLACluster)) { d.ForceNew("sku") } } @@ -198,7 +197,7 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta i if err == nil { if resp.Model != nil && resp.Model.Properties != nil { if azSku := resp.Model.Properties.Sku; azSku != nil { - if strings.EqualFold(string(azSku.Name), "lacluster") { + if strings.EqualFold(string(azSku.Name), string(workspaces.WorkspaceSkuNameEnumLACluster)) { isLACluster = true log.Printf("[INFO] Log Analytics Workspace %q (Resource Group %q): SKU is linked to Log Analytics cluster", name, resourceGroup) } @@ -221,7 +220,7 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta i t := d.Get("tags").(map[string]interface{}) if isLACluster { - sku.Name = "lacluster" + sku.Name = workspaces.WorkspaceSkuNameEnumLACluster } else if skuName == "" { // Default value if sku is not defined sku.Name = workspaces.WorkspaceSkuNameEnumPerGBTwoZeroOneEight From 693448e4e6c7303163a29737bbec7ca0bcdfea7d Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Tue, 13 Dec 2022 09:36:32 +0800 Subject: [PATCH 2/5] add condition --- .../services/loganalytics/log_analytics_workspace_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/loganalytics/log_analytics_workspace_resource.go b/internal/services/loganalytics/log_analytics_workspace_resource.go index 278f38045511..3a32342a2067 100644 --- a/internal/services/loganalytics/log_analytics_workspace_resource.go +++ b/internal/services/loganalytics/log_analytics_workspace_resource.go @@ -150,7 +150,7 @@ func resourceLogAnalyticsWorkspaceCustomDiff(ctx context.Context, d *pluginsdk.R log.Printf("[INFO] Log Analytics Workspace SKU: OLD: %q, NEW: %q", old, new) // If the old value is not LACluster(e.g. "") return ForceNew because they are // really changing the sku... - if !strings.EqualFold(old.(string), string(workspaces.WorkspaceSkuNameEnumLACluster)) { + if !strings.EqualFold(old.(string), string(workspaces.WorkspaceSkuNameEnumLACluster)) && !strings.EqualFold(old.(string), "") { d.ForceNew("sku") } } From 80d91b156b76e8069798fd1d1790ff9538ed045f Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Thu, 15 Dec 2022 16:29:53 +0800 Subject: [PATCH 3/5] empty commit to re trigger CI --- .../loganalytics/log_analytics_linked_service_resource_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go index 1cb33d87b2ea..10d2db79deaa 100644 --- a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go +++ b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go @@ -170,6 +170,7 @@ resource "azurerm_log_analytics_workspace" "test" { ] } } + `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 38db6a68431c60356005ba1b7d7a3b22c111c5e1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 21 Feb 2023 13:08:53 -0800 Subject: [PATCH 4/5] Update log_analytics_linked_service_resource_test.go --- .../log_analytics_linked_service_resource_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go index 10d2db79deaa..ebfc908e3f6b 100644 --- a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go +++ b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go @@ -163,12 +163,6 @@ resource "azurerm_log_analytics_workspace" "test" { resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" retention_in_days = 30 - - lifecycle { - ignore_changes = [ - sku - ] - } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) From 197ef8f8853567f2c7630b14a16fadbc4cdd6458 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 21 Feb 2023 13:14:57 -0800 Subject: [PATCH 5/5] Update log_analytics_linked_service_resource_test.go --- .../loganalytics/log_analytics_linked_service_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go index ebfc908e3f6b..9bbe32413f41 100644 --- a/internal/services/loganalytics/log_analytics_linked_service_resource_test.go +++ b/internal/services/loganalytics/log_analytics_linked_service_resource_test.go @@ -164,7 +164,6 @@ resource "azurerm_log_analytics_workspace" "test" { sku = "PerGB2018" retention_in_days = 30 } - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) }