Skip to content

Commit

Permalink
Add API Changes for Agent Pools to Workspaces Feature (#453)
Browse files Browse the repository at this point in the history
* added tests for agent pools

* pointer fix

* test fix

* more fixes

* added omit attribute

* removed pointer from AgentPool

* added change logs

* unnecessary change removed

* ran go fmt
  • Loading branch information
Netra2104 committed Jul 12, 2022
1 parent 11709cb commit 0568f29
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Unreleased

* [beta] Add support for triggering Workspace runs through matching Git tags [#434](https://github.com/hashicorp/go-tfe/pull/434)
* Add organization scope and allowed workspaces field for scope agents by @Netra2104 [#453](https://github.com/hashicorp/go-tfe/pull/453)

## Bug fixes
* Fixed JSON mapping for Configuration Versions failing to properly set the `speculative` property [#459](https://github.com/hashicorp/go-tfe/pull/459)
Expand Down
16 changes: 12 additions & 4 deletions agent_pool.go
Expand Up @@ -46,12 +46,14 @@ type AgentPoolList struct {

// AgentPool represents a Terraform Cloud agent pool.
type AgentPool struct {
ID string `jsonapi:"primary,agent-pools"`
Name string `jsonapi:"attr,name"`
ID string `jsonapi:"primary,agent-pools"`
Name string `jsonapi:"attr,name"`
OrganizationScoped bool `jsonapi:"attr,organization-scoped"`

// Relations
Organization *Organization `jsonapi:"relation,organization"`
Workspaces []*Workspace `jsonapi:"relation,workspaces"`
Organization *Organization `jsonapi:"relation,organization"`
Workspaces []*Workspace `jsonapi:"relation,workspaces"`
AllowedWorkspaces []*Workspace `jsonapi:"relation,allowed-workspaces"`
}

// A list of relations to include
Expand Down Expand Up @@ -172,6 +174,12 @@ type AgentPoolUpdateOptions struct {

// A new name to identify the agent pool.
Name *string `jsonapi:"attr,name"`

// 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"`
}

// Update an agent pool by its ID.
Expand Down
35 changes: 35 additions & 0 deletions agent_pool_integration_test.go
Expand Up @@ -200,6 +200,41 @@ func TestAgentPoolsUpdate(t *testing.T) {
assert.Nil(t, w)
assert.EqualError(t, err, ErrInvalidAgentPoolID.Error())
})

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{
Name: String(kBefore.Name),
AllowedWorkspaces: []*Workspace{
workspaceTest,
},
})
require.NoError(t, err)

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

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

organizationScoped := false
kAfter, err := client.AgentPools.Update(ctx, kBefore.ID, AgentPoolUpdateOptions{
Name: String(kBefore.Name),
OrganizationScoped: &organizationScoped,
})
require.NoError(t, err)

assert.NotEqual(t, kBefore.OrganizationScoped, kAfter.OrganizationScoped)
assert.Equal(t, organizationScoped, kAfter.OrganizationScoped)
})
}

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

0 comments on commit 0568f29

Please sign in to comment.