Skip to content

Commit

Permalink
Merge pull request #549 from SumoLogic/vsinghal-add-budgetType-field-…
Browse files Browse the repository at this point in the history
…ingest-budget-v2

add support for new budgetType in Ingest Budget V2 resource
  • Loading branch information
sumovishal authored Jul 21, 2023
2 parents af186d6 + e6f2e58 commit 8bc58c5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FEATURES:
* **New Resource:** sumologic_metrics_search (GH-528)
* **New Resource:** sumologic_rum_source (GH-547)
* Add `budgetType` support for sumologic_ingest_budget_v2 (GH-549)

BUG FIXES:
* Enforce non-empty string validation of `default_normalized_domain` and `domain_mappings` in cse_entity_normalization resource. (GH-540)
Expand Down
9 changes: 9 additions & 0 deletions sumologic/resource_sumologic_ingest_budget_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func resourceSumologicIngestBudgetV2() *schema.Resource {
ForceNew: false,
},

"budget_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: false,
Default: "dailyVolume",
},

"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -119,6 +126,7 @@ func resourceSumologicIngestBudgetV2Read(d *schema.ResourceData, meta interface{
d.Set("description", ingestBudgetV2.Description)
d.Set("action", ingestBudgetV2.Action)
d.Set("capacity_bytes", ingestBudgetV2.CapacityBytes)
d.Set("budget_type", ingestBudgetV2.BudgetType)

return nil
}
Expand Down Expand Up @@ -150,6 +158,7 @@ func resourceToIngestBudgetV2(d *schema.ResourceData) IngestBudgetV2 {
Timezone: d.Get("timezone").(string),
ID: d.Id(),
Action: d.Get("action").(string),
BudgetType: d.Get("budget_type").(string),
Description: d.Get("description").(string),
AuditThreshold: d.Get("audit_threshold").(int),
CapacityBytes: d.Get("capacity_bytes").(int),
Expand Down
31 changes: 21 additions & 10 deletions sumologic/resource_sumologic_ingest_budget_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ func TestAccSumologicIngestBudgetV2_basic(t *testing.T) {
testDescription := "description-7hUwr"
testAction := "stopCollecting"
testCapacityBytes := 1000
testBudgetType := "dailyVolume"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIngestBudgetV2Destroy(ingestBudgetV2),
Steps: []resource.TestStep{
{
Config: testAccCheckSumologicIngestBudgetV2ConfigImported(testName, testScope, testTimezone, testResetTime, testAuditThreshold, testDescription, testAction, testCapacityBytes),
Config: testAccCheckSumologicIngestBudgetV2ConfigImported(testName, testScope, testTimezone, testResetTime, testAuditThreshold, testDescription, testAction, testCapacityBytes, testBudgetType),
},
{
ResourceName: "sumologic_ingest_budget_v2.foo",
Expand All @@ -58,13 +59,14 @@ func TestAccSumologicIngestBudgetV2_create(t *testing.T) {
testDescription := "description-900AB"
testAction := "stopCollecting"
testCapacityBytes := 1000
testBudgetType := "dailyVolume"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIngestBudgetV2Destroy(ingestBudgetV2),
Steps: []resource.TestStep{
{
Config: testAccSumologicIngestBudgetV2(testName, testScope, testTimezone, testResetTime, testAuditThreshold, testDescription, testAction, testCapacityBytes),
Config: testAccSumologicIngestBudgetV2(testName, testScope, testTimezone, testResetTime, testAuditThreshold, testDescription, testAction, testCapacityBytes, testBudgetType),
Check: resource.ComposeTestCheckFunc(
testAccCheckIngestBudgetV2Exists("sumologic_ingest_budget_v2.test", &ingestBudgetV2, t),
testAccCheckIngestBudgetV2Attributes("sumologic_ingest_budget_v2.test"),
Expand All @@ -76,6 +78,7 @@ func TestAccSumologicIngestBudgetV2_create(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "description", testDescription),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "action", testAction),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "capacity_bytes", strconv.Itoa(testCapacityBytes)),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "budget_type", testBudgetType),
),
},
},
Expand All @@ -92,6 +95,7 @@ func TestAccSumologicIngestBudgetV2_update(t *testing.T) {
testDescription := "description-2tAk8"
testAction := "stopCollecting"
testCapacityBytes := 1000
testBudgetType := "dailyVolume"

testUpdatedName := "Developer BudgetUpdate"
testUpdatedScope := "_sourceCategory=*prod*nginx*Update"
Expand All @@ -101,14 +105,15 @@ func TestAccSumologicIngestBudgetV2_update(t *testing.T) {
testUpdatedDescription := "description-pY8kDUpdate"
testUpdatedAction := "keepCollecting"
testUpdatedCapacityBytes := 1001
testUpdatedBudgetType := "dailyVolume"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIngestBudgetV2Destroy(ingestBudgetV2),
Steps: []resource.TestStep{
{
Config: testAccSumologicIngestBudgetV2(testName, testScope, testTimezone, testResetTime, testAuditThreshold, testDescription, testAction, testCapacityBytes),
Config: testAccSumologicIngestBudgetV2(testName, testScope, testTimezone, testResetTime, testAuditThreshold, testDescription, testAction, testCapacityBytes, testBudgetType),
Check: resource.ComposeTestCheckFunc(
testAccCheckIngestBudgetV2Exists("sumologic_ingest_budget_v2.test", &ingestBudgetV2, t),
testAccCheckIngestBudgetV2Attributes("sumologic_ingest_budget_v2.test"),
Expand All @@ -120,10 +125,11 @@ func TestAccSumologicIngestBudgetV2_update(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "description", testDescription),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "action", testAction),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "capacity_bytes", strconv.Itoa(testCapacityBytes)),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "budget_type", testBudgetType),
),
},
{
Config: testAccSumologicIngestBudgetV2Update(testUpdatedName, testUpdatedScope, testUpdatedTimezone, testUpdatedResetTime, testUpdatedAuditThreshold, testUpdatedDescription, testUpdatedAction, testUpdatedCapacityBytes),
Config: testAccSumologicIngestBudgetV2Update(testUpdatedName, testUpdatedScope, testUpdatedTimezone, testUpdatedResetTime, testUpdatedAuditThreshold, testUpdatedDescription, testUpdatedAction, testUpdatedCapacityBytes, testUpdatedBudgetType),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "name", testUpdatedName),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "scope", testUpdatedScope),
Expand All @@ -133,6 +139,7 @@ func TestAccSumologicIngestBudgetV2_update(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "description", testUpdatedDescription),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "action", testUpdatedAction),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "capacity_bytes", strconv.Itoa(testUpdatedCapacityBytes)),
resource.TestCheckResourceAttr("sumologic_ingest_budget_v2.test", "budget_type", testUpdatedBudgetType),
),
},
},
Expand Down Expand Up @@ -179,7 +186,7 @@ func testAccCheckIngestBudgetV2Exists(name string, ingestBudgetV2 *IngestBudgetV
return nil
}
}
func testAccCheckSumologicIngestBudgetV2ConfigImported(name string, scope string, timezone string, resetTime string, auditThreshold int, description string, action string, capacityBytes int) string {
func testAccCheckSumologicIngestBudgetV2ConfigImported(name string, scope string, timezone string, resetTime string, auditThreshold int, description string, action string, capacityBytes int, budgetType string) string {
return fmt.Sprintf(`
resource "sumologic_ingest_budget_v2" "foo" {
name = "%s"
Expand All @@ -190,11 +197,12 @@ resource "sumologic_ingest_budget_v2" "foo" {
description = "%s"
action = "%s"
capacity_bytes = %d
budget_type = "%s"
}
`, name, scope, timezone, resetTime, auditThreshold, description, action, capacityBytes)
`, name, scope, timezone, resetTime, auditThreshold, description, action, capacityBytes, budgetType)
}

func testAccSumologicIngestBudgetV2(name string, scope string, timezone string, resetTime string, auditThreshold int, description string, action string, capacityBytes int) string {
func testAccSumologicIngestBudgetV2(name string, scope string, timezone string, resetTime string, auditThreshold int, description string, action string, capacityBytes int, budgetType string) string {
return fmt.Sprintf(`
resource "sumologic_ingest_budget_v2" "test" {
name = "%s"
Expand All @@ -205,11 +213,12 @@ resource "sumologic_ingest_budget_v2" "test" {
description = "%s"
action = "%s"
capacity_bytes = %d
budget_type = "%s"
}
`, name, scope, timezone, resetTime, auditThreshold, description, action, capacityBytes)
`, name, scope, timezone, resetTime, auditThreshold, description, action, capacityBytes, budgetType)
}

func testAccSumologicIngestBudgetV2Update(name string, scope string, timezone string, resetTime string, auditThreshold int, description string, action string, capacityBytes int) string {
func testAccSumologicIngestBudgetV2Update(name string, scope string, timezone string, resetTime string, auditThreshold int, description string, action string, capacityBytes int, budgetType string) string {
return fmt.Sprintf(`
resource "sumologic_ingest_budget_v2" "test" {
name = "%s"
Expand All @@ -220,8 +229,9 @@ resource "sumologic_ingest_budget_v2" "test" {
description = "%s"
action = "%s"
capacity_bytes = %d
budget_type = "%s"
}
`, name, scope, timezone, resetTime, auditThreshold, description, action, capacityBytes)
`, name, scope, timezone, resetTime, auditThreshold, description, action, capacityBytes, budgetType)
}

func testAccCheckIngestBudgetV2Attributes(name string) resource.TestCheckFunc {
Expand All @@ -234,6 +244,7 @@ func testAccCheckIngestBudgetV2Attributes(name string) resource.TestCheckFunc {
resource.TestCheckResourceAttrSet(name, "audit_threshold"),
resource.TestCheckResourceAttrSet(name, "description"),
resource.TestCheckResourceAttrSet(name, "action"),
resource.TestCheckResourceAttrSet(name, "budget_type"),
resource.TestCheckResourceAttrSet(name, "capacity_bytes"),
)
return f(s)
Expand Down
1 change: 1 addition & 0 deletions sumologic/sumologic_ingest_budget_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type IngestBudgetV2 struct {
Action string `json:"action"`
ResetTime string `json:"resetTime"`
Name string `json:"name"`
BudgetType string `json:"budgetType,omitempty"`
ID string `json:"id,omitempty"`
Scope string `json:"scope"`
Timezone string `json:"timezone"`
Expand Down
8 changes: 5 additions & 3 deletions website/docs/r/ingest_budget_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Provides a [Sumologic Ingest Budget v2][1].
resource "sumologic_ingest_budget_v2" "budget" {
name = "testBudget"
scope = "_sourceCategory=*prod*nginx*"
budget_type = "dailyVolume"
capacity_bytes = 30000000000
description = "For testing purposes"
timezone = "Etc/UTC"
Expand All @@ -28,8 +29,9 @@ The following arguments are supported:

* `name` - (Required) Display name of the ingest budget. This must be unique across all of the ingest budgets
* `scope` - (Required) A scope is a constraint that will be used to identify the messages on which budget needs to be applied. A scope is consists of key and value separated by =. The field must be enabled in the fields table.
* `capacity_bytes` - (Required) Capacity of the ingest budget, in bytes.
* `capacity_bytes` - (Required) Capacity of the ingest budget, in bytes. It takes a few minutes for Collectors to stop collecting when capacity is reached. We recommend setting a soft limit that is lower than your needed hard limit. The capacity bytes unit varies based on the budgetType field. For `dailyVolume` budgetType the capacity specified is in bytes/day whereas for `minuteVolume` budgetType its bytes/min.
* `description` - (Optional) The description of the collector.
* `budget_type` - (Optional) The type of budget. Supported values are: * `dailyVolume` * `minuteVolume`. Default value is `dailyVolume`.
* `timezone` - (Optional) The time zone to use for this collector. The value follows the [tzdata][2] naming convention. Defaults to `Etc/UTC`
* `action` - (Optional) Action to take when ingest budget's capacity is reached. All actions are audited. Supported values are `stopCollecting` and `keepCollecting`.
* `reset_time` - (Optional) Reset time of the ingest budget in HH:MM format. Defaults to `00:00`
Expand All @@ -40,10 +42,10 @@ The following attributes are exported:
* `id` - The internal ID of the ingest budget.

## Import
Ingest budgets can be imported using the name, e.g.:
Ingest budgets can be imported using the budget ID, e.g.:

```hcl
terraform import sumologic_ingest_budget_v2.budget budgetName
terraform import sumologic_ingest_budget_v2.budget 00000000000123AB
```

[1]: https://help.sumologic.com/Beta/Metadata_Ingest_Budgets
Expand Down

0 comments on commit 8bc58c5

Please sign in to comment.