Skip to content

Commit 2bf0f5f

Browse files
authored
Merge pull request #1060 from hashicorp/mkam/TF-24090/default-project-nullable
Support unsetting an organization's default project
2 parents ea37352 + 59cb53f commit 2bf0f5f

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/go-slug v0.16.4
1010
github.com/hashicorp/go-uuid v1.0.3
1111
github.com/hashicorp/go-version v1.7.0
12-
github.com/hashicorp/jsonapi v1.4.1
12+
github.com/hashicorp/jsonapi v1.4.3-0.20250220162346-81a76b606f3e
1313
github.com/stretchr/testify v1.10.0
1414
go.uber.org/mock v0.4.0
1515
golang.org/x/sync v0.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
1616
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
1717
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
1818
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
19-
github.com/hashicorp/jsonapi v1.4.1 h1:U6CZvnS70Sg7im0kpfhWAoF3NasLumaMndQhEWniHZA=
20-
github.com/hashicorp/jsonapi v1.4.1/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
19+
github.com/hashicorp/jsonapi v1.4.3-0.20250220162346-81a76b606f3e h1:xwy/1T0cxHWaLx2MM0g4BlaQc1BXn/9835mPrBqwSPU=
20+
github.com/hashicorp/jsonapi v1.4.3-0.20250220162346-81a76b606f3e/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
2121
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2222
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
2323
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

organization.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"fmt"
99
"net/url"
1010
"time"
11+
12+
"github.com/hashicorp/jsonapi"
1113
)
1214

1315
// Compile-time proof of interface implementation.
@@ -314,7 +316,7 @@ type OrganizationUpdateOptions struct {
314316

315317
// Optional: DefaultProject is the default project that workspaces are created in when no project is specified.
316318
// This setting is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
317-
DefaultProject *Project `jsonapi:"relation,default-project,omitempty"`
319+
DefaultProject jsonapi.NullableRelationship[*Project] `jsonapi:"relation,default-project,omitempty"`
318320
}
319321

320322
// ReadRunQueueOptions represents the options for showing the queue.

organization_integration_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/hashicorp/jsonapi"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
1516
)
@@ -400,14 +401,34 @@ func TestOrganizationsUpdate(t *testing.T) {
400401

401402
// Update the default project and verify the change
402403
updated, err := client.Organizations.Update(ctx, org.Name, OrganizationUpdateOptions{
403-
DefaultProject: proj,
404+
DefaultProject: jsonapi.NewNullableRelationshipWithValue[*Project](proj),
404405
})
405406
require.NoError(t, err)
406407
require.Equal(t, proj.ID, updated.DefaultProject.ID)
407408

408409
fetched, err := client.Organizations.Read(ctx, org.Name)
409410
require.NoError(t, err)
410411
require.Equal(t, proj.ID, fetched.DefaultProject.ID)
412+
413+
// Update without setting default project and verify no changes
414+
updated, err = client.Organizations.Update(ctx, org.Name, OrganizationUpdateOptions{})
415+
require.NoError(t, err)
416+
require.Equal(t, proj.ID, updated.DefaultProject.ID)
417+
418+
fetched, err = client.Organizations.Read(ctx, org.Name)
419+
require.NoError(t, err)
420+
require.Equal(t, proj.ID, fetched.DefaultProject.ID)
421+
422+
// Update the setting to an explicit null value and verify it is unset
423+
deleted, err := client.Organizations.Update(ctx, org.Name, OrganizationUpdateOptions{
424+
DefaultProject: jsonapi.NewNullNullableRelationship[*Project](),
425+
})
426+
require.NoError(t, err)
427+
require.Nil(t, deleted.DefaultProject)
428+
429+
fetched, err = client.Organizations.Read(ctx, org.Name)
430+
require.NoError(t, err)
431+
require.Nil(t, fetched.DefaultProject)
411432
})
412433
}
413434

0 commit comments

Comments
 (0)