Skip to content

Commit bcf86f3

Browse files
Merge pull request #674 from SumoLogic/rs-add-is-included-in-default-search-in-partitions
Add IsIncludedInDefaultSearch field to partition resource
2 parents 54e505b + 2130f6b commit bcf86f3

8 files changed

+54
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## 2.31.2 (Unreleased)
2+
ENHANCEMENTS:
3+
* Add IsIncludedInDefaultSearch field to partition resource (GH-674)
24
BUG FIXES:
35
* Fix cse_log_mappings resource conversion affecting import (GH-675)
46

sumologic/resource_sumologic_cse_match_rule_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"regexp"
66
"testing"
77

8+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
89
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
910
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1011
)
@@ -19,15 +20,15 @@ func TestAccSumologicCSEMatchRule_createAndUpdate(t *testing.T) {
1920
entitySelectorExpression := "srcDevice_ip"
2021
expression := "foo = bar"
2122
isPrototype := false
22-
name := "Test Match Rule"
23+
name := acctest.RandomWithPrefix("Test Match Rule")
2324
nameExpression := "Signal Name"
2425
severityMappingType := "constant"
2526
severityMappingDefault := 5
2627
summaryExpression := "Signal Summary"
2728
tag := "foo"
2829
suppressionWindowSize := 24 * 60 * 60 * 1000
2930

30-
nameUpdated := "Updated Match Rule"
31+
nameUpdated := acctest.RandomWithPrefix("Updated Match Rule")
3132
tagUpdated := "bar"
3233
suppressionWindowSizeUpdated := 25 * 60 * 60 * 1000
3334

@@ -83,7 +84,7 @@ func TestAccSumologicCSEMatchRule_failSuppressionValidation(t *testing.T) {
8384
entitySelectorExpression := "srcDevice_ip"
8485
expression := "foo = bar"
8586
isPrototype := false
86-
name := "Test Match Rule"
87+
name := acctest.RandomWithPrefix("Test Match Rule")
8788
nameExpression := "Signal Name"
8889
severityMappingType := "constant"
8990
severityMappingDefault := 5

sumologic/resource_sumologic_cse_network_block_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package sumologic
22

33
import (
44
"fmt"
5+
"math/rand"
6+
"net"
57
"testing"
68

79
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -12,7 +14,7 @@ func TestAccSumologicSCENetworkBlock_create(t *testing.T) {
1214
SkipCseTest(t)
1315

1416
var networkBlock CSENetworkBlock
15-
nAddressBlock := "10.0.1.0/26"
17+
nAddressBlock := generateRandomCIDRBlock()
1618
nLabel := "network block test"
1719
nInternal := true
1820
nSuppressesSignals := false
@@ -112,3 +114,13 @@ func testCheckNetworkBlockValues(networkBlock *CSENetworkBlock, nAddressBlock st
112114
return nil
113115
}
114116
}
117+
118+
func generateRandomCIDRBlock() string {
119+
ip := make(net.IP, 4)
120+
for i := 0; i < 3; i++ {
121+
ip[i] = byte(rand.Intn(256))
122+
}
123+
ip[3] = 0
124+
125+
return ip.String() + "/26"
126+
}

sumologic/resource_sumologic_cse_rule_tuning_expression_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"testing"
77

8+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
89
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
910
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1011
"github.com/stretchr/testify/assert"
@@ -14,7 +15,7 @@ func TestAccSumologicSCERuleTuningExpression_create(t *testing.T) {
1415
SkipCseTest(t)
1516

1617
var ruleTuningExpression CSERuleTuningExpression
17-
nName := "New Rule Tuning Name"
18+
nName := acctest.RandomWithPrefix("New Rule Tuning Name")
1819
nDescription := "New Rule Tuning Description"
1920
nExpression := "expression"
2021
nEnabled := true

sumologic/resource_sumologic_extraction_rule_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import (
1717
"strings"
1818
"testing"
1919

20+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
2021
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
2122
"github.com/hashicorp/terraform-plugin-sdk/terraform"
2223
)
2324

2425
func TestAccSumologicFieldExtractionRule_basic(t *testing.T) {
2526
var fieldextractionrule FieldExtractionRule
26-
testName := FieldsMap["FieldExtractionRule"]["name"]
27+
testName := FieldsMap["FieldExtractionRule"]["name"] + acctest.RandString(8)
2728
testScope := FieldsMap["FieldExtractionRule"]["scope"]
2829
testParseExpression := FieldsMap["FieldExtractionRule"]["parseExpression"]
2930
testEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["enabled"])
@@ -47,7 +48,7 @@ func TestAccSumologicFieldExtractionRule_basic(t *testing.T) {
4748

4849
func TestAccSumologicFieldExtractionRule_create(t *testing.T) {
4950
var fieldextractionrule FieldExtractionRule
50-
testName := FieldsMap["FieldExtractionRule"]["name"]
51+
testName := FieldsMap["FieldExtractionRule"]["name"] + acctest.RandString(8)
5152
testScope := FieldsMap["FieldExtractionRule"]["scope"]
5253
testParseExpression := FieldsMap["FieldExtractionRule"]["parseExpression"]
5354
testEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["enabled"])
@@ -114,12 +115,13 @@ func testAccCheckFieldExtractionRuleExists(name string, fieldextractionrule *Fie
114115

115116
func TestAccSumologicFieldExtractionRule_update(t *testing.T) {
116117
var fieldextractionrule FieldExtractionRule
117-
testName := FieldsMap["FieldExtractionRule"]["name"]
118+
randomSuffix := acctest.RandString(8)
119+
testName := FieldsMap["FieldExtractionRule"]["name"] + randomSuffix
118120
testScope := FieldsMap["FieldExtractionRule"]["scope"]
119121
testParseExpression := FieldsMap["FieldExtractionRule"]["parseExpression"]
120122
testEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["enabled"])
121123

122-
testUpdatedName := FieldsMap["FieldExtractionRule"]["updatedName"]
124+
testUpdatedName := FieldsMap["FieldExtractionRule"]["updatedName"] + randomSuffix
123125
testUpdatedScope := FieldsMap["FieldExtractionRule"]["updatedScope"]
124126
testUpdatedParseExpression := FieldsMap["FieldExtractionRule"]["updatedParseExpression"]
125127
testUpdatedEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["updatedEnabled"])

sumologic/resource_sumologic_partition.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func resourceSumologicPartition() *schema.Resource {
6767
Type: schema.TypeBool,
6868
Optional: true,
6969
},
70+
"is_included_in_default_search": {
71+
Type: schema.TypeBool,
72+
Description: "Indicates whether the partition is included in the default search scope. Configuring this property is exclusively permitted for flex partitions.",
73+
Optional: true,
74+
Default: true,
75+
},
7076
},
7177
}
7278
}
@@ -84,7 +90,7 @@ func resourceSumologicPartitionCreate(d *schema.ResourceData, meta interface{})
8490
d.SetId(createdSpartition.ID)
8591
}
8692

87-
return resourceSumologicPartitionUpdate(d, meta)
93+
return resourceSumologicPartitionRead(d, meta)
8894
}
8995

9096
func resourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) error {
@@ -113,6 +119,7 @@ func resourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) er
113119
d.Set("is_active", spartition.IsActive)
114120
d.Set("total_bytes", spartition.TotalBytes)
115121
d.Set("index_type", spartition.IndexType)
122+
d.Set("is_included_in_default_search", spartition.IsIncludedInDefaultSearch)
116123

117124
return nil
118125
}
@@ -134,17 +141,30 @@ func resourceSumologicPartitionUpdate(d *schema.ResourceData, meta interface{})
134141
}
135142

136143
func resourceToPartition(d *schema.ResourceData) Partition {
144+
145+
analyticsTier := d.Get("analytics_tier").(string)
146+
isIncludedInDefaultSearch := d.Get("is_included_in_default_search").(bool)
147+
148+
var isIncludedInDefaultSearchPtr *bool
149+
if analyticsTier == "flex" || analyticsTier == "" {
150+
isIncludedInDefaultSearchPtr = new(bool)
151+
*isIncludedInDefaultSearchPtr = isIncludedInDefaultSearch
152+
} else {
153+
isIncludedInDefaultSearchPtr = nil
154+
}
155+
137156
return Partition{
138157
ID: d.Id(),
139158
Name: d.Get("name").(string),
140159
RoutingExpression: d.Get("routing_expression").(string),
141-
AnalyticsTier: d.Get("analytics_tier").(string),
160+
AnalyticsTier: analyticsTier,
142161
RetentionPeriod: d.Get("retention_period").(int),
143162
IsCompliant: d.Get("is_compliant").(bool),
144163
DataForwardingId: d.Get("data_forwarding_id").(string),
145164
IsActive: d.Get("is_active").(bool),
146165
TotalBytes: d.Get("total_bytes").(int),
147166
IndexType: d.Get("index_type").(string),
148167
ReduceRetentionPeriodImmediately: d.Get("reduce_retention_period_immediately").(bool),
168+
IsIncludedInDefaultSearch: isIncludedInDefaultSearchPtr,
149169
}
150170
}

sumologic/sumologic_partition.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (s *Client) GetPartition(id string) (*Partition, error) {
2626
err = json.Unmarshal(data, &spartition)
2727
if err != nil {
2828
return nil, err
29-
} else if spartition.IsActive == false {
29+
} else if !spartition.IsActive {
3030
return nil, nil
3131
}
3232

@@ -75,4 +75,5 @@ type Partition struct {
7575
TotalBytes int `json:"totalBytes"`
7676
IndexType string `json:"indexType"`
7777
ReduceRetentionPeriodImmediately bool `json:"reduceRetentionPeriodImmediately,omitempty"`
78+
IsIncludedInDefaultSearch *bool `json:"isIncludedInDefaultSearch,omitempty"`
7879
}

website/docs/r/partition.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resource "sumologic_partition" "examplePartition" {
1515
routing_expression = "_sourcecategory=*/Terraform"
1616
analytics_tier = "continuous"
1717
is_compliant = false
18+
is_included_in_default_search = true
1819
lifecycle {
1920
prevent_destroy = true
2021
}
@@ -27,10 +28,11 @@ The following arguments are supported:
2728

2829
- `name` - (Required, Forces new resource) The name of the partition.
2930
- `routing_expression` - (Required) The query that defines the data to be included in the partition.
30-
- `analytics_tier` - (Optional) The cloud flex analytics tier for your data; only relevant if your account has basic analytics enabled. If no value is supplied, partition will be created in continuous tier. Other possible values are : "frequent" and "infrequent".
31+
- `analytics_tier` - (Optional) The cloud flex analytics tier for your data; only relevant if your account has basic analytics enabled. If no value is supplied, partition will be created in continuous tier. Other possible values are : "frequent" and "infrequent". For flex partition, you can leave it empty or send flex.
3132
- `retention_period` - (Optional) The number of days to retain data in the partition, or -1 to use the default value for your account. Only relevant if your account has variable retention enabled.
3233
- `is_compliant` - (Optional) Whether the partition is compliant or not. Mark a partition as compliant if it contains data used for compliance or audit purpose. Retention for a compliant partition can only be increased and cannot be reduced after the partition is marked compliant. A partition once marked compliant, cannot be marked non-compliant later.
3334
- `reduce_retention_period_immediately` - (Optional) This is required on update if the newly specified retention period is less than the existing retention period. In such a situation, a value of true says that data between the existing retention period and the new retention period should be deleted immediately; if false, such data will be deleted after seven days. This property is optional and ignored if the specified retentionPeriod is greater than or equal to the current retention period.
35+
- `is_included_in_default_search` - Indicates whether the partition is included in the default search scope. When executing a query such as "error | count," certain partitions are automatically part of the search scope. However, for specific partitions, the user must explicitly mention the partition using the _index term, as in "_index=webApp error | count". This property governs the default inclusion of the partition in the search scope. Configuring this property is exclusively permitted for flex partitions.
3436

3537
## Attributes reference
3638

0 commit comments

Comments
 (0)