Skip to content

Commit

Permalink
Merge pull request #555 from SumoLogic/vsinghal-fix-s3-use-versioned-api
Browse files Browse the repository at this point in the history
set default value for use_versioned_api param to true
  • Loading branch information
sumovishal authored Aug 3, 2023
2 parents 91d5673 + cbc2c78 commit 48bb426
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 10 additions & 1 deletion sumologic/resource_sumologic_generic_polling_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ func resourceSumologicGenericPollingSource() *schema.Resource {
"use_versioned_api": {
Type: schema.TypeBool,
Optional: true,
Default: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
contentType := d.Get("content_type").(string)
if contentType != "AwsS3Bucket" {
return true
}
return false
},
},
"path_expression": {
Type: schema.TypeString,
Expand Down Expand Up @@ -578,7 +586,8 @@ func getPollingPathSettings(d *schema.ResourceData) (PollingPath, error) {
pathSettings.BucketName = path["bucket_name"].(string)
pathSettings.PathExpression = path["path_expression"].(string)
if path["use_versioned_api"] != nil {
pathSettings.UseVersionedApi = path["use_versioned_api"].(bool)
val := path["use_versioned_api"].(bool)
pathSettings.UseVersionedApi = &val
}
pathSettings.SnsTopicOrSubscriptionArn = getPollingSnsTopicOrSubscriptionArn(d)
case "CloudWatchPath", "AwsInventoryPath":
Expand Down
17 changes: 12 additions & 5 deletions sumologic/resource_sumologic_s3_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ func TestAccSumologicS3Source_create(t *testing.T) {
s3ResourceName := "sumologic_s3_source.s3"
testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN")
testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME")
useVersionedApi := true
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckWithAWS(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckS3SourceDestroy,
Steps: []resource.TestStep{
{
Config: testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket),
Config: testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket, useVersionedApi),
Check: resource.ComposeTestCheckFunc(
testAccCheckS3SourceExists(s3ResourceName, &s3Source),
testAccCheckS3SourceValues(&s3Source, sName, sDescription, sCategory),
Expand All @@ -43,6 +44,7 @@ func TestAccSumologicS3Source_create(t *testing.T) {
resource.TestCheckResourceAttr(s3ResourceName, "category", sCategory),
resource.TestCheckResourceAttr(s3ResourceName, "content_type", "AwsS3Bucket"),
resource.TestCheckResourceAttr(s3ResourceName, "path.0.type", "S3BucketPathExpression"),
resource.TestCheckResourceAttr(s3ResourceName, "path.0.use_versioned_api", "true"),
),
},
},
Expand All @@ -56,13 +58,15 @@ func TestAccSumologicS3Source_update(t *testing.T) {
s3ResourceName := "sumologic_s3_source.s3"
testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN")
testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME")
useVersionedApi := true
useVersionedApiUpdated := false
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckWithAWS(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHTTPSourceDestroy,
Steps: []resource.TestStep{
{
Config: testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket),
Config: testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket, useVersionedApi),
Check: resource.ComposeTestCheckFunc(
testAccCheckS3SourceExists(s3ResourceName, &s3Source),
testAccCheckS3SourceValues(&s3Source, sName, sDescription, sCategory),
Expand All @@ -72,10 +76,11 @@ func TestAccSumologicS3Source_update(t *testing.T) {
resource.TestCheckResourceAttr(s3ResourceName, "category", sCategory),
resource.TestCheckResourceAttr(s3ResourceName, "content_type", "AwsS3Bucket"),
resource.TestCheckResourceAttr(s3ResourceName, "path.0.type", "S3BucketPathExpression"),
resource.TestCheckResourceAttr(s3ResourceName, "path.0.use_versioned_api", "true"),
),
},
{
Config: testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testAwsRoleArn, testAwsBucket),
Config: testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testAwsRoleArn, testAwsBucket, useVersionedApiUpdated),
Check: resource.ComposeTestCheckFunc(
testAccCheckS3SourceExists(s3ResourceName, &s3Source),
testAccCheckS3SourceValues(&s3Source, sNameUpdated, sDescriptionUpdated, sCategoryUpdated),
Expand All @@ -85,6 +90,7 @@ func TestAccSumologicS3Source_update(t *testing.T) {
resource.TestCheckResourceAttr(s3ResourceName, "category", sCategoryUpdated),
resource.TestCheckResourceAttr(s3ResourceName, "content_type", "AwsS3Bucket"),
resource.TestCheckResourceAttr(s3ResourceName, "path.0.type", "S3BucketPathExpression"),
resource.TestCheckResourceAttr(s3ResourceName, "path.0.use_versioned_api", "false"),
),
},
},
Expand Down Expand Up @@ -157,7 +163,7 @@ func testAccCheckS3SourceValues(pollingSource *PollingSource, name, description,
return nil
}
}
func testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket string) string {
func testAccSumologicS3SourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket string, useVersionedApi bool) string {
return fmt.Sprintf(`
resource "sumologic_collector" "test" {
name = "%s"
Expand All @@ -180,8 +186,9 @@ resource "sumologic_s3_source" "s3" {
type = "S3BucketPathExpression"
bucket_name = "%s"
path_expression = "*"
use_versioned_api = "%v"
}
}
`, cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket)
`, cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket, useVersionedApi)
}
2 changes: 1 addition & 1 deletion sumologic/sumologic_polling_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type PollingPath struct {
CustomServices []string `json:"customServices,omitempty"`
TagFilters []TagFilter `json:"tagFilters,omitempty"`
SnsTopicOrSubscriptionArn PollingSnsTopicOrSubscriptionArn `json:"snsTopicOrSubscriptionArn,omitempty"`
UseVersionedApi bool `json:"useVersionedApi,omitempty"`
UseVersionedApi *bool `json:"useVersionedApi,omitempty"`
}

type TagFilter struct {
Expand Down

0 comments on commit 48bb426

Please sign in to comment.