Skip to content

Commit 693676d

Browse files
authored
fix(segment): fix create feature specific segment (#156)
* fix(segment): fix create feature specific segment * bump terraform and go version * deps: bump terraform-plugin-framework-validators * deps: bump terraform-plugin-docs
1 parent a54454f commit 693676d

File tree

5 files changed

+81
-20
lines changed

5 files changed

+81
-20
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ permissions:
2020
env:
2121
# Go language version to use for building. This value should also be updated
2222
# in the release workflow if changed.
23-
GO_VERSION: '1.21'
23+
GO_VERSION: '1.22'
2424

2525
jobs:
2626
# Ensure project builds before running testing matrix
@@ -63,8 +63,8 @@ jobs:
6363
matrix:
6464
# list whatever Terraform versions here you would like to support
6565
terraform:
66-
- '1.4.*'
67-
- '1.5.*'
66+
- '1.8.*'
67+
- '1.9.*'
6868
steps:
6969
- uses: actions/setup-go@v5
7070
with:

flagsmith/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func (s *SegmentResourceData) ToClientSegment() *flagsmithapi.Segment {
418418
segmentID := s.ID.ValueInt64()
419419
segment.ID = &segmentID
420420
}
421-
if !s.ID.IsNull() && !s.FeatureID.IsUnknown() {
421+
if !s.FeatureID.IsNull() && !s.FeatureID.IsUnknown() {
422422
featureID := s.FeatureID.ValueInt64()
423423
segment.FeatureID = &featureID
424424
}

flagsmith/resource_segment_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,36 @@ func TestAccSegmentResource(t *testing.T) {
8787
})
8888
}
8989

90+
func TestAccFeatureSpecificSegmentResource(t *testing.T) {
91+
segmentName := acctest.RandString(16)
92+
93+
resource.Test(t, resource.TestCase{
94+
PreCheck: func() { testAccPreCheck(t) },
95+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
96+
CheckDestroy: testAccCheckSegmentResourceDestroy,
97+
Steps: []resource.TestStep{
98+
// Create and Read testing
99+
{
100+
Config: testAccFeatureSegmentResourceConfig(segmentName),
101+
Check: resource.ComposeAggregateTestCheckFunc(
102+
resource.TestCheckResourceAttr("flagsmith_segment.test_segment", "name", segmentName),
103+
resource.TestCheckResourceAttr("flagsmith_segment.test_segment", "project_uuid", projectUUID()),
104+
105+
resource.TestCheckResourceAttr("flagsmith_segment.test_segment", "feature_id", fmt.Sprintf("%d", featureID())),
106+
107+
resource.TestCheckResourceAttrSet("flagsmith_segment.test_segment", "id"),
108+
resource.TestCheckResourceAttrSet("flagsmith_segment.test_segment", "uuid"),
109+
resource.TestCheckResourceAttrSet("flagsmith_segment.test_segment", "project_id"),
110+
),
111+
},
112+
113+
114+
},
115+
})
116+
}
117+
118+
119+
90120
func getSegmentImportID(n string) resource.ImportStateIdFunc {
91121
return func(s *terraform.State) (string, error) {
92122
return getAttributefromState(s, n, "uuid")
@@ -137,3 +167,34 @@ resource "flagsmith_segment" "test_segment" {
137167
138168
`, segmentName, description, projectUUID())
139169
}
170+
171+
func testAccFeatureSegmentResourceConfig(segmentName string ) string {
172+
return fmt.Sprintf(`
173+
provider "flagsmith" {
174+
175+
}
176+
177+
resource "flagsmith_segment" "test_segment" {
178+
name = "%s"
179+
project_uuid = "%s"
180+
description = "new segment description"
181+
feature_id = %d
182+
rules = [
183+
{
184+
"rules" : [{
185+
"conditions" : [{
186+
"operator" : "EQUAL",
187+
"property" : "device_type",
188+
"value" : "mobile"
189+
}],
190+
"type" : "ANY"
191+
}],
192+
"type" : "ALL"
193+
194+
}
195+
]
196+
197+
}
198+
199+
`, segmentName, projectUUID(), featureID())
200+
}

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/Flagsmith/terraform-provider-flagsmith
22

3-
go 1.21
3+
go 1.22
44

55
toolchain go1.22.2
66

77
require (
88
github.com/Flagsmith/flagsmith-go-api-client v0.9.0
9-
github.com/hashicorp/terraform-plugin-docs v0.19.2
9+
github.com/hashicorp/terraform-plugin-docs v0.19.4
1010
github.com/hashicorp/terraform-plugin-framework v1.11.0
11-
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
11+
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
1212
github.com/hashicorp/terraform-plugin-go v0.23.0
1313
github.com/hashicorp/terraform-plugin-log v0.9.0
1414
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
@@ -44,8 +44,8 @@ require (
4444
github.com/hashicorp/go-multierror v1.1.1 // indirect
4545
github.com/hashicorp/go-plugin v1.6.0 // indirect
4646
github.com/hashicorp/go-uuid v1.0.3 // indirect
47-
github.com/hashicorp/go-version v1.6.0 // indirect
48-
github.com/hashicorp/hc-install v0.6.4 // indirect
47+
github.com/hashicorp/go-version v1.7.0 // indirect
48+
github.com/hashicorp/hc-install v0.7.0 // indirect
4949
github.com/hashicorp/hcl/v2 v2.20.1 // indirect
5050
github.com/hashicorp/logutils v1.0.0 // indirect
5151
github.com/hashicorp/terraform-exec v0.21.0 // indirect
@@ -77,7 +77,7 @@ require (
7777
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
7878
golang.org/x/crypto v0.23.0 // indirect
7979
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
80-
golang.org/x/mod v0.16.0 // indirect
80+
golang.org/x/mod v0.17.0 // indirect
8181
golang.org/x/net v0.23.0 // indirect
8282
golang.org/x/sys v0.20.0 // indirect
8383
golang.org/x/text v0.15.0 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/
8989
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
9090
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
9191
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
92-
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
93-
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
94-
github.com/hashicorp/hc-install v0.6.4 h1:QLqlM56/+SIIGvGcfFiwMY3z5WGXT066suo/v9Km8e0=
95-
github.com/hashicorp/hc-install v0.6.4/go.mod h1:05LWLy8TD842OtgcfBbOT0WMoInBMUSHjmDx10zuBIA=
92+
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
93+
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
94+
github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk=
95+
github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA=
9696
github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc=
9797
github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4=
9898
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
@@ -101,12 +101,12 @@ github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVW
101101
github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg=
102102
github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec=
103103
github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A=
104-
github.com/hashicorp/terraform-plugin-docs v0.19.2 h1:YjdKa1vuqt9EnPYkkrv9HnGZz175HhSJ7Vsn8yZeWus=
105-
github.com/hashicorp/terraform-plugin-docs v0.19.2/go.mod h1:gad2aP6uObFKhgNE8DR9nsEuEQnibp7il0jZYYOunWY=
104+
github.com/hashicorp/terraform-plugin-docs v0.19.4 h1:G3Bgo7J22OMtegIgn8Cd/CaSeyEljqjH3G39w28JK4c=
105+
github.com/hashicorp/terraform-plugin-docs v0.19.4/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA=
106106
github.com/hashicorp/terraform-plugin-framework v1.11.0 h1:M7+9zBArexHFXDx/pKTxjE6n/2UCXY6b8FIq9ZYhwfE=
107107
github.com/hashicorp/terraform-plugin-framework v1.11.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM=
108-
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
109-
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
108+
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E=
109+
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo=
110110
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=
111111
github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ=
112112
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
@@ -217,8 +217,8 @@ golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaU
217217
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
218218
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
219219
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
220-
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
221-
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
220+
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
221+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
222222
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
223223
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
224224
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=

0 commit comments

Comments
 (0)