Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
FEATURES:
* **Updated sumologic_monitor resource:** Added support for automated playbooks in monitors
* **New Data Source:** sumologic_monitor_folder
* **Updated sumologic_extraction_rule resource:** Add computed `field_names` property

## 3.1.1 (July 8, 2025)

Expand Down
2 changes: 2 additions & 0 deletions sumologic/fields_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ var FieldsMap = map[string]map[string]string{
"scope": "_sourceHost=127.0.0.1",
"parseExpression": "csv _raw extract 1 as f1",
"enabled": "true",
"fieldNames": "f1",
"updatedName": "TestTestTestTerraformFERUpdated",
"updatedScope": "_sourceHost=127.0.0.1",
"updatedParseExpression": "csv _raw extract 1 as f1",
"updatedEnabled": "true",
"updatedFieldNames": "f1",
},

"IngestBudget": map[string]string{
Expand Down
7 changes: 7 additions & 0 deletions sumologic/resource_sumologic_extraction_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func resourceSumologicFieldExtractionRule() *schema.Resource {
Type: schema.TypeBool,
Required: true,
},
"field_names": {
Computed: true,
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand All @@ -77,6 +82,7 @@ func resourceSumologicFieldExtractionRuleRead(d *schema.ResourceData, meta inter
d.Set("scope", fieldextractionrule.Scope)
d.Set("parse_expression", fieldextractionrule.ParseExpression)
d.Set("enabled", fieldextractionrule.Enabled)
d.Set("field_names", fieldextractionrule.FieldNames)

return nil
}
Expand Down Expand Up @@ -125,5 +131,6 @@ func resourceToFieldExtractionRule(d *schema.ResourceData) FieldExtractionRule {
Scope: d.Get("scope").(string),
ParseExpression: d.Get("parse_expression").(string),
Enabled: d.Get("enabled").(bool),
FieldNames: resourceToStringArray(d.Get("field_names").([]interface{})),
}
}
7 changes: 7 additions & 0 deletions sumologic/resource_sumologic_extraction_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAccSumologicFieldExtractionRule_create(t *testing.T) {
testScope := FieldsMap["FieldExtractionRule"]["scope"]
testParseExpression := FieldsMap["FieldExtractionRule"]["parseExpression"]
testEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["enabled"])
testFieldName := FieldsMap["FieldExtractionRule"]["fieldNames"]
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -66,6 +67,7 @@ func TestAccSumologicFieldExtractionRule_create(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "scope", testScope),
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "parse_expression", testParseExpression),
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "enabled", strconv.FormatBool(testEnabled)),
resource.TestCheckTypeSetElemAttr("sumologic_field_extraction_rule.test", "field_names.*", testFieldName),
),
},
},
Expand Down Expand Up @@ -120,11 +122,13 @@ func TestAccSumologicFieldExtractionRule_update(t *testing.T) {
testScope := FieldsMap["FieldExtractionRule"]["scope"]
testParseExpression := FieldsMap["FieldExtractionRule"]["parseExpression"]
testEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["enabled"])
testFieldName := FieldsMap["FieldExtractionRule"]["fieldNames"]

testUpdatedName := FieldsMap["FieldExtractionRule"]["updatedName"] + randomSuffix
testUpdatedScope := FieldsMap["FieldExtractionRule"]["updatedScope"]
testUpdatedParseExpression := FieldsMap["FieldExtractionRule"]["updatedParseExpression"]
testUpdatedEnabled, _ := strconv.ParseBool(FieldsMap["FieldExtractionRule"]["updatedEnabled"])
testUpdatedFieldName := FieldsMap["FieldExtractionRule"]["updatedFieldNames"]

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -140,6 +144,7 @@ func TestAccSumologicFieldExtractionRule_update(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "scope", testScope),
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "parse_expression", testParseExpression),
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "enabled", strconv.FormatBool(testEnabled)),
resource.TestCheckTypeSetElemAttr("sumologic_field_extraction_rule.test", "field_names.*", testFieldName),
),
},
{
Expand All @@ -151,6 +156,7 @@ func TestAccSumologicFieldExtractionRule_update(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "scope", testUpdatedScope),
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "parse_expression", testUpdatedParseExpression),
resource.TestCheckResourceAttr("sumologic_field_extraction_rule.test", "enabled", strconv.FormatBool(testUpdatedEnabled)),
resource.TestCheckTypeSetElemAttr("sumologic_field_extraction_rule.test", "field_names.*", testUpdatedFieldName),
),
},
},
Expand Down Expand Up @@ -197,6 +203,7 @@ func testAccCheckFieldExtractionRuleAttributes(name string) resource.TestCheckFu
resource.TestCheckResourceAttrSet(name, "scope"),
resource.TestCheckResourceAttrSet(name, "parse_expression"),
resource.TestCheckResourceAttrSet(name, "enabled"),
resource.TestCheckResourceAttrSet(name, "field_names.#"),
)
return f(s)
}
Expand Down
5 changes: 4 additions & 1 deletion sumologic/sumologic_extraction_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func (s *Client) GetFieldExtractionRule(id string) (*FieldExtractionRule, error)

func (s *Client) UpdateFieldExtractionRule(fieldExtractionRule FieldExtractionRule) error {
url := fmt.Sprintf("v1/extractionRules/%s", fieldExtractionRule.ID)

var empty_fields []string
fieldExtractionRule.ID = ""
fieldExtractionRule.FieldNames = empty_fields

_, err := s.Put(url, fieldExtractionRule)
return err
Expand All @@ -73,4 +74,6 @@ type FieldExtractionRule struct {
ParseExpression string `json:"parseExpression"`
// Is the field extraction rule enabled.
Enabled bool `json:"enabled"`
// Field names extracted by the rule
FieldNames []string `json:"fieldNames,omitempty"`
}
2 changes: 2 additions & 0 deletions website/docs/r/field_extraction_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The following arguments are supported:
The following attributes are exported:

- `id` - Unique identifier for the field extraction rule.
- `field_names` - (computed after creation) identifiers projected from the field extraction rule.


## Import
Extraction Rules can be imported using the extraction rule id, e.g.:
Expand Down
Loading