Skip to content

Commit 182ccc8

Browse files
committed
Add data source sumologic_partition
1 parent 97806e1 commit 182ccc8

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## X.Y.Z (Unreleased)
22
* Add new change notes here
33

4+
FEATURES:
5+
* **New Data Source:** sumologic_partition
6+
47
ENHANCEMENTS:
58
* Add support for searchable time for dashboard field time_source
69

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package sumologic
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7+
)
8+
9+
func dataSourceSumologicPartition() *schema.Resource {
10+
return &schema.Resource{
11+
Read: dataSourceSumologicPartitionRead,
12+
Schema: dataSourcePartitionSchema(),
13+
}
14+
}
15+
16+
func dataSourcePartitionSchema() map[string]*schema.Schema {
17+
return map[string]*schema.Schema{
18+
"id": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
},
22+
"name": {
23+
Type: schema.TypeString,
24+
Computed: true,
25+
},
26+
"routing_expression": {
27+
Type: schema.TypeString,
28+
Computed: true,
29+
},
30+
"analytics_tier": {
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"retention_period": {
35+
Type: schema.TypeInt,
36+
Computed: true,
37+
},
38+
"is_compliant": {
39+
Type: schema.TypeBool,
40+
Computed: true,
41+
},
42+
"total_bytes": {
43+
Type: schema.TypeInt,
44+
Computed: true,
45+
},
46+
"data_forwarding_id": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
},
50+
"is_active": {
51+
Type: schema.TypeBool,
52+
Computed: true,
53+
},
54+
"index_type": {
55+
Type: schema.TypeString,
56+
Computed: true,
57+
},
58+
"reduce_retention_period_immediately": {
59+
Type: schema.TypeBool,
60+
Computed: true,
61+
},
62+
"is_included_in_default_search": {
63+
Type: schema.TypeBool,
64+
Computed: true,
65+
},
66+
}
67+
}
68+
69+
func dataSourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) error {
70+
c := meta.(*Client)
71+
72+
var err error
73+
var spartition *Partition
74+
75+
rid, ok := d.GetOk("id")
76+
77+
if !ok {
78+
return fmt.Errorf("please specify the partition id")
79+
}
80+
81+
id := rid.(string)
82+
spartition, err = c.GetPartition(id)
83+
if err != nil {
84+
return fmt.Errorf("error retrieving partition with id %v: %v", id, err)
85+
}
86+
if spartition == nil {
87+
return fmt.Errorf("partition with id %v not found", id)
88+
}
89+
90+
d.SetId(spartition.ID)
91+
d.Set("routing_expression", spartition.RoutingExpression)
92+
d.Set("name", spartition.Name)
93+
d.Set("analytics_tier", spartition.AnalyticsTier)
94+
d.Set("retention_period", spartition.RetentionPeriod)
95+
d.Set("is_compliant", spartition.IsCompliant)
96+
d.Set("data_forwarding_id", spartition.DataForwardingId)
97+
d.Set("is_active", spartition.IsActive)
98+
d.Set("total_bytes", spartition.TotalBytes)
99+
d.Set("index_type", spartition.IndexType)
100+
d.Set("reduce_retention_period_immediately", spartition.ReduceRetentionPeriodImmediately)
101+
d.Set("is_included_in_default_search", spartition.IsIncludedInDefaultSearch)
102+
103+
return nil
104+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package sumologic
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccDataSourcePartition_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: testDataSourceSumologicPartitionConfig,
16+
Check: resource.ComposeTestCheckFunc(
17+
testAccDataSourcePartitionCheck("data.sumologic_partition.test"),
18+
),
19+
},
20+
},
21+
})
22+
}
23+
24+
func testAccDataSourcePartitionCheck(name string) resource.TestCheckFunc {
25+
return resource.ComposeTestCheckFunc(
26+
resource.TestCheckResourceAttr(name, "id", "00000000000AD88D"),
27+
resource.TestCheckResourceAttr(name, "name", "apache"),
28+
resource.TestCheckResourceAttr(name, "routing_expression", "_sourcecategory=*/Apache"),
29+
resource.TestCheckResourceAttr(name, "analytics_tier", "continuous"),
30+
resource.TestCheckResourceAttr(name, "retention_period", "365"),
31+
resource.TestCheckResourceAttr(name, "is_compliant", "false"),
32+
resource.TestCheckResourceAttr(name, "is_active", "true"),
33+
resource.TestCheckResourceAttr(name, "total_bytes", "0"),
34+
resource.TestCheckResourceAttr(name, "data_forwarding_id", ""),
35+
resource.TestCheckResourceAttr(name, "index_type", "Partition"),
36+
resource.TestCheckResourceAttr(name, "reduce_retention_period_immediately", "false"),
37+
resource.TestCheckResourceAttr(name, "is_included_in_default_search", "true"),
38+
)
39+
}
40+
41+
var testDataSourceSumologicPartitionConfig = `
42+
data "sumologic_partition" "test" {
43+
id = "00000000000AD88D"
44+
}
45+
`

sumologic/provider.go

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

0 commit comments

Comments
 (0)