Skip to content

Commit e4c79b4

Browse files
authored
Merge pull request #524 from SumoLogic/vsinghal-add-support-for-archive-source
add new resource for S3 Archive source
2 parents 65d4aa6 + b34869c commit e4c79b4

File tree

5 files changed

+270
-1
lines changed

5 files changed

+270
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 2.23.0 (Unreleased)
22
FEATURES:
33
* **New Resource:** sumologic_log_search (GH-432)
4+
* **New Resource:** sumologic_s3_archive_source (GH-524)
5+
46
BUG FIXES:
57
* Enforce validation of `inventory_type` for sumologic_cse_inventory_entity_group_configuration ( fix documentation too ) (GH-521)
68

sumologic/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func Provider() terraform.ResourceProvider {
7070
"sumologic_polling_source": resourceSumologicPollingSource(),
7171
"sumologic_s3_source": resourceSumologicGenericPollingSource(),
7272
"sumologic_s3_audit_source": resourceSumologicGenericPollingSource(),
73+
"sumologic_s3_archive_source": resourceSumologicGenericPollingSource(),
7374
"sumologic_cloudwatch_source": resourceSumologicGenericPollingSource(),
7475
"sumologic_aws_inventory_source": resourceSumologicGenericPollingSource(),
7576
"sumologic_aws_xray_source": resourceSumologicGenericPollingSource(),

sumologic/resource_sumologic_generic_polling_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func resourceSumologicGenericPollingSource() *schema.Resource {
2525
Required: true,
2626
ForceNew: true,
2727
ValidateFunc: validation.StringInSlice([]string{"AwsS3Bucket", "AwsElbBucket", "AwsCloudFrontBucket",
28-
"AwsCloudTrailBucket", "AwsS3AuditBucket", "AwsCloudWatch", "AwsInventory", "AwsXRay", "GcpMetrics"}, false),
28+
"AwsCloudTrailBucket", "AwsS3AuditBucket", "AwsCloudWatch", "AwsInventory", "AwsXRay", "GcpMetrics", "AwsS3ArchiveBucket"}, false),
2929
}
3030
pollingSource.Schema["scan_interval"] = &schema.Schema{
3131
Type: schema.TypeInt,
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
package sumologic
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strconv"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
11+
)
12+
13+
func TestAccSumologicS3ArchiveSource_create(t *testing.T) {
14+
var s3Source PollingSource
15+
var collector Collector
16+
cName, cDescription, cCategory := getRandomizedParams()
17+
sName, sDescription, sCategory := getRandomizedParams()
18+
s3ResourceName := "sumologic_s3_archive_source.s3_archive"
19+
testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN")
20+
testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME")
21+
resource.Test(t, resource.TestCase{
22+
PreCheck: func() { testAccPreCheckWithAWS(t) },
23+
Providers: testAccProviders,
24+
CheckDestroy: testAccCheckS3ArchiveSourceDestroy,
25+
Steps: []resource.TestStep{
26+
{
27+
Config: testAccSumologicS3ArchiveSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket),
28+
Check: resource.ComposeTestCheckFunc(
29+
testAccCheckS3SourceExists(s3ResourceName, &s3Source),
30+
testAccCheckS3SourceValues(&s3Source, sName, sDescription, sCategory),
31+
testAccCheckCollectorExists("sumologic_collector.test", &collector),
32+
testAccCheckCollectorValues(&collector, cName, cDescription, cCategory, "Etc/UTC", ""),
33+
resource.TestCheckResourceAttrSet(s3ResourceName, "id"),
34+
resource.TestCheckResourceAttr(s3ResourceName, "name", sName),
35+
resource.TestCheckResourceAttr(s3ResourceName, "description", sDescription),
36+
resource.TestCheckResourceAttr(s3ResourceName, "category", sCategory),
37+
resource.TestCheckResourceAttr(s3ResourceName, "content_type", "AwsS3ArchiveBucket"),
38+
resource.TestCheckResourceAttr(s3ResourceName, "path.0.type", "S3BucketPathExpression"),
39+
),
40+
},
41+
},
42+
})
43+
}
44+
func TestAccSumologicS3ArchiveSource_update(t *testing.T) {
45+
var s3Source PollingSource
46+
cName, cDescription, cCategory := getRandomizedParams()
47+
sName, sDescription, sCategory := getRandomizedParams()
48+
sNameUpdated, sDescriptionUpdated, sCategoryUpdated := getRandomizedParams()
49+
s3ResourceName := "sumologic_s3_archive_source.s3_archive"
50+
testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN")
51+
testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME")
52+
resource.Test(t, resource.TestCase{
53+
PreCheck: func() { testAccPreCheckWithAWS(t) },
54+
Providers: testAccProviders,
55+
CheckDestroy: testAccCheckHTTPSourceDestroy,
56+
Steps: []resource.TestStep{
57+
{
58+
Config: testAccSumologicS3ArchiveSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket),
59+
Check: resource.ComposeTestCheckFunc(
60+
testAccCheckS3SourceExists(s3ResourceName, &s3Source),
61+
testAccCheckS3SourceValues(&s3Source, sName, sDescription, sCategory),
62+
resource.TestCheckResourceAttrSet(s3ResourceName, "id"),
63+
resource.TestCheckResourceAttr(s3ResourceName, "name", sName),
64+
resource.TestCheckResourceAttr(s3ResourceName, "description", sDescription),
65+
resource.TestCheckResourceAttr(s3ResourceName, "category", sCategory),
66+
resource.TestCheckResourceAttr(s3ResourceName, "content_type", "AwsS3ArchiveBucket"),
67+
resource.TestCheckResourceAttr(s3ResourceName, "path.0.type", "S3BucketPathExpression"),
68+
),
69+
},
70+
{
71+
Config: testAccSumologicS3ArchiveSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testAwsRoleArn, testAwsBucket),
72+
Check: resource.ComposeTestCheckFunc(
73+
testAccCheckS3SourceExists(s3ResourceName, &s3Source),
74+
testAccCheckS3SourceValues(&s3Source, sNameUpdated, sDescriptionUpdated, sCategoryUpdated),
75+
resource.TestCheckResourceAttrSet(s3ResourceName, "id"),
76+
resource.TestCheckResourceAttr(s3ResourceName, "name", sNameUpdated),
77+
resource.TestCheckResourceAttr(s3ResourceName, "description", sDescriptionUpdated),
78+
resource.TestCheckResourceAttr(s3ResourceName, "category", sCategoryUpdated),
79+
resource.TestCheckResourceAttr(s3ResourceName, "content_type", "AwsS3ArchiveBucket"),
80+
resource.TestCheckResourceAttr(s3ResourceName, "path.0.type", "S3BucketPathExpression"),
81+
),
82+
},
83+
},
84+
})
85+
}
86+
func testAccCheckS3ArchiveSourceDestroy(s *terraform.State) error {
87+
client := testAccProvider.Meta().(*Client)
88+
for _, rs := range s.RootModule().Resources {
89+
if rs.Type != "sumologic_s3_source" && rs.Type != "sumologic_cloudwatch_source" {
90+
continue
91+
}
92+
if rs.Primary.ID == "" {
93+
return fmt.Errorf("HTTP Source destruction check: HTTP Source ID is not set")
94+
}
95+
id, err := strconv.Atoi(rs.Primary.ID)
96+
if err != nil {
97+
return fmt.Errorf("Encountered an error: " + err.Error())
98+
}
99+
collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"])
100+
if err != nil {
101+
return fmt.Errorf("Encountered an error: " + err.Error())
102+
}
103+
s, err := client.GetPollingSource(collectorID, id)
104+
if err != nil {
105+
return fmt.Errorf("Encountered an error: " + err.Error())
106+
}
107+
if s != nil {
108+
return fmt.Errorf("Polling Source still exists")
109+
}
110+
}
111+
return nil
112+
}
113+
func testAccCheckS3ArchiveSourceExists(n string, pollingSource *PollingSource) resource.TestCheckFunc {
114+
return func(s *terraform.State) error {
115+
rs, ok := s.RootModule().Resources[n]
116+
if !ok {
117+
return fmt.Errorf("not found: %s", n)
118+
}
119+
if rs.Primary.ID == "" {
120+
return fmt.Errorf("Polling Source ID is not set")
121+
}
122+
id, err := strconv.Atoi(rs.Primary.ID)
123+
if err != nil {
124+
return fmt.Errorf("Polling Source id should be int; got %s", rs.Primary.ID)
125+
}
126+
collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"])
127+
if err != nil {
128+
return fmt.Errorf("Encountered an error: " + err.Error())
129+
}
130+
c := testAccProvider.Meta().(*Client)
131+
pollingSourceResp, err := c.GetPollingSource(collectorID, id)
132+
if err != nil {
133+
return err
134+
}
135+
*pollingSource = *pollingSourceResp
136+
return nil
137+
}
138+
}
139+
func testAccCheckS3ArchiveSourceValues(pollingSource *PollingSource, name, description, category string) resource.TestCheckFunc {
140+
return func(s *terraform.State) error {
141+
if pollingSource.Name != name {
142+
return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, pollingSource.Name)
143+
}
144+
if pollingSource.Description != description {
145+
return fmt.Errorf("bad description, expected \"%s\", got: %#v", description, pollingSource.Description)
146+
}
147+
if pollingSource.Category != category {
148+
return fmt.Errorf("bad category, expected \"%s\", got: %#v", category, pollingSource.Category)
149+
}
150+
return nil
151+
}
152+
}
153+
func testAccSumologicS3ArchiveSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket string) string {
154+
return fmt.Sprintf(`
155+
resource "sumologic_collector" "test" {
156+
name = "%s"
157+
description = "%s"
158+
category = "%s"
159+
}
160+
resource "sumologic_s3_archive_source" "s3_archive" {
161+
name = "%s"
162+
description = "%s"
163+
category = "%s"
164+
content_type = "AwsS3ArchiveBucket"
165+
scan_interval = 300000
166+
paused = false
167+
collector_id = "${sumologic_collector.test.id}"
168+
authentication {
169+
type = "AWSRoleBasedAuthentication"
170+
role_arn = "%s"
171+
}
172+
path {
173+
type = "S3BucketPathExpression"
174+
bucket_name = "%s"
175+
path_expression = "*"
176+
}
177+
}
178+
179+
`, cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket)
180+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
layout: "sumologic"
3+
page_title: "SumoLogic: sumologic_s3_archive_source"
4+
description: |-
5+
Provides a Sumologic AWS S3 Archive Source.
6+
---
7+
8+
# sumologic_s3_archive_source
9+
Provides a [Sumologic AWS S3 Archive Source][2].
10+
11+
__IMPORTANT:__ The AWS credentials are stored in plain-text in the state. This is a potential security issue.
12+
13+
## Example Usage
14+
```hcl
15+
16+
resource "sumologic_s3_archive_source" "terraform_s3_archive_source" {
17+
name = "Amazon S3 Archive Source"
18+
description = "My description"
19+
category = "aws/s3"
20+
content_type = "AwsS3Bucket"
21+
scan_interval = 300000
22+
paused = false
23+
collector_id = "${sumologic_collector.collector.id}"
24+
25+
authentication {
26+
type = "S3BucketAuthentication"
27+
access_key = "someKey"
28+
secret_key = "******"
29+
}
30+
31+
path {
32+
type = "S3BucketPathExpression"
33+
bucket_name = "Bucket1"
34+
path_expression = "*"
35+
}
36+
}
37+
38+
resource "sumologic_collector" "collector" {
39+
name = "my-collector"
40+
description = "Just testing this"
41+
}
42+
```
43+
44+
## Argument reference
45+
46+
In addition to the [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties), the following arguments are supported:
47+
48+
- `content_type` - (Required) The content-type of the collected data. It should be `AwsS3ArchiveBucket` for archive source. Details can be found in the [Sumologic documentation for hosted sources][1].
49+
- `scan_interval` - (Required) Time interval in milliseconds of scans for new data. The default is 300000 and the minimum value is 1000 milliseconds.
50+
- `paused` - (Required) When set to true, the scanner is paused. To disable, set to false.
51+
- `authentication` - (Required) Authentication details for connecting to the S3 bucket.
52+
+ `type` - (Required) Must be either `S3BucketAuthentication` or `AWSRoleBasedAuthentication`.
53+
+ `access_key` - (Required) Your AWS access key if using type `S3BucketAuthentication`.
54+
+ `secret_key` - (Required) Your AWS secret key if using type `S3BucketAuthentication`.
55+
+ `role_arn` - (Required) Your AWS role ARN if using type `AWSRoleBasedAuthentication`. This is not supported for AWS China regions.
56+
+ `region` - (Optional) Your AWS Bucket region.
57+
- `path` - (Required) The location to scan for new data.
58+
+ `type` - (Required) type of polling source. This has to be `S3BucketPathExpression` for `S3 source`.
59+
+ `bucket_name` - (Required) The name of the bucket.
60+
+ `path_expression` - (Required) The path to the data.
61+
62+
### See also
63+
* [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties)
64+
* [Configuring SNS Subscription](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#configuring-sns-subscription)
65+
66+
## Attributes Reference
67+
The following attributes are exported:
68+
69+
- `id` - The internal ID of the source.
70+
- `url` - The HTTP endpoint to use with [SNS to notify Sumo Logic of new files](https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/AWS-S3-Source#Set_up_SNS_in_AWS_(Optional)).
71+
72+
## Import
73+
S3 sources can be imported using the collector and source IDs (`collector/source`), e.g.:
74+
75+
```hcl
76+
terraform import sumologic_s3_archive_source.test 123/456
77+
```
78+
79+
S3 sources can be imported using the collector name and source name (`collectorName/sourceName`), e.g.:
80+
81+
```hcl
82+
terraform import sumologic_s3_archive_source.test my-test-collector/my-test-source
83+
```
84+
85+
[1]: https://help.sumologic.com/Send_Data/Sources/03Use_JSON_to_Configure_Sources/JSON_Parameters_for_Hosted_Sources
86+
[2]: https://help.sumologic.com/docs/manage/archive/#create-an-aws-s3-archivesource

0 commit comments

Comments
 (0)