From b3e9ea9341a3a27ca26a8d831d0700e47ac3f8b3 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:31:33 +0800 Subject: [PATCH] fix [GH-27358] --- .../log_analytics_workspace_table_resource.go | 16 +++++++++------- ...og_analytics_workspace_table_resource_test.go | 7 ++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_workspace_table_resource.go b/internal/services/loganalytics/log_analytics_workspace_table_resource.go index 0760259e69040..0ecef121fea35 100644 --- a/internal/services/loganalytics/log_analytics_workspace_table_resource.go +++ b/internal/services/loganalytics/log_analytics_workspace_table_resource.go @@ -133,8 +133,12 @@ func (r LogAnalyticsWorkspaceTableResource) Create() sdk.ResourceFunc { if model.Plan == string(tables.TablePlanEnumAnalytics) { updateInput.Properties.RetentionInDays = pointer.To(model.RetentionInDays) + } + + if model.TotalRetentionInDays != 0 { updateInput.Properties.TotalRetentionInDays = pointer.To(model.TotalRetentionInDays) } + if err := client.CreateOrUpdateThenPoll(ctx, id, updateInput); err != nil { return fmt.Errorf("failed to update table %s in workspace %s in resource group %s: %s", tableName, workspaceId.WorkspaceName, workspaceId.ResourceGroupName, err) } @@ -183,10 +187,10 @@ func (r LogAnalyticsWorkspaceTableResource) Update() sdk.ResourceFunc { if metadata.ResourceData.HasChange("retention_in_days") { updateInput.Properties.RetentionInDays = pointer.To(state.RetentionInDays) } + } - if metadata.ResourceData.HasChange("total_retention_in_days") { - updateInput.Properties.TotalRetentionInDays = pointer.To(state.TotalRetentionInDays) - } + if metadata.ResourceData.HasChange("total_retention_in_days") { + updateInput.Properties.TotalRetentionInDays = pointer.To(state.TotalRetentionInDays) } if err := client.CreateOrUpdateThenPoll(ctx, *id, updateInput); err != nil { @@ -231,10 +235,8 @@ func (r LogAnalyticsWorkspaceTableResource) Read() sdk.ResourceFunc { if model := resp.Model; model != nil { if props := model.Properties; props != nil { - if pointer.From(props.Plan) == tables.TablePlanEnumAnalytics { - state.RetentionInDays = pointer.From(props.RetentionInDays) - state.TotalRetentionInDays = pointer.From(props.TotalRetentionInDays) - } + state.RetentionInDays = pointer.From(props.RetentionInDays) + state.TotalRetentionInDays = pointer.From(props.TotalRetentionInDays) state.Plan = string(pointer.From(props.Plan)) } } diff --git a/internal/services/loganalytics/log_analytics_workspace_table_resource_test.go b/internal/services/loganalytics/log_analytics_workspace_table_resource_test.go index 5db39e331c878..9e6adf3b2cf49 100644 --- a/internal/services/loganalytics/log_analytics_workspace_table_resource_test.go +++ b/internal/services/loganalytics/log_analytics_workspace_table_resource_test.go @@ -104,9 +104,10 @@ resource "azurerm_log_analytics_workspace" "test" { retention_in_days = 30 } resource "azurerm_log_analytics_workspace_table" "test" { - name = "AppTraces" - workspace_id = azurerm_log_analytics_workspace.test.id - plan = "Basic" + name = "AppTraces" + workspace_id = azurerm_log_analytics_workspace.test.id + plan = "Basic" + total_retention_in_days = 32 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) }