From 2896a79a09c9fb1a8179dbc3322acf873de7710d Mon Sep 17 00:00:00 2001 From: Chirag Agarwal Date: Thu, 23 Jan 2025 18:23:58 +0530 Subject: [PATCH] BE-468: Changelog --- CHANGELOG.md | 2 +- .../resource_sumologic_scan_budget_test.go | 99 ++++++++++--------- website/docs/r/scan_budget.html.markdown | 58 +++++++++++ 3 files changed, 112 insertions(+), 47 deletions(-) create mode 100644 website/docs/r/scan_budget.html.markdown diff --git a/CHANGELOG.md b/CHANGELOG.md index daad9d3e..ea258e73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## X.Y.Z (Unreleased) -* Add new change notes here +* **New Resource:** sumologic_scan_budget ## 3.0.1 (January 17, 2025) **ENHANCEMENTS:** diff --git a/sumologic/resource_sumologic_scan_budget_test.go b/sumologic/resource_sumologic_scan_budget_test.go index 1fda1980..4f8def06 100644 --- a/sumologic/resource_sumologic_scan_budget_test.go +++ b/sumologic/resource_sumologic_scan_budget_test.go @@ -31,8 +31,7 @@ func TestAccSumologicScanBudget_basic(t *testing.T) { testWindow := "Query" testApplicableOn := "PerEntity" testGroupBy := "User" - testAction := "StopScan" - testScope := "j" + testAction := "StopForeGroundScan" testStatus := "active" resource.Test(t, resource.TestCase{ @@ -41,7 +40,7 @@ func TestAccSumologicScanBudget_basic(t *testing.T) { CheckDestroy: testAccCheckScanBudgetDestroy(scanBudget), Steps: []resource.TestStep{ { - Config: testAccCheckSumologicScanBudgetConfigImported(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testScope, testStatus), + Config: testAccCheckSumologicScanBudgetConfigImported(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testStatus), }, { ResourceName: "sumologic_scan_budget.foo", @@ -61,8 +60,7 @@ func TestAccSumologicScanBudget_create(t *testing.T) { testWindow := "Query" testApplicableOn := "PerEntity" testGroupBy := "User" - testAction := "StopScan" - testScope := "j" + testAction := "StopForeGroundScan" testStatus := "active" resource.Test(t, resource.TestCase{ @@ -71,19 +69,18 @@ func TestAccSumologicScanBudget_create(t *testing.T) { CheckDestroy: testAccCheckScanBudgetDestroy(scanBudget), Steps: []resource.TestStep{ { - Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testScope, testStatus), + Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testStatus), Check: resource.ComposeTestCheckFunc( testAccCheckScanBudgetExists("sumologic_scan_budget.test", &scanBudget, t), testAccCheckScanBudgetAttributes("sumologic_scan_budget.test"), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "name", testName), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "capacity", strconv.Itoa(testCapacity)), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "unit", testUnit), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "budgetType", testBudgetType), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "budget_type", testBudgetType), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "window", testWindow), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "applicableOn", testApplicableOn), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "groupBy", testGroupBy), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "applicable_on", testApplicableOn), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "group_by", testGroupBy), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "action", testAction), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "scope", testScope), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "status", testStatus), ), }, @@ -101,8 +98,7 @@ func TestAccSumologicScanBudget_update(t *testing.T) { testWindow := "Query" testApplicableOn := "PerEntity" testGroupBy := "User" - testAction := "StopScan" - testScope := "j" + testAction := "StopForeGroundScan" testStatus := "active" testUpdatedName := "Test Budget" @@ -112,8 +108,7 @@ func TestAccSumologicScanBudget_update(t *testing.T) { testUpdatedWindow := "Daily" testUpdatedApplicableOn := "PerEntity" testUpdatedGroupBy := "User" - testUpdatedAction := "StopScan" - testUpdatedScope := "j" + testUpdatedAction := "Warn" testUpdatedStatus := "active" resource.Test(t, resource.TestCase{ @@ -122,34 +117,32 @@ func TestAccSumologicScanBudget_update(t *testing.T) { CheckDestroy: testAccCheckScanBudgetDestroy(scanBudget), Steps: []resource.TestStep{ { - Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testScope, testStatus), + Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testStatus), Check: resource.ComposeTestCheckFunc( testAccCheckScanBudgetExists("sumologic_scan_budget.test", &scanBudget, t), testAccCheckScanBudgetAttributes("sumologic_scan_budget.test"), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "name", testName), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "capacity", strconv.Itoa(testCapacity)), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "unit", testUnit), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "budgetType", testBudgetType), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "budget_type", testBudgetType), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "window", testWindow), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "applicableOn", testApplicableOn), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "groupBy", testGroupBy), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "applicable_on", testApplicableOn), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "group_by", testGroupBy), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "action", testAction), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "scope", testScope), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "status", testStatus), ), }, { - Config: testAccSumologicScanBudgetUpdate(testUpdatedName, testUpdatedCapacity, testUpdatedUnit, testUpdatedBudgetType, testUpdatedWindow, testUpdatedApplicableOn, testUpdatedGroupBy, testUpdatedAction, testUpdatedScope, testUpdatedStatus), + Config: testAccSumologicScanBudgetUpdate(testUpdatedName, testUpdatedCapacity, testUpdatedUnit, testUpdatedBudgetType, testUpdatedWindow, testUpdatedApplicableOn, testUpdatedGroupBy, testUpdatedAction, testUpdatedStatus), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("sumologic_scan_budget.test", "name", testUpdatedName), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "capacity", strconv.Itoa(testUpdatedCapacity)), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "unit", testUpdatedUnit), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "budgetType", testUpdatedBudgetType), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "budget_type", testUpdatedBudgetType), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "window", testUpdatedWindow), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "applicableOn", testUpdatedApplicableOn), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "groupBy", testUpdatedGroupBy), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "applicable_on", testUpdatedApplicableOn), + resource.TestCheckResourceAttr("sumologic_scan_budget.test", "group_by", testUpdatedGroupBy), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "action", testUpdatedAction), - resource.TestCheckResourceAttr("sumologic_scan_budget.test", "scope", testUpdatedScope), resource.TestCheckResourceAttr("sumologic_scan_budget.test", "status", testUpdatedStatus), ), }, @@ -197,55 +190,70 @@ func testAccCheckScanBudgetExists(name string, scanBudget *ScanBudget, t *testin return nil } } -func testAccCheckSumologicScanBudgetConfigImported(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, scope string, status string) string { +func testAccCheckSumologicScanBudgetConfigImported(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, status string) string { return fmt.Sprintf(` resource "sumologic_scan_budget" "foo" { name = "%s" capacity = %d unit = "%s" - budgetType = "%s" + budget_type = "%s" window = "%s" - applicableOn = "%s" - groupBy = "%s" + applicable_on = "%s" + group_by = "%s" action = "%s" - scope = "%s" + scope { + included_users = ["000000000000011C"] + excluded_users = [] + included_roles = [] + excluded_roles = ["0000000000000196"] + } status = "%s" } -`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, scope, status) +`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, status) } -func testAccSumologicScanBudget(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, scope string, status string) string { +func testAccSumologicScanBudget(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, status string) string { return fmt.Sprintf(` resource "sumologic_scan_budget" "test" { name = "%s" capacity = %d unit = "%s" - budgetType = "%s" + budget_type = "%s" window = "%s" - applicableOn = "%s" - groupBy = "%s" + applicable_on = "%s" + group_by = "%s" action = "%s" - scope = "%s" + scope { + included_users = ["000000000000011C"] + excluded_users = [] + included_roles = [] + excluded_roles = ["0000000000000196"] + } status = "%s" } -`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, scope, status) +`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, status) } -func testAccSumologicScanBudgetUpdate(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, scope string, status string) string { +func testAccSumologicScanBudgetUpdate(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, status string) string { return fmt.Sprintf(` resource "sumologic_scan_budget" "test" { name = "%s" capacity = %d unit = "%s" - budgetType = "%s" + budget_type = "%s" window = "%s" - applicableOn = "%s" - groupBy = "%s" + applicable_on = "%s" + group_by = "%s" action = "%s" - scope = "%s" + scope { + included_users = ["000000000000011C"] + excluded_users = [] + included_roles = [] + excluded_roles = ["0000000000000196"] + } status = "%s" } -`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, scope, status) +`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, status) } func testAccCheckScanBudgetAttributes(name string) resource.TestCheckFunc { @@ -254,12 +262,11 @@ func testAccCheckScanBudgetAttributes(name string) resource.TestCheckFunc { resource.TestCheckResourceAttrSet(name, "name"), resource.TestCheckResourceAttrSet(name, "capacity"), resource.TestCheckResourceAttrSet(name, "unit"), - resource.TestCheckResourceAttrSet(name, "budgetType"), + resource.TestCheckResourceAttrSet(name, "budget_type"), resource.TestCheckResourceAttrSet(name, "window"), - resource.TestCheckResourceAttrSet(name, "applicableOn"), - resource.TestCheckResourceAttrSet(name, "groupBy"), + resource.TestCheckResourceAttrSet(name, "applicable_on"), + resource.TestCheckResourceAttrSet(name, "group_by"), resource.TestCheckResourceAttrSet(name, "action"), - resource.TestCheckResourceAttrSet(name, "scope"), resource.TestCheckResourceAttrSet(name, "status"), ) return f(s) diff --git a/website/docs/r/scan_budget.html.markdown b/website/docs/r/scan_budget.html.markdown new file mode 100644 index 00000000..26be98d9 --- /dev/null +++ b/website/docs/r/scan_budget.html.markdown @@ -0,0 +1,58 @@ +--- +layout: "sumologic" +page_title: "SumoLogic: sumologic_scan_budget" +description: |- + Provides a Sumologic Scan Budget +--- + +# sumologic_scan_budget +Provides a [Sumologic Scan Budget][1]. + +## Example Usage +```hcl +resource "sumologic_scan_budget" "budget" { + name = "TestBudget" + capacity = 10 + unit = "GB" + budget_type = "ScanBudget" + window = "Query" + applicable_on = "PerEntity" + group_by = "User" + action = "StopScan" + status = "active" + scope { + included_users = ["000000000000011C"] + excluded_users = [] + included_roles = [] + excluded_roles = ["0000000000000196"] + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Display name of the scan budget. This must be unique across all the scan budgets. +* `capacity` - (Required) Capacity of the scan budget. Only whole numbers are supported. +* `unit` - (Required) Unit of the capacity. Supported values are: `MB`, `GB` and `TB`. +* `budget_type` - (Required) Type of the budget. Supported values are: `ScanBudget`. +* `window` - (Required) Window of the budget. Supported values are: `Query`, `Daily`, `Weekly` and `Monthly`. +* `applicable_on` - (Required) Grouping of the budget. Supported values are: `PerEntity` and `Sum`. +* `group_by` - (Required) Grouping Entity of the budget. Supported values are: `User`. +* `action` - (Required) Action to be taken if the budget is breached. Supported values are: `StopForeGroundScan` and `Warn`. +* `scope` - (Required) Scope of the budget. +* `status` - (Required) Signifies the state of the budget. Supported values are: `active` and `inactive`. + +The following attributes are exported: + +* `id` - The internal ID of the budget. + +## Import +Scan budgets can be imported using the budget ID, e.g.: + +```hcl +terraform import sumologic_scan_budget.budget 00000000000123AB +``` + +[1]: https://help.sumologic.com/docs/manage/manage-subscription/usage-management/