Skip to content

Commit e88522e

Browse files
committed
Add data source sumologic_partitions
1 parent 182ccc8 commit e88522e

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
FEATURES:
55
* **New Data Source:** sumologic_partition
6+
* **New Data Source:** sumologic_partitions
67

78
ENHANCEMENTS:
89
* Add support for searchable time for dashboard field time_source
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package sumologic
2+
3+
import (
4+
"crypto/sha256"
5+
"encoding/hex"
6+
"fmt"
7+
"sort"
8+
"strings"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
11+
)
12+
13+
func dataSourceSumologicPartitions() *schema.Resource {
14+
return &schema.Resource{
15+
Read: dataSourceSumologicPartitionsRead,
16+
17+
Schema: map[string]*schema.Schema{
18+
"partitions": {
19+
Type: schema.TypeList,
20+
Computed: true,
21+
Elem: &schema.Resource{
22+
Schema: dataSourcePartitionSchema(),
23+
Read: dataSourceSumologicPartitionRead,
24+
},
25+
},
26+
},
27+
}
28+
}
29+
30+
func dataSourceSumologicPartitionsRead(d *schema.ResourceData, meta interface{}) error {
31+
c := meta.(*Client)
32+
33+
spartitions, err := c.ListPartitions()
34+
if err != nil {
35+
return fmt.Errorf("error retrieving partitions: %v", err)
36+
}
37+
38+
partitions := make([]map[string]interface{}, 0, len(spartitions))
39+
40+
for _, spartition := range spartitions {
41+
partition := map[string]interface{}{
42+
"id": spartition.ID,
43+
"name": spartition.Name,
44+
"routing_expression": spartition.RoutingExpression,
45+
"analytics_tier": spartition.AnalyticsTier,
46+
"retention_period": spartition.RetentionPeriod,
47+
"is_compliant": spartition.IsCompliant,
48+
"total_bytes": spartition.TotalBytes,
49+
"data_forwarding_id": spartition.DataForwardingId,
50+
"is_active": spartition.IsActive,
51+
"index_type": spartition.IndexType,
52+
"is_included_in_default_search": spartition.IsIncludedInDefaultSearch,
53+
}
54+
55+
partitions = append(partitions, partition)
56+
}
57+
58+
d.Set("partitions", partitions)
59+
d.SetId(generatePartitionsId(spartitions))
60+
61+
return nil
62+
}
63+
64+
func generatePartitionsId(partitions []Partition) string {
65+
// Collect a sorted list of partition IDs
66+
ids := []string{"partition_ids"}
67+
for _, partition := range partitions {
68+
ids = append(ids, partition.ID)
69+
}
70+
sort.Strings(ids)
71+
72+
// Join all IDs and create a hash
73+
idString := strings.Join(ids, "|")
74+
hash := sha256.Sum256([]byte(idString))
75+
return hex.EncodeToString(hash[:])
76+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package sumologic
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccDataSourcePartitions_basic(t *testing.T) {
10+
resource.Test(t, resource.TestCase{
11+
PreCheck: func() { testAccPreCheck(t) },
12+
Providers: testAccProviders,
13+
Steps: []resource.TestStep{
14+
{
15+
Config: testDataSourceSumologicPartitionsConfig,
16+
Check: resource.ComposeTestCheckFunc(
17+
checkResourceAttrGreaterThanZero("data.sumologic_partitions.test", "partitions.#"),
18+
),
19+
},
20+
},
21+
})
22+
}
23+
24+
var testDataSourceSumologicPartitionsConfig = `
25+
data "sumologic_partitions" "test" {}
26+
`

sumologic/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func Provider() terraform.ResourceProvider {
135135
"sumologic_folder": dataSourceSumologicFolder(),
136136
"sumologic_my_user_id": dataSourceSumologicMyUserId(),
137137
"sumologic_partition": dataSourceSumologicPartition(),
138+
"sumologic_partitions": dataSourceSumologicPartitions(),
138139
"sumologic_role": dataSourceSumologicRole(),
139140
"sumologic_role_v2": dataSourceSumologicRoleV2(),
140141
"sumologic_user": dataSourceSumologicUser(),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
layout: "sumologic"
3+
page_title: "SumoLogic: sumologic_partition"
4+
description: |-
5+
Provides a way to retrieve all Sumo Logic partitions.
6+
---
7+
8+
# sumologic_partition
9+
10+
Provides a way to retrieve all [Sumologic Partitions][1].
11+
12+
## Example Usage
13+
14+
```hcl
15+
data "sumologic_partitions" "partitions" {}
16+
```
17+
18+
## Attributes reference
19+
20+
The following attributes are exported:
21+
22+
- `name` - The name of the partition.
23+
- `routing_expression` - The query that defines the data to be included in the partition.
24+
- `analytics_tier` - The Data Tier where the data in the partition will reside. Possible values are: `continuous`, `frequent`, `infrequent`
25+
- `retention_period` - The number of days to retain data in the partition.
26+
- `is_compliant` - Whether the partition is used for compliance or audit purposes.
27+
- `is_included_in_default_search` - Whether the partition is included in the default search scope.
28+
- `total_bytes` - The size of the data in the partition in bytes.
29+
- `is_active` - Whether the partition is currently active or decommissioned.
30+
- `index_type` - The type of partition index. Possible values are: `DefaultIndex`, `AuditIndex`or `Partition`
31+
- `data_forwarding_id` - The ID of the data forwarding configuration to be used by the partition.
32+
33+
[1]: https://help.sumologic.com/docs/manage/partitions/data-tiers/

0 commit comments

Comments
 (0)