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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for new organization-specific workspace limit setting #425

Merged
merged 1 commit into from Jul 5, 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
Expand Up @@ -4,6 +4,7 @@
* Adds `RetryServerErrors` field to the `Config` object by @sebasslash [#439](https://github.com/hashicorp/go-tfe/pull/439)
* Adds support for the GPG Keys API by @sebasslash [#429](https://github.com/hashicorp/go-tfe/pull/429)
* [beta] Renames the optional StateVersion field `ExtState` to `JSONState` and changes to string for base64 encoding by @annawinkler [#444](https://github.com/hashicorp/go-tfe/pull/444)
* Add support for new `WorkspaceLimit` Admin setting for organizations [#425](https://github.com/hashicorp/go-tfe/pull/425)

# v1.3.0

Expand Down
2 changes: 2 additions & 0 deletions admin_organization.go
Expand Up @@ -50,6 +50,7 @@ type AdminOrganization struct {
TerraformBuildWorkerApplyTimeout string `jsonapi:"attr,terraform-build-worker-apply-timeout"`
TerraformBuildWorkerPlanTimeout string `jsonapi:"attr,terraform-build-worker-plan-timeout"`
TerraformWorkerSudoEnabled bool `jsonapi:"attr,terraform-worker-sudo-enabled"`
WorkspaceLimit *int `jsonapi:"attr,workspace-limit"`

// Relations
Owners []*User `jsonapi:"relation,owners"`
Expand All @@ -64,6 +65,7 @@ type AdminOrganizationUpdateOptions struct {
TerraformBuildWorkerApplyTimeout *string `jsonapi:"attr,terraform-build-worker-apply-timeout,omitempty"`
TerraformBuildWorkerPlanTimeout *string `jsonapi:"attr,terraform-build-worker-plan-timeout,omitempty"`
TerraformWorkerSudoEnabled bool `jsonapi:"attr,terraform-worker-sudo-enabled,omitempty"`
WorkspaceLimit *int `jsonapi:"attr,workspace-limit,omitempty"`
}

// AdminOrganizationList represents a list of organizations via Admin API.
Expand Down
15 changes: 12 additions & 3 deletions admin_organization_integration_test.go
Expand Up @@ -106,6 +106,7 @@ func TestAdminOrganizations_Read(t *testing.T) {
assert.NotNilf(t, adminOrg.NotificationEmail, "NotificationEmail is not nil")
assert.NotNilf(t, adminOrg.SsoEnabled, "SsoEnabled is not nil")
assert.NotNilf(t, adminOrg.TerraformWorkerSudoEnabled, "TerraformWorkerSudoEnabledis not nil")
assert.Nilf(t, adminOrg.WorkspaceLimit, "WorkspaceLimit is nil")
})
}

Expand Down Expand Up @@ -238,39 +239,47 @@ func TestAdminOrganizations_Update(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, accessBetaTools, adminOrg.AccessBetaTools)
assert.Equal(t, globalModuleSharing, adminOrg.GlobalModuleSharing)
assert.Equal(t, adminOrg.GlobalModuleSharing, &globalModuleSharing)
assert.Equal(t, isDisabled, adminOrg.IsDisabled)
assert.Equal(t, terraformBuildWorkerApplyTimeout, adminOrg.TerraformBuildWorkerApplyTimeout)
assert.Equal(t, terraformBuildWorkerPlanTimeout, adminOrg.TerraformBuildWorkerPlanTimeout)
assert.Equal(t, terraformWorkerSudoEnabled, adminOrg.TerraformWorkerSudoEnabled)
assert.Nil(t, adminOrg.WorkspaceLimit, "default workspace limit should be nil")

isDisabled = true
globalModuleSharing = true
workspaceLimit := 42
opts = AdminOrganizationUpdateOptions{
GlobalModuleSharing: &globalModuleSharing,
IsDisabled: &isDisabled,
WorkspaceLimit: &workspaceLimit,
}

adminOrg, err = client.Admin.Organizations.Update(ctx, org.Name, opts)
assert.NoError(t, err)
assert.NotNilf(t, adminOrg, "Org returned as nil when it shouldn't be.")

assert.Equal(t, adminOrg.GlobalModuleSharing, globalModuleSharing)
assert.Equal(t, adminOrg.GlobalModuleSharing, &globalModuleSharing)
assert.Equal(t, adminOrg.IsDisabled, isDisabled)
assert.Equal(t, &workspaceLimit, adminOrg.WorkspaceLimit)

globalModuleSharing = false
isDisabled = false
workspaceLimit = 0
opts = AdminOrganizationUpdateOptions{
GlobalModuleSharing: &globalModuleSharing,
IsDisabled: &isDisabled,
WorkspaceLimit: &workspaceLimit,
}

adminOrg, err = client.Admin.Organizations.Update(ctx, org.Name, opts)
assert.NoError(t, err)
assert.NotNilf(t, adminOrg, "Org returned as nil when it shouldn't be.")

assert.Equal(t, adminOrg.GlobalModuleSharing, globalModuleSharing)
assert.Equal(t, &globalModuleSharing, adminOrg.GlobalModuleSharing)
Comment on lines -272 to +279
Copy link
Collaborator

@brandonc brandonc Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by the argument swapping here and on L241. The other assertions seem to put the parameter second and the model first. And also by the address operator. What's going on?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that I had to make a few changes to the existing test (specifically, assertions about the GlobalModuleSharing flag) in order to get these tests to pass. Since those tests don't get run in CI, I'm thinking they probably haven't run in a long while.

OK ! Nevermind !

assert.Equal(t, adminOrg.IsDisabled, isDisabled)

assert.Equal(t, &workspaceLimit, adminOrg.WorkspaceLimit)
})
}

Expand Down
2 changes: 1 addition & 1 deletion docs/TESTS.md
Expand Up @@ -12,7 +12,7 @@ Your registry module repository will need to be a [valid module](https://www.ter
It will need the following:
1. To be named `terraform-<PROVIDER>-<NAME>`
1. At least one valid SemVer tag in the format `x.y.z`
[terraform-random-module](ttps://github.com/caseylang/terraform-random-module) is a good example repo.
[terraform-random-module](https://github.com/caseylang/terraform-random-module) is a good example repo.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small little typo fix that I didn't think was worth a second PR, so I snuck it in here 馃シ


## 2. Set up environment variables (ENVVARS)

Expand Down