Skip to content

Commit 3fd7e34

Browse files
authored
Merge pull request #153 from SumoLogic/scheduled-views-fixes
bug fixes for partitions and scheduled views
2 parents 9d5336c + e7106c1 commit 3fd7e34

File tree

6 files changed

+95
-51
lines changed

6 files changed

+95
-51
lines changed

sumologic/resource_sumologic_partition.go

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,48 @@ func resourceSumologicPartition() *schema.Resource {
2727
"routing_expression": {
2828
Type: schema.TypeString,
2929
Required: true,
30-
ValidateFunc: validation.StringLenBetween(0, 16384),
30+
ValidateFunc: validation.StringLenBetween(1, 16384),
3131
},
3232
"analytics_tier": {
3333
Type: schema.TypeString,
3434
Optional: true,
3535
ValidateFunc: validation.StringInSlice([]string{"continuous", "frequent", "infrequent"}, false),
3636
Default: "continuous",
3737
},
38-
// Terraform does not support reducing the retention period after creation
3938
"retention_period": {
4039
Type: schema.TypeInt,
4140
Optional: true,
4241
ValidateFunc: validation.IntAtLeast(-1),
4342
Default: -1,
4443
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
45-
if new == "-1" && old != "" {
46-
return true
47-
}
48-
return false
44+
return new == "-1" && old != ""
4945
},
5046
},
5147
"is_compliant": {
5248
Type: schema.TypeBool,
53-
Required: true,
49+
Optional: true,
50+
Default: false,
51+
},
52+
"total_bytes": {
53+
Type: schema.TypeInt,
54+
Computed: true,
5455
},
5556
"data_forwarding_id": {
5657
Type: schema.TypeString,
57-
Optional: true,
58+
Computed: true,
5859
},
5960
"is_active": {
6061
Type: schema.TypeBool,
6162
Computed: true,
6263
},
64+
"index_type": {
65+
Type: schema.TypeString,
66+
Computed: true,
67+
},
68+
"reduce_retention_period_immediately": {
69+
Type: schema.TypeBool,
70+
Optional: true,
71+
},
6372
},
6473
}
6574
}
@@ -104,6 +113,8 @@ func resourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) er
104113
d.Set("is_compliant", spartition.IsCompliant)
105114
d.Set("data_forwarding_id", spartition.DataForwardingId)
106115
d.Set("is_active", spartition.IsActive)
116+
d.Set("total_bytes", spartition.TotalBytes)
117+
d.Set("index_type", spartition.IndexType)
107118

108119
return nil
109120
}
@@ -126,13 +137,16 @@ func resourceSumologicPartitionUpdate(d *schema.ResourceData, meta interface{})
126137

127138
func resourceToPartition(d *schema.ResourceData) Partition {
128139
return Partition{
129-
ID: d.Id(),
130-
Name: d.Get("name").(string),
131-
RoutingExpression: d.Get("routing_expression").(string),
132-
AnalyticsTier: d.Get("analytics_tier").(string),
133-
RetentionPeriod: d.Get("retention_period").(int),
134-
IsCompliant: d.Get("is_compliant").(bool),
135-
DataForwardingId: d.Get("data_forwarding_id").(string),
136-
IsActive: d.Get("is_active").(bool),
140+
ID: d.Id(),
141+
Name: d.Get("name").(string),
142+
RoutingExpression: d.Get("routing_expression").(string),
143+
AnalyticsTier: d.Get("analytics_tier").(string),
144+
RetentionPeriod: d.Get("retention_period").(int),
145+
IsCompliant: d.Get("is_compliant").(bool),
146+
DataForwardingId: d.Get("data_forwarding_id").(string),
147+
IsActive: d.Get("is_active").(bool),
148+
TotalBytes: d.Get("total_bytes").(int),
149+
IndexType: d.Get("index_type").(string),
150+
ReduceRetentionPeriodImmediately: d.Get("reduce_retention_period_immediately").(bool),
137151
}
138152
}

sumologic/resource_sumologic_scheduled_view.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ func resourceSumologicScheduledView() *schema.Resource {
2828
"index_name": {
2929
Type: schema.TypeString,
3030
Required: true,
31+
ForceNew: true,
3132
ValidateFunc: validation.StringLenBetween(0, 255),
3233
},
3334
"start_time": {
3435
Type: schema.TypeString,
3536
Required: true,
37+
ForceNew: true,
3638
ValidateFunc: validation.IsRFC3339Time,
3739
},
3840
"retention_period": {
@@ -41,14 +43,24 @@ func resourceSumologicScheduledView() *schema.Resource {
4143
ValidateFunc: validation.IntAtLeast(-1),
4244
Default: -1,
4345
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
44-
// taken from https://stackoverflow.com/a/57785476/118587
45-
return old == "-1"
46+
return new == "-1" && old != ""
4647
},
4748
},
4849
"data_forwarding_id": {
4950
Type: schema.TypeString,
5051
Optional: true,
5152
},
53+
"parsing_mode": {
54+
Type: schema.TypeString,
55+
Optional: true,
56+
ForceNew: true,
57+
Default: "Manual",
58+
ValidateFunc: validation.StringInSlice([]string{"AutoParse", "Manual"}, false),
59+
},
60+
"reduce_retention_period_immediately": {
61+
Type: schema.TypeBool,
62+
Optional: true,
63+
},
5264
},
5365
}
5466
}
@@ -92,6 +104,7 @@ func resourceSumologicScheduledViewRead(d *schema.ResourceData, meta interface{}
92104
d.Set("start_time", sview.StartTime.Format(time.RFC3339))
93105
d.Set("retention_period", sview.RetentionPeriod)
94106
d.Set("data_forwarding_id", sview.DataForwardingId)
107+
d.Set("parsing_mode", sview.ParsingMode)
95108

96109
return nil
97110
}
@@ -118,11 +131,13 @@ func resourceToScheduledView(d *schema.ResourceData) ScheduledView {
118131
log.Fatal(err)
119132
}
120133
return ScheduledView{
121-
ID: d.Id(),
122-
Query: d.Get("query").(string),
123-
IndexName: d.Get("index_name").(string),
124-
StartTime: startTimeParsed,
125-
RetentionPeriod: d.Get("retention_period").(int),
126-
DataForwardingId: d.Get("data_forwarding_id").(string),
134+
ID: d.Id(),
135+
Query: d.Get("query").(string),
136+
IndexName: d.Get("index_name").(string),
137+
StartTime: startTimeParsed,
138+
RetentionPeriod: d.Get("retention_period").(int),
139+
DataForwardingId: d.Get("data_forwarding_id").(string),
140+
ParsingMode: d.Get("parsing_mode").(string),
141+
ReduceRetentionPeriodImmediately: d.Get("reduce_retention_period_immediately").(bool),
127142
}
128143
}

sumologic/sumologic_partition.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ func (s *Client) UpdatePartition(spartition Partition) error {
6565
}
6666

6767
type Partition struct {
68-
ID string `json:"id,omitempty"`
69-
Name string `json:"name"`
70-
RoutingExpression string `json:"routingExpression"`
71-
AnalyticsTier string `json:"analyticsTier"`
72-
RetentionPeriod int `json:"retentionPeriod"`
73-
IsCompliant bool `json:"isCompliant"`
74-
DataForwardingId string `json:"dataForwardingId"`
75-
IsActive bool `json:"isActive"`
68+
ID string `json:"id,omitempty"`
69+
Name string `json:"name"`
70+
RoutingExpression string `json:"routingExpression"`
71+
AnalyticsTier string `json:"analyticsTier"`
72+
RetentionPeriod int `json:"retentionPeriod"`
73+
IsCompliant bool `json:"isCompliant"`
74+
DataForwardingId string `json:"dataForwardingId"`
75+
IsActive bool `json:"isActive"`
76+
TotalBytes int `json:"totalBytes"`
77+
IndexType string `json:"indexType"`
78+
ReduceRetentionPeriodImmediately bool `json:"reduceRetentionPeriodImmediately"`
7679
}

sumologic/sumologic_scheduled_view.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ func (s *Client) UpdateScheduledView(sview ScheduledView) error {
5757
}
5858

5959
type ScheduledView struct {
60-
ID string `json:"id,omitempty"`
61-
Query string `json:"query"`
62-
IndexName string `json:"indexName"`
63-
StartTime time.Time `json:"startTime"`
64-
RetentionPeriod int `json:"retentionPeriod"`
65-
DataForwardingId string `json:"dataForwardingId"`
60+
ID string `json:"id,omitempty"`
61+
Query string `json:"query"`
62+
IndexName string `json:"indexName"`
63+
StartTime time.Time `json:"startTime"`
64+
RetentionPeriod int `json:"retentionPeriod"`
65+
DataForwardingId string `json:"dataForwardingId"`
66+
ParsingMode string `json:"parsingMode"`
67+
ReduceRetentionPeriodImmediately bool `json:"reduceRetentionPeriodImmediately"`
6668
}

website/docs/r/partition.html.markdown

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@ Provides a [Sumologic Partition][1].
1111
## Example Usage
1212
```hcl
1313
resource "sumologic_partition" "examplePartition" {
14-
name = "terraform_examplePartition"
15-
routing_expression = "_sourcecategory=*/Terraform"
16-
analytics_tier = "enhanced"
17-
is_compliant = false
14+
name = "terraform_examplePartition"
15+
routing_expression = "_sourcecategory=*/Terraform"
16+
analytics_tier = "enhanced"
17+
is_compliant = false
18+
lifecycle {
19+
prevent_destroy = true
20+
}
1821
}
1922
```
2023

2124
## Argument reference
2225

2326
The following arguments are supported:
2427

25-
- `name` - (Required) The name of the partition.
28+
- `name` - (Required, Forces new resource) The name of the partition.
2629
- `routing_expression` - (Required) The query that defines the data to be included in the partition.
27-
- `analytics_tier` - (Required) The Cloud Flex analytics tier for your data; only relevant if your account has basic analytics enabled. Possible values are: `enhanced`, `basic`, `cold`, `continuous`, `frequent`, `infrequent`
30+
- `analytics_tier` - (Required) The Cloud Flex analytics tier for your data; only relevant if your account has basic analytics enabled. Possible values are: `continuous`, `frequent`, `infrequent`
2831
- `retention_period` - (Optional) The number of days to retain data in the partition, or -1 to use the default value for your account. Only relevant if your account has variable retention enabled.
29-
- `is_compliant` - (Required) Whether the partition is compliant or not. Mark a partition as compliant if it contains data used for compliance or audit purpose. Retention for a compliant partition can only be increased and cannot be reduced after the partition is marked compliant. A partition once marked compliant, cannot be marked non-compliant later.
30-
- `data_forwarding_id` - (Optional) An optional ID of a data forwarding configuration to be used by the partition.
32+
- `is_compliant` - (Optional) Whether the partition is compliant or not. Mark a partition as compliant if it contains data used for compliance or audit purpose. Retention for a compliant partition can only be increased and cannot be reduced after the partition is marked compliant. A partition once marked compliant, cannot be marked non-compliant later.
33+
- `reduce_retention_period_immediately` - (Optional) This is required on update if the newly specified retention period is less than the existing retention period. In such a situation, a value of true says that data between the existing retention period and the new retention period should be deleted immediately; if false, such data will be deleted after seven days. This property is optional and ignored if the specified retentionPeriod is greater than or equal to the current retention period.
3134

3235
## Attributes reference
3336

website/docs/r/scheduled_view.html.markdown

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ _view=connections connectionStats
2121
QUERY
2222
start_time = "2019-09-01T00:00:00Z"
2323
retention_period = 365
24+
lifecycle {
25+
prevent_destroy = true
26+
}
2427
}
2528
```
2629

2730
## Argument reference
2831

2932
The following arguments are supported:
3033

31-
- `index_name` - (Required) Name of the index (scheduled view).
32-
- `query` - (Required) Log query defining the scheduled view. This value cannot be updated.
33-
- `start_time` - (Required) Starting date/time for log indexing.
34-
- `retention_period` - (Optional) Number of days to keep the scheduled view data for.
35-
- `data_forwarding_id` - (Optional) ID of a data forwarding configuration to be used by the scheduled view.
34+
~> For attributes that force a new resource, if the value is updated, it will destroy the resource and recreate it which may incur significant costs. We advise customers to set the `lifecycle` attribute `prevent_destroy` to `true` to avoid accidentally destroying and recreating expensive resources.
35+
36+
- `index_name` - (Required, Forces new resource) Name of the index (scheduled view).
37+
- `query` - (Required, Forces new resource) Log query defining the scheduled view.
38+
- `start_time` - (Required, Forces new resource) Start timestamp in UTC in RFC3339 format.
39+
- `retention_period` - (Optional) The number of days to retain data in the scheduled view, or -1 to use the default value for your account. Only relevant if your account has multi-retention. enabled.
40+
- `data_forwarding_id` - (Optional) An optional ID of a data forwarding configuration to be used by the scheduled view.
41+
- `parsing_mode` - (Optional, Forces new resource) Default to `Manual`. Define the parsing mode to scan the JSON format log messages. Possible values are: `AutoParse` - In AutoParse mode, the system automatically figures out fields to parse based on the search query. `Manual` - While in the Manual mode, no fields are parsed out automatically. For more information see Dynamic Parsing.
42+
- `reduce_retention_period_immediately` - (Optional) This is required on update if the newly specified retention period is less than the existing retention period. In such a situation, a value of true says that data between the existing retention period and the new retention period should be deleted immediately; if false, such data will be deleted after seven days. This property is optional and ignored if the specified retentionPeriod is greater than or equal to the current retention period.
3643

3744
The following attributes are exported:
3845

0 commit comments

Comments
 (0)