Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Sep 18, 2024
1 parent 8916ae9 commit b3e9ea9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b3e9ea9

Please sign in to comment.