diff --git a/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go b/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go index a59dcd661a86..3d61b2f89627 100644 --- a/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go +++ b/azurerm/internal/services/loganalytics/log_analytics_workspace_resource.go @@ -84,11 +84,18 @@ func resourceLogAnalyticsWorkspace() *schema.Resource { string(operationalinsights.WorkspaceSkuNameEnumPremium), string(operationalinsights.WorkspaceSkuNameEnumStandalone), string(operationalinsights.WorkspaceSkuNameEnumStandard), + string(operationalinsights.WorkspaceSkuNameEnumCapacityReservation), "Unlimited", // TODO check if this is actually no longer valid, removed in v28.0.0 of the SDK }, true), DiffSuppressFunc: logAnalyticsLinkedServiceSkuChangeCaseDifference, }, + "reservation_capcity_in_gb_per_day": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.All(validation.IntBetween(100, 5000), validation.IntDivisibleBy(100)), + }, + "retention_in_days": { Type: schema.TypeInt, Optional: true, @@ -210,6 +217,19 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta inte } } + capacityReservationLevel, ok := d.GetOk("reservation_capcity_in_gb_per_day") + if ok { + if strings.EqualFold(skuName, string(operationalinsights.WorkspaceSkuNameEnumCapacityReservation)) { + parameters.WorkspaceProperties.Sku.CapacityReservationLevel = utils.Int32((int32(capacityReservationLevel.(int)))) + } else { + return fmt.Errorf("`reservation_capcity_in_gb_per_day` can only be used with the `CapacityReservation` SKU") + } + } else { + if strings.EqualFold(skuName, string(operationalinsights.WorkspaceSkuNameEnumCapacityReservation)) { + return fmt.Errorf("`reservation_capcity_in_gb_per_day` must be set when using the `CapacityReservation` SKU") + } + } + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) if err != nil { return err @@ -256,6 +276,10 @@ func resourceLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface{}) d.Set("portal_url", "") if sku := resp.Sku; sku != nil { d.Set("sku", sku.Name) + + if capacityReservationLevel := sku.CapacityReservationLevel; capacityReservationLevel != nil { + d.Set("reservation_capcity_in_gb_per_day", capacityReservationLevel) + } } d.Set("retention_in_days", resp.RetentionInDays) if resp.WorkspaceProperties != nil && resp.WorkspaceProperties.Sku != nil && strings.EqualFold(string(resp.WorkspaceProperties.Sku.Name), string(operationalinsights.WorkspaceSkuNameEnumFree)) { diff --git a/azurerm/internal/services/loganalytics/log_analytics_workspace_resource_test.go b/azurerm/internal/services/loganalytics/log_analytics_workspace_resource_test.go index 7c504944e1e0..4d156f1ab6be 100644 --- a/azurerm/internal/services/loganalytics/log_analytics_workspace_resource_test.go +++ b/azurerm/internal/services/loganalytics/log_analytics_workspace_resource_test.go @@ -177,6 +177,21 @@ func TestAccLogAnalyticsWorkspace_withInternetQueryEnabled(t *testing.T) { data.ImportStep(), }) } +func TestAccLogAnalyticsWorkspace_withCapacityReservation(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") + r := LogAnalyticsWorkspaceResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.withCapacityReservation(data, 2300), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("reservation_capcity_in_gb_per_day").HasValue("2300"), + ), + }, + data.ImportStep(), + }) +} func (t LogAnalyticsWorkspaceResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { id, err := parse.LogAnalyticsWorkspaceID(state.ID) @@ -430,3 +445,25 @@ resource "azurerm_log_analytics_workspace" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func (LogAnalyticsWorkspaceResource) withCapacityReservation(data acceptance.TestData, capacityReservation int) 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 + internet_query_enabled = false + sku = "CapacityReservation" + reservation_capcity_in_gb_per_day = %d +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, capacityReservation) +} diff --git a/website/docs/r/log_analytics_workspace.html.markdown b/website/docs/r/log_analytics_workspace.html.markdown index bb41cb16e2ad..8971074fe10a 100644 --- a/website/docs/r/log_analytics_workspace.html.markdown +++ b/website/docs/r/log_analytics_workspace.html.markdown @@ -37,7 +37,7 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `sku` - (Optional) Specifies the Sku of the Log Analytics Workspace. Possible values are `Free`, `PerNode`, `Premium`, `Standard`, `Standalone`, `Unlimited`, and `PerGB2018` (new Sku as of `2018-04-03`). Defaults to `PerGB2018`. +* `sku` - (Optional) Specifies the Sku of the Log Analytics Workspace. Possible values are `Free`, `PerNode`, `Premium`, `Standard`, `Standalone`, `Unlimited`, `CapacityReservation`, and `PerGB2018` (new Sku as of `2018-04-03`). Defaults to `PerGB2018`. ~> **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). @@ -47,12 +47,16 @@ The following arguments are supported: * `daily_quota_gb` - (Optional) The workspace daily quota for ingestion in GB. Defaults to -1 (unlimited) if omitted. -~> **NOTE:** When `sku_name` is set to `Free` this field can be set to a maximum of `0.5` (GB), and has a default value of `0.5`. +~> **NOTE:** When `sku` is set to `Free` this field can be set to a maximum of `0.5` (GB), and has a default value of `0.5`. * `internet_ingestion_enabled ` - (Optional) Should the Log Analytics Workflow support ingestion over the Public Internet? Defaults to `true`. * `internet_query_enabled` - (Optional) Should the Log Analytics Workflow support querying over the Public Internet? Defaults to `true`. +* `reservation_capcity_in_gb_per_day` - (Optional) The capacity reservation level in GB for this workspace. Must be in increments of 100 between 100 and 5000. + +~> **NOTE:** `reservation_capcity_in_gb_per_day` can only be used when the `sku` is set to `CapacityReservation`. + * `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` it will not be able to be modified until link between the workspace and the cluster has been broken by deleting the `azurerm_log_analytics_linked_service` resource.