Skip to content

Commit

Permalink
Merge pull request #718 from hashicorp/kirch/update_agent_pool_allowe…
Browse files Browse the repository at this point in the history
…d_workspaces

Re-add allowed-workspaces field to AgentPoolUpdateOptions
  • Loading branch information
brandonc authored Jun 9, 2023
2 parents b01ef71 + 2f3f628 commit fd8ca3c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ type AgentPoolUpdateOptions struct {

// True if the agent pool is organization scoped, false otherwise.
OrganizationScoped *bool `jsonapi:"attr,organization-scoped,omitempty"`

// A new list of workspaces that are associated with an agent pool.
AllowedWorkspaces []*Workspace `jsonapi:"relation,allowed-workspaces,omitempty"`
}

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

// Update an agent pool by its ID.
// **Note:** This method cannot be used to clear the allowed workspaces field, instead use UpdateAllowedWorkspaces
func (s *agentPools) Update(ctx context.Context, agentPoolID string, options AgentPoolUpdateOptions) (*AgentPool, error) {
if !validStringID(&agentPoolID) {
return nil, ErrInvalidAgentPoolID
Expand Down
20 changes: 20 additions & 0 deletions agent_pool_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,26 @@ func TestAgentPoolsUpdate(t *testing.T) {
assert.NotEqual(t, kBefore.OrganizationScoped, kAfter.OrganizationScoped)
assert.Equal(t, organizationScoped, kAfter.OrganizationScoped)
})

t.Run("when updating allowed-workspaces", func(t *testing.T) {
kBefore, kTestCleanup := createAgentPool(t, client, orgTest)
defer kTestCleanup()

workspaceTest, workspaceTestCleanup := createWorkspace(t, client, orgTest)
defer workspaceTestCleanup()

kAfter, err := client.AgentPools.Update(ctx, kBefore.ID, AgentPoolUpdateOptions{
AllowedWorkspaces: []*Workspace{
workspaceTest,
},
})
require.NoError(t, err)

assert.Equal(t, kBefore.Name, kAfter.Name)
assert.NotEqual(t, kBefore.AllowedWorkspaces, kAfter.AllowedWorkspaces)
assert.Equal(t, 1, len(kAfter.AllowedWorkspaces))
assert.Equal(t, workspaceTest.ID, kAfter.AllowedWorkspaces[0].ID)
})
}

func TestAgentPoolsUpdateAllowedWorkspaces(t *testing.T) {
Expand Down

0 comments on commit fd8ca3c

Please sign in to comment.