Skip to content

Commit 42311a6

Browse files
committed
Merge branch 'master' into SUMO-205710-deprecate-threshold-type-in-ss
2 parents b30744b + c838185 commit 42311a6

11 files changed

+444
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
## 2.20.1 (Unreleased)
1+
## 2.21.1 (Unreleased)
2+
3+
BUG FIXES:
4+
* Deprecate thresholdType field under searchSchedule in content resource (GH-483)
5+
6+
## 2.21.0 (February 27, 2023)
27
FEATURES:
38
* **New Resource:** sumologic_cse_first_seen_rule (GH-476)
9+
* **New Resource:** sumologic_cse_automation (GH-467)
410
* Add new optional `min_data_points` field to metrics monitor trigger_conditions (GH-464)
11+
* Added support to manage monitor based SLOs (GH-480)
512

613
BUG FIXES:
714
* Added validations to fail if no trigger conditions defined in monitor resource (GH-463)
815
* Fixed validation on connection name to match with UI/API (GH-478)
9-
* Deprecate thresholdType field under searchSchedule in content resource (GH-483)
16+
* Corrected SLO examples in the SLO terraform documentation (GH-481)
17+
* Fixed Sumo help docs link in SLO documentation (GH-481)
1018

1119
## 2.20.0 (December 15, 2022)
1220
FEATURES:
@@ -15,7 +23,6 @@ FEATURES:
1523
BUG FIXES:
1624
* Fix typo on cse_match_list documentation (GH-461)
1725

18-
1926
## 2.19.2 (November 4, 2022)
2027
ENHANCEMENTS:
2128
* Suppress diffs for equivalent values of some time attributes. This should reduce output of `terraform plan` that didn't disappear after running `terraform apply`. (GH-442)

GNUmakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
33
WEBSITE_REPO=github.com/hashicorp/terraform-website
44
PKG_NAME=sumologic
55
PLUGIN_DIR=~/.terraform.d/plugins
6+
UNAME=$(shell uname -m)
67

78
default: build
89

@@ -20,11 +21,19 @@ install: fmtcheck
2021
# separate command for installing in the right directory for testing development changes
2122
install-dev: fmtcheck
2223
mkdir -vp $(PLUGIN_DIR)
24+
ifeq ($(UNAME), arm64)
25+
go build -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_arm64/terraform-provider-sumologic
26+
else
2327
go build -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_amd64/terraform-provider-sumologic
28+
endif
2429

2530
uninstall:
2631
@rm -vf $(PLUGIN_DIR)/terraform-provider-sumologic
32+
ifeq ($(UNAME), arm64)
33+
@rm -vf $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_arm64/terraform-provider-sumologic
34+
else
2735
@rm -vf $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_amd64/terraform-provider-sumologic
36+
endif
2837

2938
errcheck:
3039
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

sumologic/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func Provider() terraform.ResourceProvider {
4343
},
4444
},
4545
ResourcesMap: map[string]*schema.Resource{
46+
"sumologic_cse_automation": resourceSumologicCSEAutomation(),
4647
"sumologic_cse_entity_normalization_configuration": resourceSumologicCSEEntityNormalizationConfiguration(),
4748
"sumologic_cse_inventory_entity_group_configuration": resourceSumologicCSEInventoryEntityGroupConfiguration(),
4849
"sumologic_cse_entity_entity_group_configuration": resourceSumologicCSEEntityEntityGroupConfiguration(),
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package sumologic
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
6+
"log"
7+
)
8+
9+
func resourceSumologicCSEAutomation() *schema.Resource {
10+
return &schema.Resource{
11+
Create: resourceSumologicCSEAutomationCreate,
12+
Read: resourceSumologicCSEAutomationRead,
13+
Delete: resourceSumologicCSEAutomationDelete,
14+
Update: resourceSumologicCSEAutomationUpdate,
15+
Importer: &schema.ResourceImporter{
16+
State: schema.ImportStatePassthrough,
17+
},
18+
19+
Schema: map[string]*schema.Schema{
20+
"name": {
21+
Type: schema.TypeString,
22+
Computed: true,
23+
},
24+
"description": {
25+
Type: schema.TypeString,
26+
Computed: true,
27+
},
28+
"playbook_id": {
29+
Type: schema.TypeString,
30+
Required: true,
31+
},
32+
"cse_resource_type": {
33+
Type: schema.TypeString,
34+
Required: true,
35+
},
36+
"cse_resource_sub_types": {
37+
Type: schema.TypeList,
38+
Optional: true,
39+
Elem: &schema.Schema{
40+
Type: schema.TypeString,
41+
},
42+
},
43+
"execution_types": {
44+
Type: schema.TypeList,
45+
Required: true,
46+
Elem: &schema.Schema{
47+
Type: schema.TypeString,
48+
ValidateFunc: validation.StringIsNotEmpty,
49+
},
50+
},
51+
"enabled": {
52+
Type: schema.TypeBool,
53+
Required: true,
54+
},
55+
},
56+
}
57+
}
58+
59+
func resourceSumologicCSEAutomationRead(d *schema.ResourceData, meta interface{}) error {
60+
c := meta.(*Client)
61+
62+
var CSEAutomation *CSEAutomation
63+
id := d.Id()
64+
65+
CSEAutomation, err := c.GetCSEAutomation(id)
66+
if err != nil {
67+
log.Printf("[WARN] CSE Custom Entity Type not found when looking by id: %s, err: %v", id, err)
68+
69+
}
70+
71+
if CSEAutomation == nil {
72+
log.Printf("[WARN] CSE Custom Entity Type not found, removing from state: %v - %v", id, err)
73+
d.SetId("")
74+
return nil
75+
}
76+
77+
d.Set("name", CSEAutomation.Name)
78+
d.Set("description", CSEAutomation.Description)
79+
d.Set("playbook_id", CSEAutomation.PlaybookId)
80+
d.Set("cse_resource_type", CSEAutomation.CseResourceType)
81+
d.Set("cse_resource_sub_types", CSEAutomation.CseResourceSubTypes)
82+
d.Set("execution_types", CSEAutomation.ExecutionTypes)
83+
d.Set("enabled", CSEAutomation.Enabled)
84+
85+
return nil
86+
}
87+
88+
func resourceSumologicCSEAutomationDelete(d *schema.ResourceData, meta interface{}) error {
89+
c := meta.(*Client)
90+
91+
return c.DeleteCSEAutomation(d.Id())
92+
93+
}
94+
95+
func resourceSumologicCSEAutomationCreate(d *schema.ResourceData, meta interface{}) error {
96+
c := meta.(*Client)
97+
98+
if d.Id() == "" {
99+
id, err := c.CreateCSEAutomation(CSEAutomation{
100+
PlaybookId: d.Get("playbook_id").(string),
101+
CseResourceType: d.Get("cse_resource_type").(string),
102+
CseResourceSubTypes: resourceFieldsToStringArray(d.Get("cse_resource_sub_types").([]interface{})),
103+
ExecutionTypes: resourceFieldsToStringArray(d.Get("execution_types").([]interface{})),
104+
Enabled: d.Get("enabled").(bool),
105+
})
106+
107+
if err != nil {
108+
return err
109+
}
110+
111+
d.SetId(id)
112+
}
113+
114+
return resourceSumologicCSEAutomationRead(d, meta)
115+
}
116+
117+
func resourceSumologicCSEAutomationUpdate(d *schema.ResourceData, meta interface{}) error {
118+
CSEAutomation, err := resourceToCSEAutomation(d)
119+
if err != nil {
120+
return err
121+
}
122+
123+
c := meta.(*Client)
124+
if err = c.UpdateCSEAutomation(CSEAutomation); err != nil {
125+
return err
126+
}
127+
128+
return resourceSumologicCSEAutomationRead(d, meta)
129+
}
130+
131+
func resourceToCSEAutomation(d *schema.ResourceData) (CSEAutomation, error) {
132+
id := d.Id()
133+
if id == "" {
134+
return CSEAutomation{}, nil
135+
}
136+
137+
return CSEAutomation{
138+
ID: id,
139+
Name: d.Get("name").(string),
140+
Description: d.Get("description").(string),
141+
PlaybookId: d.Get("playbook_id").(string),
142+
CseResourceType: d.Get("cse_resource_type").(string),
143+
CseResourceSubTypes: resourceFieldsToStringArray(d.Get("cse_resource_sub_types").([]interface{})),
144+
ExecutionTypes: resourceFieldsToStringArray(d.Get("execution_types").([]interface{})),
145+
Enabled: d.Get("enabled").(bool),
146+
}, nil
147+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package sumologic
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
9+
)
10+
11+
func TestAccSumologicSCEAutomation_create_update(t *testing.T) {
12+
SkipCseTest(t)
13+
14+
var Automation CSEAutomation
15+
nPlaybookId := "63ece953d5f0cb2ec4d5794e"
16+
nCseResourceType := "INSIGHT"
17+
nExecutionTypes := []string{"NEW_INSIGHT"}
18+
nEnabled := true
19+
uExecutionTypes := []string{"ON_DEMAND"}
20+
uEnabled := false
21+
resourceName := "sumologic_cse_automation.automation"
22+
resource.Test(t, resource.TestCase{
23+
PreCheck: func() { testAccPreCheck(t) },
24+
Providers: testAccProviders,
25+
CheckDestroy: testAccCSEAutomationDestroy,
26+
Steps: []resource.TestStep{
27+
{
28+
Config: testCreateCSEAutomationConfig(nPlaybookId, nCseResourceType, nExecutionTypes, nEnabled),
29+
Check: resource.ComposeTestCheckFunc(
30+
testCheckCSEAutomationExists(resourceName, &Automation),
31+
testCheckAutomationValues(&Automation, nPlaybookId, nCseResourceType, nExecutionTypes, nEnabled),
32+
resource.TestCheckResourceAttrSet(resourceName, "id"),
33+
),
34+
},
35+
{
36+
Config: testCreateCSEAutomationConfig(nPlaybookId, nCseResourceType, uExecutionTypes, uEnabled),
37+
Check: resource.ComposeTestCheckFunc(
38+
testCheckCSEAutomationExists(resourceName, &Automation),
39+
testCheckAutomationValues(&Automation, nPlaybookId, nCseResourceType, uExecutionTypes, uEnabled),
40+
),
41+
},
42+
},
43+
})
44+
}
45+
46+
func testAccCSEAutomationDestroy(s *terraform.State) error {
47+
client := testAccProvider.Meta().(*Client)
48+
49+
for _, rs := range s.RootModule().Resources {
50+
if rs.Type != "sumologic_cse_custom_entity_type" {
51+
continue
52+
}
53+
54+
if rs.Primary.ID == "" {
55+
return fmt.Errorf("CSE Custom Entity Type Config destruction check: CSE Custom Entity Type Config ID is not set")
56+
}
57+
58+
s, err := client.GetCSEAutomation(rs.Primary.ID)
59+
if err != nil {
60+
return fmt.Errorf("Encountered an error: " + err.Error())
61+
}
62+
if s != nil {
63+
return fmt.Errorf("entity Custom Entity Type still exists")
64+
}
65+
}
66+
return nil
67+
}
68+
69+
func testCreateCSEAutomationConfig(nPlaybookId string, nCseResourceType string, nExecutionTypes []string, nEnabled bool) string {
70+
71+
return fmt.Sprintf(`
72+
resource "sumologic_cse_automation" "automation" {
73+
playbook_id = "%s"
74+
cse_resource_type = "%s"
75+
execution_types = ["%s"]
76+
enabled = "%t"
77+
}
78+
`, nPlaybookId, nCseResourceType, nExecutionTypes[0], nEnabled)
79+
}
80+
81+
func testCheckCSEAutomationExists(n string, Automation *CSEAutomation) resource.TestCheckFunc {
82+
return func(s *terraform.State) error {
83+
rs, ok := s.RootModule().Resources[n]
84+
if !ok {
85+
return fmt.Errorf("not found: %s", n)
86+
}
87+
88+
if rs.Primary.ID == "" {
89+
return fmt.Errorf("entity Custom Entity Type ID is not set")
90+
}
91+
92+
c := testAccProvider.Meta().(*Client)
93+
AutomationResp, err := c.GetCSEAutomation(rs.Primary.ID)
94+
if err != nil {
95+
return err
96+
}
97+
98+
*Automation = *AutomationResp
99+
100+
return nil
101+
}
102+
}
103+
104+
func testCheckAutomationValues(Automation *CSEAutomation, nPlaybookId string, nCseResourceType string, nExecutionTypes []string, nEnabled bool) resource.TestCheckFunc {
105+
return func(s *terraform.State) error {
106+
if Automation.PlaybookId != nPlaybookId {
107+
return fmt.Errorf("bad playbook_id, expected \"%s\", got: %#v", nPlaybookId, Automation.PlaybookId)
108+
}
109+
if Automation.CseResourceType != nCseResourceType {
110+
return fmt.Errorf("bad cse_resource_type, expected \"%s\", got: %#v", nCseResourceType, Automation.CseResourceType)
111+
}
112+
if Automation.ExecutionTypes != nil {
113+
if len(Automation.ExecutionTypes) != len(nExecutionTypes) {
114+
return fmt.Errorf("bad execution_types list, expected \"%d\", got: %d", len(nExecutionTypes), len(Automation.ExecutionTypes))
115+
}
116+
if Automation.ExecutionTypes[0] != nExecutionTypes[0] {
117+
return fmt.Errorf("bad execution_types in list, expected \"%s\", got: %s", nExecutionTypes[0], Automation.ExecutionTypes[0])
118+
}
119+
}
120+
if Automation.Enabled != nEnabled {
121+
return fmt.Errorf("bad enabled field, expected \"%t\", got: %#v", nEnabled, Automation.Enabled)
122+
}
123+
124+
return nil
125+
}
126+
}

sumologic/resource_sumologic_dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func resourceSumologicDashboard() *schema.Resource {
7979
"refresh_interval": {
8080
Type: schema.TypeInt,
8181
Optional: true,
82-
ValidateFunc: validation.IntInSlice([]int{120, 300, 900, 1800, 3600, 7200, 86400}),
82+
ValidateFunc: validation.IntInSlice([]int{0, 30, 60, 120, 300, 900, 1800, 3600, 7200, 86400}),
8383
},
8484
"time_range": {
8585
Type: schema.TypeList,

sumologic/resource_sumologic_partition.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ func resourceSumologicPartition() *schema.Resource {
3030
ValidateFunc: validation.StringLenBetween(1, 16384),
3131
},
3232
"analytics_tier": {
33-
Type: schema.TypeString,
34-
Optional: true,
35-
ValidateFunc: validation.StringInSlice([]string{"continuous", "frequent", "infrequent"}, false),
36-
Default: "continuous",
33+
Type: schema.TypeString,
34+
Optional: true,
3735
},
3836
"retention_period": {
3937
Type: schema.TypeInt,

sumologic/resource_sumologic_partition_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ resource "sumologic_partition" "foo" {
9191
routing_expression = "_sourcecategory=*/Terraform"
9292
is_compliant = false
9393
retention_period = 30
94+
analytics_tier = "continuous"
9495
}
9596
`, testName)
9697
}
@@ -102,6 +103,7 @@ resource "sumologic_partition" "foo" {
102103
routing_expression = "_sourcecategory=*/Terraform"
103104
retention_period = 365
104105
is_compliant = false
106+
analytics_tier = "continuous"
105107
}
106108
`, testName)
107109
}

0 commit comments

Comments
 (0)