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 - support for the immediate_data_purge_on_30_days_enabled property #24015

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func resourceLogAnalyticsWorkspace() *pluginsdk.Resource {
ValidateFunc: datacollectionrules.ValidateDataCollectionRuleID,
},

"immediate_data_purge_on_30_days_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"workspace_id": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -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_data_purge_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 {
Expand Down Expand Up @@ -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_data_purge_on_30_days_enabled", purgeDataOnThirtyDays)

defaultDataCollectionRuleResourceId := ""
if props.DefaultDataCollectionRuleResourceId != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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_data_purge_on_30_days_enabled = %[4]t
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enable)
}
2 changes: 2 additions & 0 deletions website/docs/r/log_analytics_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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_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.

~> **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.
Expand Down
Loading