From cbecc80627ef2fc42e3f36ebad286bd6dcada6c7 Mon Sep 17 00:00:00 2001 From: magodo Date: Sat, 9 May 2020 17:16:56 +0800 Subject: [PATCH] `azurerm_log_analytics_workspace` `rentention_in_days` consider Free Tier --- .../log_analytics_workspace_resource.go | 2 +- .../log_analytics_workspace_resource_test.go | 40 +++++++++++++++++++ .../r/log_analytics_workspace.html.markdown | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go b/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go index f790515a4c55..537a06b2110c 100644 --- a/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go +++ b/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go @@ -69,7 +69,7 @@ func resourceArmLogAnalyticsWorkspace() *schema.Resource { Type: schema.TypeInt, Optional: true, Computed: true, - ValidateFunc: validation.IntBetween(30, 730), + ValidateFunc: validation.Any(validation.IntBetween(30, 730), validation.IntInSlice([]int{7})), }, "workspace_id": { diff --git a/azurerm/internal/services/loganalytics/tests/log_analytics_workspace_resource_test.go b/azurerm/internal/services/loganalytics/tests/log_analytics_workspace_resource_test.go index 88687d1752c6..7905cf017de8 100644 --- a/azurerm/internal/services/loganalytics/tests/log_analytics_workspace_resource_test.go +++ b/azurerm/internal/services/loganalytics/tests/log_analytics_workspace_resource_test.go @@ -115,6 +115,25 @@ func TestAccAzureRMLogAnalyticsWorkspace_complete(t *testing.T) { }) } +func TestAccAzureRMLogAnalyticsWorkspace_freeTier(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogAnalyticsWorkspace_freeTier(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMLogAnalyticsWorkspaceDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.WorkspacesClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -229,3 +248,24 @@ resource "azurerm_log_analytics_workspace" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func testAccAzureRMLogAnalyticsWorkspace_freeTier(data acceptance.TestData) 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 = "Free" + retention_in_days = 7 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} diff --git a/website/docs/r/log_analytics_workspace.html.markdown b/website/docs/r/log_analytics_workspace.html.markdown index fdff86b466d1..cd2016922e81 100644 --- a/website/docs/r/log_analytics_workspace.html.markdown +++ b/website/docs/r/log_analytics_workspace.html.markdown @@ -41,7 +41,7 @@ The following arguments are supported: ~> **NOTE:** A new pricing model took effect on `2018-04-03`, which requires the SKU `PerGB2018`. If you're provisioned resources before this date you have the option of remaining with the previous Pricing SKU and using the other SKU's defined above. More information about [the Pricing SKU's is available at the following URI](http://aka.ms/PricingTierWarning). -* `retention_in_days` - (Optional) The workspace data retention in days. Possible values range between 30 and 730. +* `retention_in_days` - (Optional) The workspace data retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730. * `tags` - (Optional) A mapping of tags to assign to the resource.