Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API Changes for Agent Pools to Workspaces Feature #453

Merged
merged 9 commits into from Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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{
Netra2104 marked this conversation as resolved.
Show resolved Hide resolved
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