Skip to content

Commit

Permalink
log_analytics_workspace: support for the daily_quota_gb property (#…
Browse files Browse the repository at this point in the history
…8861)

Resolves #3288

The daily volume cap is off by default as per the docs, so I've set the default value to -1 which means unlimited (no cap). Validation is set to either be -1 or some non-negative value.

One new test per resource/data source added, and one old test updated to confirm default value.
  • Loading branch information
Lucretius authored Oct 22, 2020
1 parent 0235910 commit 539b9e3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func dataSourceLogAnalyticsWorkspace() *schema.Resource {
Computed: true,
},

"daily_quota_gb": {
Type: schema.TypeFloat,
Computed: true,
},

"workspace_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -101,6 +106,12 @@ func dataSourceLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface{
}
d.Set("retention_in_days", resp.RetentionInDays)

if workspaceCapping := resp.WorkspaceCapping; workspaceCapping != nil {
d.Set("daily_quota_gb", resp.WorkspaceCapping.DailyQuotaGb)
} else {
d.Set("daily_quota_gb", utils.Float(-1))
}

sharedKeys, err := sharedKeysClient.GetSharedKeys(ctx, resGroup, name)
if err != nil {
log.Printf("[ERROR] Unable to List Shared keys for Log Analytics workspaces %s: %+v", name, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func resourceArmLogAnalyticsWorkspace() *schema.Resource {
ValidateFunc: validation.Any(validation.IntBetween(30, 730), validation.IntInSlice([]int{7})),
},

"daily_quota_gb": {
Type: schema.TypeFloat,
Optional: true,
Default: -1.0,
ValidateFunc: validation.Any(validation.FloatBetween(-1, -1), validation.FloatAtLeast(0)),
},

"workspace_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -130,6 +137,7 @@ func resourceArmLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta i
}

retentionInDays := int32(d.Get("retention_in_days").(int))
dailyQuotaGb := d.Get("daily_quota_gb").(float64)

t := d.Get("tags").(map[string]interface{})

Expand All @@ -140,6 +148,9 @@ func resourceArmLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta i
WorkspaceProperties: &operationalinsights.WorkspaceProperties{
Sku: sku,
RetentionInDays: &retentionInDays,
WorkspaceCapping: &operationalinsights.WorkspaceCapping{
DailyQuotaGb: &dailyQuotaGb,
},
},
}

Expand Down Expand Up @@ -197,6 +208,11 @@ func resourceArmLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface
d.Set("sku", sku.Name)
}
d.Set("retention_in_days", resp.RetentionInDays)
if workspaceCapping := resp.WorkspaceCapping; workspaceCapping != nil {
d.Set("daily_quota_gb", resp.WorkspaceCapping.DailyQuotaGb)
} else {
d.Set("daily_quota_gb", utils.Float(-1))
}

sharedKeys, err := sharedKeysClient.GetSharedKeys(ctx, id.ResourceGroup, id.Name)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ func TestAccDataSourceAzureRMLogAnalyticsWorkspace_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "sku", "pergb2018"),
resource.TestCheckResourceAttr(data.ResourceName, "retention_in_days", "30"),
resource.TestCheckResourceAttr(data.ResourceName, "daily_quota_gb", "-1"),
),
},
},
})
}

func TestAccDataSourceAzureRMLogAnalyticsWorkspace_volumeCapWithDataSource(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_log_analytics_workspace", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMLogAnalyticsWorkspace_volumeCapWithDataSource(data, 4.5),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(data.ResourceName, "sku", "pergb2018"),
resource.TestCheckResourceAttr(data.ResourceName, "retention_in_days", "30"),
resource.TestCheckResourceAttr(data.ResourceName, "daily_quota_gb", "4.5"),
),
},
},
Expand All @@ -38,3 +59,15 @@ data "azurerm_log_analytics_workspace" "test" {
}
`, config)
}

func testAccDataSourceAzureRMLogAnalyticsWorkspace_volumeCapWithDataSource(data acceptance.TestData, volumeCapGb float64) string {
config := testAccAzureRMLogAnalyticsWorkspace_withVolumeCap(data, volumeCapGb)
return fmt.Sprintf(`
%s
data "azurerm_log_analytics_workspace" "test" {
name = azurerm_log_analytics_workspace.test.name
resource_group_name = azurerm_log_analytics_workspace.test.resource_group_name
}
`, config)
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ func TestAccAzureRMLogAnalyticsWorkspace_withDefaultSku(t *testing.T) {
})
}

func TestAccAzureRMLogAnalyticsWorkspace_withVolumeCap(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_withVolumeCap(data, 4.5),
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
Expand Down Expand Up @@ -307,3 +326,29 @@ resource "azurerm_log_analytics_workspace" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMLogAnalyticsWorkspace_withVolumeCap(data acceptance.TestData, volumeCapGb float64) 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
daily_quota_gb = %f
tags = {
Environment = "Test"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, volumeCapGb)
}
2 changes: 2 additions & 0 deletions website/docs/d/log_analytics_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The following attributes are exported:

* `retention_in_days` - The workspace data retention in days.

* `daily_quota_gb` - The workspace daily quota for ingestion in GB.

* `tags` - A mapping of tags assigned to the resource.

## Timeouts
Expand Down
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 @@ -43,6 +43,8 @@ The following arguments are supported:

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

* `daily_quota_gb` - (Optional) The workspace daily quota for ingestion in GB. Defaults to -1 (unlimited).

* `tags` - (Optional) A mapping of tags to assign to the resource.

## Attributes Reference
Expand Down

0 comments on commit 539b9e3

Please sign in to comment.