Skip to content

Commit

Permalink
SUMO-245309 Resolve the merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
yuting-liu committed Jan 13, 2025
2 parents 9d5d99d + 69d8e42 commit 9606f54
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 6 deletions.
9 changes: 4 additions & 5 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @sumovishal, @dagould will be requested for
# review when someone opens a pull request.
* @sumovishal @dagould
# the repo. Unless a later match takes precedence, they will
# be requested for review when someone opens a pull request.
* @SumoLogic/tf-platform-team

# Code owners for collection sources
/sumologic/*_source.go @maimaisie @vsinghal13
/sumologic/*_source_test.go @maimaisie @vsinghal13
/sumologic/*_ingest_budget* @maimaisie @vsinghal13
/sumologic/*_collector* @maimaisie @vsinghal13
/sumologic/*_cse* @josh-williams @pmontiel-sumo
/sumologic/*_cse* @pmontiel-sumo
/website/docs/r/collector* @maimaisie @vsinghal13
/website/docs/r/ingest_* @maimaisie @vsinghal13
/website/docs/r/*_source* @maimaisie @vsinghal13
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ jobs:
SUMOLOGIC_TEST_ROLE_ARN: ${{ secrets.SUMOLOGIC_TEST_ROLE_ARN }}
SUMOLOGIC_TEST_SAS_KEY: ${{ secrets.SUMOLOGIC_TEST_SAS_KEY }}
SUMOLOGIC_TEST_SAS_KEY_NAME: ${{ secrets.SUMOLOGIC_TEST_SAS_KEY_NAME }}
SUMOLOGIC_DATA_FORWARDING_BUCKET: ${{ secrets.SUMOLOGIC_DATA_FORWARDING_BUCKET }}
SUMOLOGIC_DATA_FORWARDING_ROLE_ARN: ${{ secrets.SUMOLOGIC_DATA_FORWARDING_ROLE_ARN }}
SUMOLOGIC_DATA_FORWARDING_AWS_REGION: ${{ secrets.SUMOLOGIC_DATA_FORWARDING_AWS_REGION }}
SUMOLOGIC_TEST_AZURE_TENANT_ID: ${{ secrets.SUMOLOGIC_TEST_AZURE_TENANT_ID }}
SUMOLOGIC_TEST_AZURE_CLIENT_ID: ${{ secrets.SUMOLOGIC_TEST_AZURE_CLIENT_ID }}
SUMOLOGIC_TEST_AZURE_CLIENT_SECRET: ${{ secrets.SUMOLOGIC_TEST_AZURE_CLIENT_SECRET }}
Expand Down
40 changes: 39 additions & 1 deletion sumologic/resource_sumologic_field.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sumologic

import (
"errors"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -10,6 +11,7 @@ func resourceSumologicField() *schema.Resource {
return &schema.Resource{
Create: resourceSumologicFieldCreate,
Read: resourceSumologicFieldRead,
Update: resourceSumologicFieldUpdate,
Delete: resourceSumologicFieldDelete,
Importer: &schema.ResourceImporter{
State: resourceSumologicFieldImport,
Expand Down Expand Up @@ -38,7 +40,6 @@ func resourceSumologicField() *schema.Resource {
"state": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
Expand Down Expand Up @@ -116,6 +117,43 @@ func resourceSumologicFieldImport(d *schema.ResourceData, meta interface{}) ([]*
return []*schema.ResourceData{d}, nil
}

func resourceSumologicFieldUpdate(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

id := d.Get("field_id").(string)
name := d.Get("field_name").(string)
state := d.Get("state").(string)
if id == "" {
newId, err := c.FindFieldId(name)
if err != nil {
return err
}
id = newId
}
_, err := c.GetField(id)

if err != nil {
return err
}

if state == "Enabled" {
err := c.EnableField(id)
if err != nil {
return err
}
} else if state == "Disabled" {
err := c.DisableField(id)
if err != nil {
return err
}
} else {
return errors.New("Invalid value of state field. Only Enabled or Disabled values are accepted")
}

return resourceSumologicFieldRead(d, meta)

}

func resourceToField(d *schema.ResourceData) Field {
return Field{
DataType: d.Get("data_type").(string),
Expand Down
45 changes: 45 additions & 0 deletions sumologic/resource_sumologic_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,41 @@ func TestAccSumologicField_create(t *testing.T) {
})
}

func TestAccSumologicField_update(t *testing.T) {
var field Field
testFieldName := "fields_provider_test"
testDataType := "String"
testState := "Enabled"
updatedState := "Disabled"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFieldDestroy(field),
Steps: []resource.TestStep{
{
Config: testAccSumologicField(testFieldName, testDataType, testState),
Check: resource.ComposeTestCheckFunc(
testAccCheckFieldExists("sumologic_field.test", &field, t),
testAccCheckFieldAttributes("sumologic_field.test"),
resource.TestCheckResourceAttr("sumologic_field.test", "field_name", testFieldName),
resource.TestCheckResourceAttr("sumologic_field.test", "data_type", testDataType),
resource.TestCheckResourceAttr("sumologic_field.test", "state", testState),
),
},
{
Config: testAccSumologicFieldUpdate(testFieldName, testDataType, updatedState),
Check: resource.ComposeTestCheckFunc(
testAccCheckFieldExists("sumologic_field.test", &field, t),
testAccCheckFieldAttributes("sumologic_field.test"),
resource.TestCheckResourceAttr("sumologic_field.test", "field_name", testFieldName),
resource.TestCheckResourceAttr("sumologic_field.test", "data_type", testDataType),
resource.TestCheckResourceAttr("sumologic_field.test", "state", updatedState),
),
},
},
})
}

func testAccCheckFieldDestroy(field Field) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*Client)
Expand Down Expand Up @@ -116,6 +151,16 @@ resource "sumologic_field" "test" {
`, fieldName, dataType, state)
}

func testAccSumologicFieldUpdate(fieldName string, dataType string, state string) string {
return fmt.Sprintf(`
resource "sumologic_field" "test" {
field_name = "%s"
data_type = "%s"
state = "%s"
}
`, fieldName, dataType, state)
}

func testAccCheckFieldAttributes(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
f := resource.ComposeTestCheckFunc(
Expand Down
14 changes: 14 additions & 0 deletions sumologic/sumologic_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ func (s *Client) FindFieldId(name string) (string, error) {
return "", fmt.Errorf("Field \"%s\" not found", name)
}

func (s *Client) DisableField(id string) error {
urlWithParams := fmt.Sprintf("v1/fields/%s/disable", id)

_, err := s.Delete(urlWithParams)
return err
}

func (s *Client) EnableField(id string) error {
urlWithParams := fmt.Sprintf("v1/fields/%s/enable", id)

_, err := s.Put(urlWithParams, nil)
return err
}

type Field struct {
FieldId string `json:"fieldId"`
DataType string `json:"dataType"`
Expand Down

0 comments on commit 9606f54

Please sign in to comment.