From 04a2fcfcd5208f2b110986141974a1abe9eb3e10 Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:55:37 +0800 Subject: [PATCH 1/2] support `immediate_purge_data_on_30_days_enabled` --- .../log_analytics_workspace_resource.go | 24 ++++++---- .../log_analytics_workspace_resource_test.go | 48 +++++++++++++++++++ .../r/log_analytics_workspace.html.markdown | 2 + 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_workspace_resource.go b/internal/services/loganalytics/log_analytics_workspace_resource.go index 238fc577b051..27a7f31812c2 100644 --- a/internal/services/loganalytics/log_analytics_workspace_resource.go +++ b/internal/services/loganalytics/log_analytics_workspace_resource.go @@ -154,6 +154,11 @@ func resourceLogAnalyticsWorkspace() *pluginsdk.Resource { ValidateFunc: datacollectionrules.ValidateDataCollectionRuleID, }, + "immediate_purge_data_on_30_days_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + "workspace_id": { Type: pluginsdk.TypeString, Computed: true, @@ -301,6 +306,12 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta i } } + // The `ImmediatePurgeDataOn30Days` are not returned before it has been set + // nolint : staticcheck + if v, ok := d.GetOkExists("immediate_purge_data_on_30_days_enabled"); ok { + parameters.Properties.Features.ImmediatePurgeDataOn30Days = utils.Bool(v.(bool)) + } + propName := "reservation_capacity_in_gb_per_day" capacityReservationLevel, ok := d.GetOk(propName) if ok { @@ -457,18 +468,15 @@ func resourceLogAnalyticsWorkspaceRead(d *pluginsdk.ResourceData, meta interface allowResourceOnlyPermissions := true disableLocalAuth := false + purgeDataOnThirtyDays := false if features := props.Features; features != nil { - v := features.EnableLogAccessUsingOnlyResourcePermissions - if v != nil { - allowResourceOnlyPermissions = *v - } - d := features.DisableLocalAuth - if d != nil { - disableLocalAuth = *d - } + allowResourceOnlyPermissions = pointer.From(features.EnableLogAccessUsingOnlyResourcePermissions) + disableLocalAuth = pointer.From(features.DisableLocalAuth) + purgeDataOnThirtyDays = pointer.From(features.ImmediatePurgeDataOn30Days) } d.Set("allow_resource_only_permissions", allowResourceOnlyPermissions) d.Set("local_authentication_disabled", disableLocalAuth) + d.Set("immediate_purge_data_on_30_days_enabled", purgeDataOnThirtyDays) defaultDataCollectionRuleResourceId := "" if props.DefaultDataCollectionRuleResourceId != nil { diff --git a/internal/services/loganalytics/log_analytics_workspace_resource_test.go b/internal/services/loganalytics/log_analytics_workspace_resource_test.go index 81c744be1d2d..773dedc4dbce 100644 --- a/internal/services/loganalytics/log_analytics_workspace_resource_test.go +++ b/internal/services/loganalytics/log_analytics_workspace_resource_test.go @@ -332,6 +332,32 @@ func TestAccLogAnalyticsWorkspace_ToggleDisableLocalAuth(t *testing.T) { }) } +func TestAccLogAnalyticsWorkspace_ToggleImmediatelyPurgeDataOn30Days(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") + r := LogAnalyticsWorkspaceResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.withImmediatePurgeDataOn30Days(data, true), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.withImmediatePurgeDataOn30Days(data, false), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.withImmediatePurgeDataOn30Days(data, true), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + }) +} + func TestAccLogAnalyticsWorkspace_updateSku(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") r := LogAnalyticsWorkspaceResource{} @@ -939,3 +965,25 @@ resource "azurerm_log_analytics_workspace" "test" { } `, data.RandomInteger, data.Locations.Primary, ruleID) } + +func (LogAnalyticsWorkspaceResource) withImmediatePurgeDataOn30Days(data acceptance.TestData, enable bool) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestLAW-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "PerGB2018" + retention_in_days = 30 + immediate_purge_data_on_30_days_enabled = %[4]t +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enable) +} diff --git a/website/docs/r/log_analytics_workspace.html.markdown b/website/docs/r/log_analytics_workspace.html.markdown index f3a02780ebb2..c2292861571e 100644 --- a/website/docs/r/log_analytics_workspace.html.markdown +++ b/website/docs/r/log_analytics_workspace.html.markdown @@ -69,6 +69,8 @@ The following arguments are supported: * `data_collection_rule_id` - (Optional) The ID of the Data Collection Rule to use for this workspace. +* `immediate_purge_data_on_30_days_enabled` - (Optional) Whether to remove the data in the Log Analytics Workspace immediately after 30 days. + * `tags` - (Optional) A mapping of tags to assign to the resource. ~> **NOTE:** If a `azurerm_log_analytics_workspace` is connected to a `azurerm_log_analytics_cluster` via a `azurerm_log_analytics_linked_service` you will not be able to modify the workspaces `sku` field until the link between the workspace and the cluster has been broken by deleting the `azurerm_log_analytics_linked_service` resource. All other fields are modifiable while the workspace is linked to a cluster. From 779b6d6fdce5ffb17fa37571157898fbf503098c Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Mon, 11 Dec 2023 23:25:02 +0800 Subject: [PATCH 2/2] update per comments --- .../loganalytics/log_analytics_workspace_resource.go | 6 +++--- .../loganalytics/log_analytics_workspace_resource_test.go | 2 +- website/docs/r/log_analytics_workspace.html.markdown | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_workspace_resource.go b/internal/services/loganalytics/log_analytics_workspace_resource.go index 27a7f31812c2..3c79c1330b1f 100644 --- a/internal/services/loganalytics/log_analytics_workspace_resource.go +++ b/internal/services/loganalytics/log_analytics_workspace_resource.go @@ -154,7 +154,7 @@ func resourceLogAnalyticsWorkspace() *pluginsdk.Resource { ValidateFunc: datacollectionrules.ValidateDataCollectionRuleID, }, - "immediate_purge_data_on_30_days_enabled": { + "immediate_data_purge_on_30_days_enabled": { Type: pluginsdk.TypeBool, Optional: true, }, @@ -308,7 +308,7 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta i // The `ImmediatePurgeDataOn30Days` are not returned before it has been set // nolint : staticcheck - if v, ok := d.GetOkExists("immediate_purge_data_on_30_days_enabled"); ok { + if v, ok := d.GetOkExists("immediate_data_purge_on_30_days_enabled"); ok { parameters.Properties.Features.ImmediatePurgeDataOn30Days = utils.Bool(v.(bool)) } @@ -476,7 +476,7 @@ func resourceLogAnalyticsWorkspaceRead(d *pluginsdk.ResourceData, meta interface } d.Set("allow_resource_only_permissions", allowResourceOnlyPermissions) d.Set("local_authentication_disabled", disableLocalAuth) - d.Set("immediate_purge_data_on_30_days_enabled", purgeDataOnThirtyDays) + d.Set("immediate_data_purge_on_30_days_enabled", purgeDataOnThirtyDays) defaultDataCollectionRuleResourceId := "" if props.DefaultDataCollectionRuleResourceId != nil { diff --git a/internal/services/loganalytics/log_analytics_workspace_resource_test.go b/internal/services/loganalytics/log_analytics_workspace_resource_test.go index 773dedc4dbce..fa3abd32b9b1 100644 --- a/internal/services/loganalytics/log_analytics_workspace_resource_test.go +++ b/internal/services/loganalytics/log_analytics_workspace_resource_test.go @@ -983,7 +983,7 @@ resource "azurerm_log_analytics_workspace" "test" { resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" retention_in_days = 30 - immediate_purge_data_on_30_days_enabled = %[4]t + immediate_data_purge_on_30_days_enabled = %[4]t } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enable) } diff --git a/website/docs/r/log_analytics_workspace.html.markdown b/website/docs/r/log_analytics_workspace.html.markdown index c2292861571e..95eeb0fa4d72 100644 --- a/website/docs/r/log_analytics_workspace.html.markdown +++ b/website/docs/r/log_analytics_workspace.html.markdown @@ -69,7 +69,7 @@ The following arguments are supported: * `data_collection_rule_id` - (Optional) The ID of the Data Collection Rule to use for this workspace. -* `immediate_purge_data_on_30_days_enabled` - (Optional) Whether to remove the data in the Log Analytics Workspace immediately after 30 days. +* `immediate_data_purge_on_30_days_enabled` - (Optional) Whether to remove the data in the Log Analytics Workspace immediately after 30 days. * `tags` - (Optional) A mapping of tags to assign to the resource.