Skip to content

Commit 0595b83

Browse files
committed
working environment resource
1 parent 676e012 commit 0595b83

File tree

9 files changed

+71
-70
lines changed

9 files changed

+71
-70
lines changed

internal/provider/environment/resource_schema_test.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

internal/provider/environment/resource.go renamed to internal/provider/environments/resource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Package environment provides implementation of the Environment resource.
2-
package environment
1+
// Package environments provides implementation of the Environment resource.
2+
package environments
33

44
import (
55
"context"
@@ -37,7 +37,7 @@ type environmentResourceModel struct {
3737
UpdatedAt types.String `tfsdk:"updated_at"`
3838
}
3939

40-
// Create new Environment resource.
40+
// NewResource creates a new Environment resource.
4141
func NewResource() resource.Resource {
4242
return &environmentResource{}
4343
}
@@ -206,14 +206,14 @@ func (r *environmentResource) Update(ctx context.Context, req resource.UpdateReq
206206

207207
var operations []api.ReplaceOperation
208208

209-
// Check if name changed
209+
// Check if name changed.
210210
if !plan.Name.Equal(state.Name) {
211211
nameOp := api.NewReplaceOperation("replace", "/name")
212212
nameOp.Value = plan.Name.ValueStringPointer()
213213
operations = append(operations, *nameOp)
214214
}
215215

216-
// Check if description changed
216+
// Check if description changed.
217217
if !plan.Description.Equal(state.Description) {
218218
descOp := api.NewReplaceOperation("replace", "/description")
219219
if plan.Description.IsNull() {
@@ -224,14 +224,14 @@ func (r *environmentResource) Update(ctx context.Context, req resource.UpdateReq
224224
operations = append(operations, *descOp)
225225
}
226226

227-
// Check if color changed
227+
// Check if color changed.
228228
if !plan.Color.Equal(state.Color) {
229229
colorOp := api.NewReplaceOperation("replace", "/color")
230230
colorOp.Value = plan.Color.ValueStringPointer()
231231
operations = append(operations, *colorOp)
232232
}
233233

234-
// Only make the PATCH request if there are operations to perform
234+
// Only make the PATCH request if there are operations to perform.
235235
if len(operations) > 0 {
236236
patchRequest := api.NewEnvironmentsEnvironmentIdPatchRequest(operations)
237237
response, httpResponse, err := r.client.EnvironmentsAPI.EnvironmentsEnvironmentIdPatch(ctx, environmentID).EnvironmentsEnvironmentIdPatchRequest(*patchRequest).Execute()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package environments
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
// The fwresource import alias is so there is no collistion
8+
// with the more typical acceptance testing import:
9+
// "github.com/hashicorp/terraform-plugin-testing/helper/resource".
10+
fwresource "github.com/hashicorp/terraform-plugin-framework/resource"
11+
)
12+
13+
func TestEnvironmentResourceSchema(t *testing.T) {
14+
t.Parallel()
15+
16+
ctx := context.Background()
17+
schemaRequest := fwresource.SchemaRequest{}
18+
schemaResponse := &fwresource.SchemaResponse{}
19+
20+
// Instantiate the resource.Resource and call its Schema method.
21+
NewResource().Schema(ctx, schemaRequest, schemaResponse)
22+
23+
if schemaResponse.Diagnostics.HasError() {
24+
t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics)
25+
}
26+
27+
// Validate the schema.
28+
diagnostics := schemaResponse.Schema.ValidateImplementation(ctx)
29+
30+
if diagnostics.HasError() {
31+
t.Fatalf("Schema validation diagnostics: %+v", diagnostics)
32+
}
33+
}

internal/provider/environment/resource_test.go renamed to internal/provider/environments/resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package environment_test
1+
package environments_test
22

33
import (
44
"fmt"

internal/provider/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"golang.org/x/mod/semver"
2121

2222
"github.com/tryretool/terraform-provider-retool/internal/provider/configurationvariable"
23-
"github.com/tryretool/terraform-provider-retool/internal/provider/environment"
2423
"github.com/tryretool/terraform-provider-retool/internal/provider/environments"
2524
"github.com/tryretool/terraform-provider-retool/internal/provider/folder"
2625
"github.com/tryretool/terraform-provider-retool/internal/provider/group"
@@ -309,6 +308,6 @@ func (p *retoolProvider) Resources(_ context.Context) []func() resource.Resource
309308
sourcecontrol.NewResource,
310309
sourcecontrolsettings.NewResource,
311310
configurationvariable.NewResource,
312-
environment.NewResource,
311+
environments.NewResource,
313312
}
314313
}

terraform-provider-retool

16 Bytes
Binary file not shown.

test/data/recordings/TestAccEnvironment.yaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ interactions:
3030
trailer: {}
3131
content_length: 263
3232
uncompressed: false
33-
body: '{"success":true,"data":{"id":"6e2ae8ea-49e8-44d2-aee0-c63be29b108b","name":"test-environment","description":"Test environment for acceptance tests","color":"#FF5733","default":false,"created_at":"2025-11-13T01:09:11.652Z","updated_at":"2025-11-13T01:09:11.652Z"}}'
33+
body: '{"success":true,"data":{"id":"8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee","name":"test-environment","description":"Test environment for acceptance tests","color":"#FF5733","default":false,"created_at":"2025-11-13T01:18:10.910Z","updated_at":"2025-11-13T01:18:10.910Z"}}'
3434
headers:
3535
Content-Type:
3636
- application/json; charset=utf-8
3737
status: 200 OK
3838
code: 200
39-
duration: 3.390111666s
39+
duration: 3.42377175s
4040
- id: 1
4141
request:
4242
proto: HTTP/1.1
@@ -53,7 +53,7 @@ interactions:
5353
headers:
5454
User-Agent:
5555
- OpenAPI-Generator/1.0.0/go
56-
url: https://recorded.retool.dev/api/v2/environments/6e2ae8ea-49e8-44d2-aee0-c63be29b108b
56+
url: https://recorded.retool.dev/api/v2/environments/8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee
5757
method: GET
5858
response:
5959
proto: HTTP/1.1
@@ -63,13 +63,13 @@ interactions:
6363
trailer: {}
6464
content_length: 263
6565
uncompressed: false
66-
body: '{"success":true,"data":{"id":"6e2ae8ea-49e8-44d2-aee0-c63be29b108b","name":"test-environment","description":"Test environment for acceptance tests","color":"#FF5733","default":false,"created_at":"2025-11-13T01:09:11.652Z","updated_at":"2025-11-13T01:09:11.652Z"}}'
66+
body: '{"success":true,"data":{"id":"8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee","name":"test-environment","description":"Test environment for acceptance tests","color":"#FF5733","default":false,"created_at":"2025-11-13T01:18:10.910Z","updated_at":"2025-11-13T01:18:10.910Z"}}'
6767
headers:
6868
Content-Type:
6969
- application/json; charset=utf-8
7070
status: 200 OK
7171
code: 200
72-
duration: 32.338459ms
72+
duration: 63.933541ms
7373
- id: 2
7474
request:
7575
proto: HTTP/1.1
@@ -86,7 +86,7 @@ interactions:
8686
headers:
8787
User-Agent:
8888
- OpenAPI-Generator/1.0.0/go
89-
url: https://recorded.retool.dev/api/v2/environments/6e2ae8ea-49e8-44d2-aee0-c63be29b108b
89+
url: https://recorded.retool.dev/api/v2/environments/8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee
9090
method: GET
9191
response:
9292
proto: HTTP/1.1
@@ -96,13 +96,13 @@ interactions:
9696
trailer: {}
9797
content_length: 263
9898
uncompressed: false
99-
body: '{"success":true,"data":{"id":"6e2ae8ea-49e8-44d2-aee0-c63be29b108b","name":"test-environment","description":"Test environment for acceptance tests","color":"#FF5733","default":false,"created_at":"2025-11-13T01:09:11.652Z","updated_at":"2025-11-13T01:09:11.652Z"}}'
99+
body: '{"success":true,"data":{"id":"8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee","name":"test-environment","description":"Test environment for acceptance tests","color":"#FF5733","default":false,"created_at":"2025-11-13T01:18:10.910Z","updated_at":"2025-11-13T01:18:10.910Z"}}'
100100
headers:
101101
Content-Type:
102102
- application/json; charset=utf-8
103103
status: 200 OK
104104
code: 200
105-
duration: 31.19525ms
105+
duration: 34.708584ms
106106
- id: 3
107107
request:
108108
proto: HTTP/1.1
@@ -122,7 +122,7 @@ interactions:
122122
- application/json
123123
User-Agent:
124124
- OpenAPI-Generator/1.0.0/go
125-
url: https://recorded.retool.dev/api/v2/environments/6e2ae8ea-49e8-44d2-aee0-c63be29b108b
125+
url: https://recorded.retool.dev/api/v2/environments/8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee
126126
method: PATCH
127127
response:
128128
proto: HTTP/1.1
@@ -132,13 +132,13 @@ interactions:
132132
trailer: {}
133133
content_length: 258
134134
uncompressed: false
135-
body: '{"success":true,"data":{"id":"6e2ae8ea-49e8-44d2-aee0-c63be29b108b","name":"test-environment-updated","description":"Updated test environment","color":"#00FF00","default":false,"created_at":"2025-11-13T01:09:11.652Z","updated_at":"2025-11-13T01:09:15.337Z"}}'
135+
body: '{"success":true,"data":{"id":"8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee","name":"test-environment-updated","description":"Updated test environment","color":"#00FF00","default":false,"created_at":"2025-11-13T01:18:10.910Z","updated_at":"2025-11-13T01:18:14.751Z"}}'
136136
headers:
137137
Content-Type:
138138
- application/json; charset=utf-8
139139
status: 200 OK
140140
code: 200
141-
duration: 35.445166ms
141+
duration: 48.816208ms
142142
- id: 4
143143
request:
144144
proto: HTTP/1.1
@@ -155,7 +155,7 @@ interactions:
155155
headers:
156156
User-Agent:
157157
- OpenAPI-Generator/1.0.0/go
158-
url: https://recorded.retool.dev/api/v2/environments/6e2ae8ea-49e8-44d2-aee0-c63be29b108b
158+
url: https://recorded.retool.dev/api/v2/environments/8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee
159159
method: GET
160160
response:
161161
proto: HTTP/1.1
@@ -165,13 +165,13 @@ interactions:
165165
trailer: {}
166166
content_length: 258
167167
uncompressed: false
168-
body: '{"success":true,"data":{"id":"6e2ae8ea-49e8-44d2-aee0-c63be29b108b","name":"test-environment-updated","description":"Updated test environment","color":"#00FF00","default":false,"created_at":"2025-11-13T01:09:11.652Z","updated_at":"2025-11-13T01:09:15.337Z"}}'
168+
body: '{"success":true,"data":{"id":"8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee","name":"test-environment-updated","description":"Updated test environment","color":"#00FF00","default":false,"created_at":"2025-11-13T01:18:10.910Z","updated_at":"2025-11-13T01:18:14.751Z"}}'
169169
headers:
170170
Content-Type:
171171
- application/json; charset=utf-8
172172
status: 200 OK
173173
code: 200
174-
duration: 31.434958ms
174+
duration: 34.825542ms
175175
- id: 5
176176
request:
177177
proto: HTTP/1.1
@@ -188,7 +188,7 @@ interactions:
188188
headers:
189189
User-Agent:
190190
- OpenAPI-Generator/1.0.0/go
191-
url: https://recorded.retool.dev/api/v2/environments/6e2ae8ea-49e8-44d2-aee0-c63be29b108b
191+
url: https://recorded.retool.dev/api/v2/environments/8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee
192192
method: GET
193193
response:
194194
proto: HTTP/1.1
@@ -198,13 +198,13 @@ interactions:
198198
trailer: {}
199199
content_length: 258
200200
uncompressed: false
201-
body: '{"success":true,"data":{"id":"6e2ae8ea-49e8-44d2-aee0-c63be29b108b","name":"test-environment-updated","description":"Updated test environment","color":"#00FF00","default":false,"created_at":"2025-11-13T01:09:11.652Z","updated_at":"2025-11-13T01:09:15.337Z"}}'
201+
body: '{"success":true,"data":{"id":"8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee","name":"test-environment-updated","description":"Updated test environment","color":"#00FF00","default":false,"created_at":"2025-11-13T01:18:10.910Z","updated_at":"2025-11-13T01:18:14.751Z"}}'
202202
headers:
203203
Content-Type:
204204
- application/json; charset=utf-8
205205
status: 200 OK
206206
code: 200
207-
duration: 34.7465ms
207+
duration: 32.043625ms
208208
- id: 6
209209
request:
210210
proto: HTTP/1.1
@@ -221,7 +221,7 @@ interactions:
221221
headers:
222222
User-Agent:
223223
- OpenAPI-Generator/1.0.0/go
224-
url: https://recorded.retool.dev/api/v2/environments/6e2ae8ea-49e8-44d2-aee0-c63be29b108b
224+
url: https://recorded.retool.dev/api/v2/environments/8c951d2d-ac54-4175-b8d0-fe3da8b4c3ee
225225
method: DELETE
226226
response:
227227
proto: HTTP/1.1
@@ -235,4 +235,4 @@ interactions:
235235
headers: {}
236236
status: 204 No Content
237237
code: 204
238-
duration: 37.480959ms
238+
duration: 34.380667ms

test/data/recordings/TestAccEnvironmentWithoutDescription.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ interactions:
3030
trailer: {}
3131
content_length: 236
3232
uncompressed: false
33-
body: '{"success":true,"data":{"id":"6e88f310-eea9-4e7b-b8ab-6d3b521f73ac","name":"test-environment-no-desc","description":null,"color":"#0000FF","default":false,"created_at":"2025-11-13T01:09:11.611Z","updated_at":"2025-11-13T01:09:11.611Z"}}'
33+
body: '{"success":true,"data":{"id":"72fd47f5-6315-4cce-bf7e-082eb6c7be96","name":"test-environment-no-desc","description":null,"color":"#0000FF","default":false,"created_at":"2025-11-13T01:18:10.996Z","updated_at":"2025-11-13T01:18:10.996Z"}}'
3434
headers:
3535
Content-Type:
3636
- application/json; charset=utf-8
3737
status: 200 OK
3838
code: 200
39-
duration: 3.137612458s
39+
duration: 3.456174125s
4040
- id: 1
4141
request:
4242
proto: HTTP/1.1
@@ -53,7 +53,7 @@ interactions:
5353
headers:
5454
User-Agent:
5555
- OpenAPI-Generator/1.0.0/go
56-
url: https://recorded.retool.dev/api/v2/environments/6e88f310-eea9-4e7b-b8ab-6d3b521f73ac
56+
url: https://recorded.retool.dev/api/v2/environments/72fd47f5-6315-4cce-bf7e-082eb6c7be96
5757
method: GET
5858
response:
5959
proto: HTTP/1.1
@@ -63,13 +63,13 @@ interactions:
6363
trailer: {}
6464
content_length: 236
6565
uncompressed: false
66-
body: '{"success":true,"data":{"id":"6e88f310-eea9-4e7b-b8ab-6d3b521f73ac","name":"test-environment-no-desc","description":null,"color":"#0000FF","default":false,"created_at":"2025-11-13T01:09:11.611Z","updated_at":"2025-11-13T01:09:11.611Z"}}'
66+
body: '{"success":true,"data":{"id":"72fd47f5-6315-4cce-bf7e-082eb6c7be96","name":"test-environment-no-desc","description":null,"color":"#0000FF","default":false,"created_at":"2025-11-13T01:18:10.996Z","updated_at":"2025-11-13T01:18:10.996Z"}}'
6767
headers:
6868
Content-Type:
6969
- application/json; charset=utf-8
7070
status: 200 OK
7171
code: 200
72-
duration: 33.512375ms
72+
duration: 51.932084ms
7373
- id: 2
7474
request:
7575
proto: HTTP/1.1
@@ -86,7 +86,7 @@ interactions:
8686
headers:
8787
User-Agent:
8888
- OpenAPI-Generator/1.0.0/go
89-
url: https://recorded.retool.dev/api/v2/environments/6e88f310-eea9-4e7b-b8ab-6d3b521f73ac
89+
url: https://recorded.retool.dev/api/v2/environments/72fd47f5-6315-4cce-bf7e-082eb6c7be96
9090
method: DELETE
9191
response:
9292
proto: HTTP/1.1
@@ -100,4 +100,4 @@ interactions:
100100
headers: {}
101101
status: 204 No Content
102102
code: 204
103-
duration: 37.141958ms
103+
duration: 38.388291ms

test/data/recordings/TestAccEnvironmentsDataSource.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interactions:
3333
- application/json; charset=utf-8
3434
status: 200 OK
3535
code: 200
36-
duration: 69.57075ms
36+
duration: 83.215791ms
3737
- id: 1
3838
request:
3939
proto: HTTP/1.1
@@ -66,7 +66,7 @@ interactions:
6666
- application/json; charset=utf-8
6767
status: 200 OK
6868
code: 200
69-
duration: 35.446709ms
69+
duration: 47.441334ms
7070
- id: 2
7171
request:
7272
proto: HTTP/1.1
@@ -99,4 +99,4 @@ interactions:
9999
- application/json; charset=utf-8
100100
status: 200 OK
101101
code: 200
102-
duration: 34.679042ms
102+
duration: 45.353791ms

0 commit comments

Comments
 (0)