Skip to content

Commit 35a4b47

Browse files
authored
Revert "Revert "add snsTopicArn field in polling sources (#303)" (#309)" (#311)
This reverts commit 170cae6.
1 parent 5de4b78 commit 35a4b47

8 files changed

+91
-14
lines changed

sumologic/resource_sumologic_generic_polling_source.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ func resourceSumologicGenericPollingSource() *schema.Resource {
130130
},
131131
},
132132
},
133+
"sns_topic_or_subscription_arn": {
134+
Type: schema.TypeList,
135+
Computed: true,
136+
Elem: &schema.Resource{
137+
Schema: map[string]*schema.Schema{
138+
"is_success": {
139+
Type: schema.TypeBool,
140+
Computed: true,
141+
},
142+
"arn": {
143+
Type: schema.TypeString,
144+
Computed: true,
145+
},
146+
},
147+
},
148+
},
133149
},
134150
},
135151
}
@@ -252,12 +268,13 @@ func getPollingThirdPartyPathAttributes(pollingResource []PollingResource) []map
252268

253269
for _, t := range pollingResource {
254270
mapping := map[string]interface{}{
255-
"type": t.Path.Type,
256-
"bucket_name": t.Path.BucketName,
257-
"path_expression": t.Path.PathExpression,
258-
"limit_to_regions": t.Path.LimitToRegions,
259-
"limit_to_namespaces": t.Path.LimitToNamespaces,
260-
"tag_filters": flattenPollingTagFilters(t.Path.TagFilters),
271+
"type": t.Path.Type,
272+
"bucket_name": t.Path.BucketName,
273+
"path_expression": t.Path.PathExpression,
274+
"limit_to_regions": t.Path.LimitToRegions,
275+
"limit_to_namespaces": t.Path.LimitToNamespaces,
276+
"tag_filters": flattenPollingTagFilters(t.Path.TagFilters),
277+
"sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn),
261278
}
262279
s = append(s, mapping)
263280
}
@@ -319,6 +336,32 @@ func getPollingTagFilters(d *schema.ResourceData) []TagFilter {
319336
return filters
320337
}
321338

339+
func flattenPollingSnsTopicOrSubscriptionArn(v PollingSnsTopicOrSubscriptionArn) []map[string]interface{} {
340+
var snsTopicOrSubscriptionArn []map[string]interface{}
341+
snsTopic := map[string]interface{}{
342+
"is_success": v.IsSuccess,
343+
"arn": v.Arn,
344+
}
345+
snsTopicOrSubscriptionArn = append(snsTopicOrSubscriptionArn, snsTopic)
346+
return snsTopicOrSubscriptionArn
347+
}
348+
349+
func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) PollingSnsTopicOrSubscriptionArn {
350+
paths := d.Get("path").([]interface{})
351+
path := paths[0].(map[string]interface{})
352+
snsConfig := path["sns_topic_or_subscription_arn"].([]interface{})
353+
snsTopicOrSubscriptionArn := PollingSnsTopicOrSubscriptionArn{}
354+
355+
if len(snsConfig) > 0 {
356+
for _, rawConfig := range snsConfig {
357+
config := rawConfig.(map[string]interface{})
358+
snsTopicOrSubscriptionArn.IsSuccess = config["is_success"].(bool)
359+
snsTopicOrSubscriptionArn.Arn = config["arn"].(string)
360+
}
361+
}
362+
return snsTopicOrSubscriptionArn
363+
}
364+
322365
func getPollingAuthentication(d *schema.ResourceData) (PollingAuthentication, error) {
323366
auths := d.Get("authentication").([]interface{})
324367
authSettings := PollingAuthentication{}
@@ -364,6 +407,7 @@ func getPollingPathSettings(d *schema.ResourceData) (PollingPath, error) {
364407
pathSettings.Type = "S3BucketPathExpression"
365408
pathSettings.BucketName = path["bucket_name"].(string)
366409
pathSettings.PathExpression = path["path_expression"].(string)
410+
pathSettings.SnsTopicOrSubscriptionArn = getPollingSnsTopicOrSubscriptionArn(d)
367411
case "CloudWatchPath", "AwsInventoryPath":
368412
pathSettings.Type = pathType
369413
rawLimitToRegions := path["limit_to_regions"].([]interface{})

sumologic/sumologic_polling_source.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ type PollingAuthentication struct {
3333
}
3434

3535
type PollingPath struct {
36-
Type string `json:"type"`
37-
BucketName string `json:"bucketName,omitempty"`
38-
PathExpression string `json:"pathExpression,omitempty"`
39-
LimitToRegions []string `json:"limitToRegions,omitempty"`
40-
LimitToNamespaces []string `json:"limitToNamespaces,omitempty"`
41-
TagFilters []TagFilter `json:"tagFilters,omitempty"`
36+
Type string `json:"type"`
37+
BucketName string `json:"bucketName,omitempty"`
38+
PathExpression string `json:"pathExpression,omitempty"`
39+
LimitToRegions []string `json:"limitToRegions,omitempty"`
40+
LimitToNamespaces []string `json:"limitToNamespaces,omitempty"`
41+
TagFilters []TagFilter `json:"tagFilters,omitempty"`
42+
SnsTopicOrSubscriptionArn PollingSnsTopicOrSubscriptionArn `json:"snsTopicOrSubscriptionArn,omitempty"`
4243
}
4344

4445
type TagFilter struct {
@@ -47,6 +48,11 @@ type TagFilter struct {
4748
Tags []string `json:"tags"`
4849
}
4950

51+
type PollingSnsTopicOrSubscriptionArn struct {
52+
IsSuccess bool `json:"isSuccess"`
53+
Arn string `json:"arn"`
54+
}
55+
5056
func (s *Client) CreatePollingSource(source PollingSource, collectorID int) (int, error) {
5157

5258
type PollingSourceMessage struct {

website/docs/index.html.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,20 @@ The following properties are common to ALL sources and can be used to configure
130130
- `cutoff_relative_time` - (Optional) Can be specified instead of cutoffTimestamp to provide a relative offset with respect to the current time. Example: use -1h, -1d, or -1w to collect data that's less than one hour, one day, or one week old, respectively.
131131
- `fields` - (Optional) Map containing key/value pairs.
132132

133+
## Configuring SNS Subscription
134+
This is supported in the following resources.
135+
- `sumologic_cloudfront_source`
136+
- `sumologic_cloudtrail_source`
137+
- `sumologic_elb_source`
138+
- `sumologic_s3_audit_source`
139+
- `sumologic_s3_source`
140+
141+
Steps to configure SNS subscription and sync the state in terrform:
142+
- Step 1: Create the source via terraform.
143+
- Step 2: Setup [SNS subscription][3] outside of terraform on Sumologic UI.
144+
- Step 3: Run `terraform plan -refresh-only` to review the changes and verify the state with the SNS subscription information. Make sure only `sns_topic_or_subscription_arn` is updated. If SNS has been successfully configured and has received a subscription confirmation request `isSuccess` parameter will be true.
145+
- Step 4: Apply the changes with `terraform apply -refresh-only`.
146+
133147
[2]: https://en.wikipedia.org/wiki/Tz_database
148+
[3]: https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/AWS_Sources#set-up-sns-in-aws-highly-recommended
149+

website/docs/r/cloudfront_source.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ In addition to the common properties, the following arguments are supported:
5858
+ `type` - (Required) type of polling source. This has to be `S3BucketPathExpression` for `CloudFront` source.
5959
+ `bucket_name` - (Required) The name of the bucket. This is needed if using type `S3BucketPathExpression`.
6060
+ `path_expression` - (Required) The path to the data. This is needed if using type `S3BucketPathExpression`.
61+
+ `sns_topic_or_subscription_arn` - (Computed) This is a computed field for SNS topic/subscription ARN.
6162

6263
### See also
6364
* [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties)
65+
* [Configuring SNS Subscription](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#configuring-sns-subscription)
6466

6567
## Attributes Reference
6668
The following attributes are exported:
@@ -82,4 +84,4 @@ terraform import sumologic_cloudfront_source.test my-test-collector/my-test-sour
8284
```
8385

8486
[1]: https://help.sumologic.com/Send_Data/Sources/03Use_JSON_to_Configure_Sources/JSON_Parameters_for_Hosted_Sources
85-
[2]: https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/Amazon-CloudFront-Source
87+
[2]: https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/Amazon-CloudFront-Source

website/docs/r/cloudtrail_source.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ In addition to the common properties, the following arguments are supported:
5858
+ `type` - (Required) type of polling source. This has to be `S3BucketPathExpression` for `CloudTrail` source.
5959
+ `bucket_name` - (Required) The name of the bucket.
6060
+ `path_expression` - (Required) The path to the data.
61+
+ `sns_topic_or_subscription_arn` - (Computed) This is a computed field for SNS topic/subscription ARN.
62+
6163

6264
### See also
6365
* [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties)
66+
* [Configuring SNS Subscription](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#configuring-sns-subscription)
6467

6568
## Attributes Reference
6669
The following attributes are exported:
@@ -82,4 +85,4 @@ terraform import sumologic_cloudtrail_source.test my-test-collector/my-test-sour
8285
```
8386

8487
[1]: https://help.sumologic.com/Send_Data/Sources/03Use_JSON_to_Configure_Sources/JSON_Parameters_for_Hosted_Sources
85-
[2]: https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/AWS-CloudTrail-Source
88+
[2]: https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/AWS-CloudTrail-Source

website/docs/r/elb_source.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ In addition to the common properties, the following arguments are supported:
5858
+ `type` - (Required) type of polling source. This has to be `S3BucketPathExpression` for `ELB` source.
5959
+ `bucket_name` - (Required) The name of the bucket.
6060
+ `path_expression` - (Required) The path to the data.
61+
+ `sns_topic_or_subscription_arn` - (Computed) This is a computed field for SNS topic/subscription ARN.
6162

6263
### See also
6364
* [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties)
65+
* [Configuring SNS Subscription](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#configuring-sns-subscription)
6466

6567
## Attributes Reference
6668
The following attributes are exported:

website/docs/r/s3_audit_source.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ In addition to the common properties, the following arguments are supported:
5858
+ `type` - (Required) type of polling source. This has to be `S3BucketPathExpression` for `S3 Audit source`.
5959
+ `bucket_name` - (Required) The name of the bucket.
6060
+ `path_expression` - (Required) The path to the data.
61+
+ `sns_topic_or_subscription_arn` - (Computed) This is a computed field for SNS topic/subscription ARN.
6162

6263
### See also
6364
* [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties)
65+
* [Configuring SNS Subscription](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#configuring-sns-subscription)
6466

6567
## Attributes Reference
6668
The following attributes are exported:

website/docs/r/s3_source.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ In addition to the common properties, the following arguments are supported:
5858
+ `type` - (Required) type of polling source. This has to be `S3BucketPathExpression` for `S3 source`.
5959
+ `bucket_name` - (Required) The name of the bucket.
6060
+ `path_expression` - (Required) The path to the data.
61+
+ `sns_topic_or_subscription_arn` - (Computed) This is a computed field for SNS topic/subscription ARN.
6162

6263
### See also
6364
* [Common Source Properties](https://github.com/SumoLogic/tree/master/website#common-source-properties)
65+
* [Configuring SNS Subscription](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#configuring-sns-subscription)
6466

6567
## Attributes Reference
6668
The following attributes are exported:

0 commit comments

Comments
 (0)