Skip to content

Commit

Permalink
azurerm_log_analytics_workspace - prevent ForceNew when sku is `L…
Browse files Browse the repository at this point in the history
…ACluster` (#19608)
  • Loading branch information
ziyeqf authored Feb 21, 2023
1 parent 8ba7a3f commit c2d8266
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,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)) && !strings.EqualFold(old.(string), "") {
d.ForceNew("sku")
}
}
Expand Down Expand Up @@ -222,7 +221,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)
}
Expand All @@ -245,7 +244,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
Expand Down

0 comments on commit c2d8266

Please sign in to comment.