Skip to content

Commit 1da6ecb

Browse files
authored
Merge pull request #757 from SumoLogic/raghav-fix-disallow-updates-to-partitions-tier
SUMO-258848: disallow updates to partition's analytics tier other than in case of flex migration
2 parents 426ba12 + 3f6a954 commit 1da6ecb

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
FEATURES:
55
* **New Data Source:** sumologic_apps
66

7+
BUG FIXES:
8+
* Prevent user-initiated updates to the analytics_tier field in the partition resource, while allowing Terraform to reconcile state changes resulting from backend-driven updates (e.g., Flex migrations).
9+
10+
711
ENHANCEMENTS:
812
* Improve error message when an API URL is constructed with missing parameters
913

sumologic/resource_sumologic_partition.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sumologic
22

33
import (
4+
"fmt"
45
"log"
56
"strings"
67

@@ -135,11 +136,23 @@ func resourceSumologicPartitionDelete(d *schema.ResourceData, meta interface{})
135136
return c.DecommissionPartition(d.Id())
136137
}
137138
func resourceSumologicPartitionUpdate(d *schema.ResourceData, meta interface{}) error {
139+
c := meta.(*Client)
140+
141+
partitionId := d.Id()
142+
138143
spartition := resourceToPartition(d)
144+
if d.HasChange("analytics_tier") {
145+
currPartitionState, err := c.GetPartition(partitionId)
146+
if err != nil {
147+
return fmt.Errorf("error loading partition with id %s for analytics_tier update validation", partitionId)
148+
}
139149

140-
c := meta.(*Client)
141-
err := c.UpdatePartition(spartition)
150+
if !areAnalyticsTierEqual(currPartitionState.AnalyticsTier, spartition.AnalyticsTier) {
151+
return fmt.Errorf("analytics_tier of a partition can only be updated post creation if partition has been moved to flex tier")
152+
}
153+
}
142154

155+
err := c.UpdatePartition(spartition)
143156
if err != nil {
144157
return err
145158
}
@@ -183,3 +196,15 @@ func resourceToPartition(d *schema.ResourceData) Partition {
183196
IsIncludedInDefaultSearch: isIncludedInDefaultSearchPtr,
184197
}
185198
}
199+
200+
func areAnalyticsTierEqual(a, b *string) bool {
201+
coerceToStr := func(s *string) string {
202+
if s == nil {
203+
return ""
204+
}
205+
return *s
206+
}
207+
208+
return strings.EqualFold(coerceToStr(a), coerceToStr(b))
209+
}
210+

sumologic/resource_sumologic_partition_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sumologic
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
@@ -50,6 +51,28 @@ func TestAccSumoLogicPartition_basic(t *testing.T) {
5051
"sumologic_partition.foo", "is_compliant", "false"),
5152
),
5253
},
54+
// allow change in casing of analytics_tier
55+
{
56+
Config: updatePartitionAnalyticsTierCase(testName),
57+
Check: resource.ComposeTestCheckFunc(
58+
testAccCheckPartitionExists("sumologic_partition.foo"),
59+
resource.TestCheckResourceAttr(
60+
"sumologic_partition.foo", "name", "terraform_acctest_"+testName),
61+
resource.TestCheckResourceAttr(
62+
"sumologic_partition.foo", "routing_expression", "_sourcecategory=*/Terraform"),
63+
resource.TestCheckResourceAttr(
64+
"sumologic_partition.foo", "analytics_tier", "continuous"),
65+
resource.TestCheckResourceAttr(
66+
"sumologic_partition.foo", "retention_period", "366"),
67+
resource.TestCheckResourceAttr(
68+
"sumologic_partition.foo", "is_compliant", "false"),
69+
),
70+
},
71+
// Update analytics tier to a different value and assert error
72+
{
73+
Config: updatePartitionAnalyticsTierConfig(testName),
74+
ExpectError: regexp.MustCompile(`(?i)analytics_tier of a partition can only be updated post creation if partition has been moved to flex tier`),
75+
},
5376
},
5477
})
5578
}
@@ -107,3 +130,27 @@ resource "sumologic_partition" "foo" {
107130
}
108131
`, testName)
109132
}
133+
134+
func updatePartitionAnalyticsTierConfig(testName string) string {
135+
return fmt.Sprintf(`
136+
resource "sumologic_partition" "foo" {
137+
name = "terraform_acctest_%s"
138+
routing_expression = "_sourcecategory=*/Terraform"
139+
retention_period = 365
140+
is_compliant = false
141+
analytics_tier = "infrequent" // Changed from "continuous" to trigger error
142+
}
143+
`, testName)
144+
}
145+
146+
func updatePartitionAnalyticsTierCase(testName string) string {
147+
return fmt.Sprintf(`
148+
resource "sumologic_partition" "foo" {
149+
name = "terraform_acctest_%s"
150+
routing_expression = "_sourcecategory=*/Terraform"
151+
retention_period = 366
152+
is_compliant = false
153+
analytics_tier = "ContinuouS" // Changed case for "continuous"
154+
}
155+
`, testName)
156+
}

website/docs/r/partition.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The following arguments are supported:
2929
- `name` - (Required, Forces new resource) The name of the partition.
3030
- `routing_expression` - (Required) The query that defines the data to be included in the partition.
3131
- `analytics_tier` - (Optional) The cloud flex analytics tier for your data; only relevant if your account has basic analytics enabled. If no value is supplied, partition will be created in continuous tier. Other possible values are : "frequent" and "infrequent". For flex partition, you can leave it empty or send flex.
32+
This field is set during partition creation and cannot be modified later by the user. However, Terraform can detect and reconcile backend-driven changes, such as those resulting from a Flex migration.
3233
- `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.
3334
- `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.
3435
- `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.

0 commit comments

Comments
 (0)