diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 89310bc1..7a99a8ba 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61366564..4679b9a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/sumologic/resource_sumologic_field.go b/sumologic/resource_sumologic_field.go index 93b973d7..e07cbe2a 100644 --- a/sumologic/resource_sumologic_field.go +++ b/sumologic/resource_sumologic_field.go @@ -1,6 +1,7 @@ package sumologic import ( + "errors" "fmt" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -10,6 +11,7 @@ func resourceSumologicField() *schema.Resource { return &schema.Resource{ Create: resourceSumologicFieldCreate, Read: resourceSumologicFieldRead, + Update: resourceSumologicFieldUpdate, Delete: resourceSumologicFieldDelete, Importer: &schema.ResourceImporter{ State: resourceSumologicFieldImport, @@ -38,7 +40,6 @@ func resourceSumologicField() *schema.Resource { "state": { Type: schema.TypeString, Optional: true, - ForceNew: true, }, }, } @@ -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), diff --git a/sumologic/resource_sumologic_field_test.go b/sumologic/resource_sumologic_field_test.go index b6e2eaa0..58b3145d 100644 --- a/sumologic/resource_sumologic_field_test.go +++ b/sumologic/resource_sumologic_field_test.go @@ -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) @@ -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( diff --git a/sumologic/sumologic_field.go b/sumologic/sumologic_field.go index c25b0594..5b542ec3 100644 --- a/sumologic/sumologic_field.go +++ b/sumologic/sumologic_field.go @@ -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"`