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

r/log_analytics_workspace - Expose capacity_reservation_level and CapacityReservation SKU value #10612

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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,
},

"capacity_reservation_level": {
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.All(validation.IntBetween(100, 5000), validation.IntDivisibleBy(100)),
},

"retention_in_days": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -210,6 +217,19 @@ func resourceLogAnalyticsWorkspaceCreateUpdate(d *schema.ResourceData, meta inte
}
}

capacityReservationLevel, ok := d.GetOk("capacity_reservation_level")
if ok {
if strings.EqualFold(skuName, string(operationalinsights.WorkspaceSkuNameEnumCapacityReservation)) {
parameters.WorkspaceProperties.Sku.CapacityReservationLevel = utils.Int32((int32(capacityReservationLevel.(int))))
} else {
return fmt.Errorf("`capacity_reservation_level` can only be used with the `CapacityReservation` SKU")
}
} else {
if strings.EqualFold(skuName, string(operationalinsights.WorkspaceSkuNameEnumCapacityReservation)) {
return fmt.Errorf("`capacity_reservation_level` must be set when using the `CapacityReservation` SKU")
}
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters)
if err != nil {
return err
Expand Down Expand Up @@ -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("capacity_reservation_level", 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("capacity_reservation_level").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)
Expand Down Expand Up @@ -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"
capacity_reservation_level = %d
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, capacityReservation)
}
8 changes: 6 additions & 2 deletions website/docs/r/log_analytics_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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`.

* `capacity_reservation` - (Optional) The capacity reservation level for this workspace. Must be in increments of 100 between 100 and 5000.

~> **NOTE:** `capacity_reservation` 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.
Expand Down