Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_log_analytics_workspace_table support for total_retention_in_days property #24513

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ var _ sdk.ResourceWithUpdate = LogAnalyticsWorkspaceTableResource{}
var _ sdk.ResourceWithCustomizeDiff = LogAnalyticsWorkspaceTableResource{}

type LogAnalyticsWorkspaceTableResourceModel struct {
Name string `tfschema:"name"`
WorkspaceId string `tfschema:"workspace_id"`
Plan string `tfschema:"plan"`
RetentionInDays int64 `tfschema:"retention_in_days"`
Name string `tfschema:"name"`
WorkspaceId string `tfschema:"workspace_id"`
Plan string `tfschema:"plan"`
RetentionInDays int64 `tfschema:"retention_in_days"`
TotalRetentionInDays int64 `tfschema:"total_retention_in_days"`
}

func (r LogAnalyticsWorkspaceTableResource) CustomizeDiff() sdk.ResourceFunc {
Expand Down Expand Up @@ -77,6 +78,12 @@ func (r LogAnalyticsWorkspaceTableResource) Arguments() map[string]*pluginsdk.Sc
Optional: true,
ValidateFunc: validation.Any(validation.IntBetween(30, 730), validation.IntInSlice([]int{7})),
},

"total_retention_in_days": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.Any(validation.IntBetween(30, 730), validation.IntInSlice([]int{7})),
},
}
}

Expand Down Expand Up @@ -125,6 +132,7 @@ func (r LogAnalyticsWorkspaceTableResource) Create() sdk.ResourceFunc {

if model.Plan == string(tables.TablePlanEnumAnalytics) {
updateInput.Properties.RetentionInDays = pointer.To(model.RetentionInDays)
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 @@ -174,6 +182,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 err := client.CreateOrUpdateThenPoll(ctx, *id, updateInput); err != nil {
Expand Down Expand Up @@ -220,6 +232,7 @@ func (r LogAnalyticsWorkspaceTableResource) Read() sdk.ResourceFunc {
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.Plan = string(pointer.From(props.Plan))
}
Expand Down Expand Up @@ -247,10 +260,12 @@ func (r LogAnalyticsWorkspaceTableResource) Delete() sdk.ResourceFunc {
// We do not delete the resource here, just set the retention to workspace default value, which is
// achieved by setting the value to `-1`
retentionInDays := utils.Int64(-1)
totalRetentionInDays := utils.Int64(-1)

updateInput := tables.Table{
Properties: &tables.TableProperties{
RetentionInDays: retentionInDays,
RetentionInDays: retentionInDays,
TotalRetentionInDays: totalRetentionInDays,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccLogAnalyticsWorkspaceTable_updateTableRetention(t *testing.T) {
check.That(data.ResourceName).Key("id").Exists(),
check.That(data.ResourceName).Key("name").HasValue("AppEvents"),
check.That(data.ResourceName).Key("retention_in_days").HasValue("7"),
check.That(data.ResourceName).Key("total_retention_in_days").HasValue("20"),
katbyte marked this conversation as resolved.
Show resolved Hide resolved
),
},
})
Expand Down Expand Up @@ -79,9 +80,10 @@ resource "azurerm_log_analytics_workspace" "test" {
retention_in_days = 30
}
resource "azurerm_log_analytics_workspace_table" "test" {
name = "AppEvents"
workspace_id = azurerm_log_analytics_workspace.test.id
retention_in_days = 7
name = "AppEvents"
workspace_id = azurerm_log_analytics_workspace.test.id
retention_in_days = 7
total_retention_in_days = 32
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
Expand Down
13 changes: 9 additions & 4 deletions website/docs/r/log_analytics_workspace_table.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ resource "azurerm_log_analytics_workspace" "example" {
retention_in_days = 30
}
resource "azurerm_log_analytics_workspace_table" "example" {
workspace_id = azurerm_log_analytics_workspace.example.id
name = "AppMetrics"
retention_in_days = 60
workspace_id = azurerm_log_analytics_workspace.example.id
name = "AppMetrics"
retention_in_days = 60
total_retention_in_days = 180
}
```

Expand All @@ -47,7 +48,9 @@ The following arguments are supported:

* `retention_in_days` - (Optional) The table's retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730.

-> **Note:** `retention_in_days` will revert back to the value of azurerm_log_analytics_workspace retention_in_days when a azurerm_log_analytics_workspace_table is deleted.
* `total_retention_in_days` - (Optional) The table's total retention in days. Possible values range between 30 and 4383.

-> **Note:** `retention_in_days` and `total_retention_in_days` will revert back to the value of azurerm_log_analytics_workspace retention_in_days when a azurerm_log_analytics_workspace_table is deleted.

-> **Note:** The `retention_in_days` cannot be specified when `plan` is `Basic` because the retention is fixed at eight days.

Expand All @@ -61,6 +64,8 @@ The following attributes are exported:

* `retention_in_days` - The table's data retention in days.

* `total_retention_in_days` - The table's total data retention in days.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down