Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INVS-1778: Request custom target column names to determine match list state when appropriate #591

Merged
merged 4 commits into from
Nov 14, 2023
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 2.27.1 (Unreleased)
## 2.27.1 (November 14, 2023)
BUG FIXES:
* Fixes `resource_sumologic_cse_match_list` constant change when defining a match list containing a custom column using the custom columns name instead of ID (GH-591)

## 2.27.0 (September 28, 2023)
FEATURES:
Expand Down
7 changes: 6 additions & 1 deletion sumologic/resource_sumologic_cse_match_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sumologic
import (
"fmt"
"log"
"regexp"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -93,7 +94,11 @@ func resourceSumologicCSEMatchListRead(d *schema.ResourceData, meta interface{})
var CSEMatchList *CSEMatchListGet
id := d.Id()

CSEMatchList, err := c.GetCSEMatchList(id)
// Determine whether the target column is defined using its ID or its name
definedTargetColumnIsId, _ := regexp.MatchString("^-?[0-9]*$", d.Get("target_column").(string))
definedTargetColumnIsName := !definedTargetColumnIsId

CSEMatchList, err := c.GetCSEMatchList(id, definedTargetColumnIsName)
if err != nil {
log.Printf("[WARN] CSE Match List not found when looking by id: %s, err: %v", id, err)

Expand Down
5 changes: 3 additions & 2 deletions sumologic/resource_sumologic_cse_match_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func testAccCSEMatchListDestroy(s *terraform.State) error {
return fmt.Errorf("CSE Match List destruction check: CSE Match List ID is not set")
}

s, err := client.GetCSEMatchList(rs.Primary.ID)
s, err := client.GetCSEMatchList(rs.Primary.ID, false)
if err != nil {
return fmt.Errorf("Encountered an error: " + err.Error())
}
Expand Down Expand Up @@ -136,7 +136,8 @@ func testCheckCSEMatchListExists(n string, matchList *CSEMatchListGet) resource.
return fmt.Errorf("match List ID is not set")
}
c := testAccProvider.Meta().(*Client)
matchListResp, err := c.GetCSEMatchList(rs.Primary.ID)

matchListResp, err := c.GetCSEMatchList(rs.Primary.ID, false)
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions sumologic/resource_sumologic_cse_outlier_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package sumologic
import (
"bytes"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/stretchr/testify/assert"
"strings"
"testing"
"text/template"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/stretchr/testify/assert"
)

func TestAccSumologicCSEOutlierRule_createAndUpdate(t *testing.T) {
Expand All @@ -27,7 +29,7 @@ func TestAccSumologicCSEOutlierRule_createAndUpdate(t *testing.T) {
GroupByFields: []string{"user_username"},
IsPrototype: false,
MatchExpression: `objectType="Network"`,
Name: "OutlierRuleTerraformTest",
Name: fmt.Sprintf("OutlierRuleTerraformTest %s", uuid.New()),
NameExpression: "OutlierRuleTerraformTest - {{ user_username }}",
RetentionWindowSize: "1209600000",
Severity: 1,
Expand Down
25 changes: 16 additions & 9 deletions sumologic/resource_sumologic_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strings"
"testing"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
Expand Down Expand Up @@ -164,11 +165,13 @@ func TestAccSumologicUser_update(t *testing.T) {
}

func testAccCheckSumologicUserConfigImported(firstName string, lastName string, email string, isActive bool, transferTo string) string {
testUuid := uuid.New()

return fmt.Sprintf(`
resource "sumologic_role" "testRole" {
name = "testRole Name"
name = "testRole Name %s"
capabilities = []
description = "testRole Description"
description = "testRole Description %s"
filter_predicate = ""
}
resource "sumologic_user" "foo" {
Expand All @@ -179,15 +182,17 @@ resource "sumologic_user" "foo" {
is_active = %t
transfer_to = "%s"
}
`, firstName, lastName, email, isActive, transferTo)
`, testUuid, testUuid, firstName, lastName, email, isActive, transferTo)
}

func testAccSumologicUser(firstName string, lastName string, email string, isActive bool, transferTo string) string {
testUuid := uuid.New()

return fmt.Sprintf(`
resource "sumologic_role" "testRole" {
name = "testRole Name"
name = "testRole Name %s"
capabilities = []
description = "testRole Description"
description = "testRole Description %s"
filter_predicate = ""
}
resource "sumologic_user" "test" {
Expand All @@ -198,15 +203,17 @@ resource "sumologic_user" "test" {
is_active = %t
transfer_to = "%s"
}
`, firstName, lastName, email, isActive, transferTo)
`, testUuid, testUuid, firstName, lastName, email, isActive, transferTo)
}

func testAccSumologicUserUpdate(firstName string, lastName string, email string, isActive bool, transferTo string) string {
testUuid := uuid.New()

return fmt.Sprintf(`
resource "sumologic_role" "testRole" {
name = "testRole Name"
name = "testRole Name %s"
capabilities = []
description = "testRole Description"
description = "testRole Description %s"
filter_predicate = ""
}
resource "sumologic_user" "test" {
Expand All @@ -217,7 +224,7 @@ resource "sumologic_user" "test" {
is_active = %t
transfer_to = "%s"
}
`, firstName, lastName, email, isActive, transferTo)
`, testUuid, testUuid, firstName, lastName, email, isActive, transferTo)
}

func testAccCheckUserAttributes(name string) resource.TestCheckFunc {
Expand Down
4 changes: 2 additions & 2 deletions sumologic/sumologic_cse_match_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
)

func (s *Client) GetCSEMatchList(id string) (*CSEMatchListGet, error) {
data, _, err := s.Get(fmt.Sprintf("sec/v1/match-lists/%s", id))
func (s *Client) GetCSEMatchList(id string, getCustomTargetColumnName bool) (*CSEMatchListGet, error) {
data, _, err := s.Get(fmt.Sprintf("sec/v1/match-lists/%s?getTargetCustomColumnName=%t", id, getCustomTargetColumnName))
if err != nil {
return nil, err
}
Expand Down
Loading