Skip to content

Commit 47dd5d6

Browse files
committed
SUMO-258848: disallow updates to partition's analytics tier other than case of migration to flex
1 parent fe20dd5 commit 47dd5d6

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

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+
if a == nil && b == nil {
202+
return true
203+
}
204+
205+
if a == nil || b == nil {
206+
return false
207+
}
208+
209+
return strings.EqualFold(*a, *b)
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+
}

0 commit comments

Comments
 (0)