Skip to content

Commit fd8ca3c

Browse files
authored
Merge pull request #718 from hashicorp/kirch/update_agent_pool_allowed_workspaces
Re-add allowed-workspaces field to AgentPoolUpdateOptions
2 parents b01ef71 + 2f3f628 commit fd8ca3c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

agent_pool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ type AgentPoolUpdateOptions struct {
196196

197197
// True if the agent pool is organization scoped, false otherwise.
198198
OrganizationScoped *bool `jsonapi:"attr,organization-scoped,omitempty"`
199+
200+
// A new list of workspaces that are associated with an agent pool.
201+
AllowedWorkspaces []*Workspace `jsonapi:"relation,allowed-workspaces,omitempty"`
199202
}
200203

201204
// AgentPoolUpdateAllowedWorkspacesOptions represents the options for updating the allowed workspace on an agent pool
@@ -211,6 +214,7 @@ type AgentPoolAllowedWorkspacesUpdateOptions struct {
211214
}
212215

213216
// Update an agent pool by its ID.
217+
// **Note:** This method cannot be used to clear the allowed workspaces field, instead use UpdateAllowedWorkspaces
214218
func (s *agentPools) Update(ctx context.Context, agentPoolID string, options AgentPoolUpdateOptions) (*AgentPool, error) {
215219
if !validStringID(&agentPoolID) {
216220
return nil, ErrInvalidAgentPoolID

agent_pool_integration_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,26 @@ func TestAgentPoolsUpdate(t *testing.T) {
316316
assert.NotEqual(t, kBefore.OrganizationScoped, kAfter.OrganizationScoped)
317317
assert.Equal(t, organizationScoped, kAfter.OrganizationScoped)
318318
})
319+
320+
t.Run("when updating allowed-workspaces", func(t *testing.T) {
321+
kBefore, kTestCleanup := createAgentPool(t, client, orgTest)
322+
defer kTestCleanup()
323+
324+
workspaceTest, workspaceTestCleanup := createWorkspace(t, client, orgTest)
325+
defer workspaceTestCleanup()
326+
327+
kAfter, err := client.AgentPools.Update(ctx, kBefore.ID, AgentPoolUpdateOptions{
328+
AllowedWorkspaces: []*Workspace{
329+
workspaceTest,
330+
},
331+
})
332+
require.NoError(t, err)
333+
334+
assert.Equal(t, kBefore.Name, kAfter.Name)
335+
assert.NotEqual(t, kBefore.AllowedWorkspaces, kAfter.AllowedWorkspaces)
336+
assert.Equal(t, 1, len(kAfter.AllowedWorkspaces))
337+
assert.Equal(t, workspaceTest.ID, kAfter.AllowedWorkspaces[0].ID)
338+
})
319339
}
320340

321341
func TestAgentPoolsUpdateAllowedWorkspaces(t *testing.T) {

0 commit comments

Comments
 (0)