Skip to content

Commit

Permalink
Add Waypoint entitlements for organizations
Browse files Browse the repository at this point in the history
These changes add to the organizational entitlement struct to be able to
utilize the new Waypoint-based entitlements granted with HCP Terraform
feature sets:

- waypoint-actions
- waypoint-templates-and-addons
  • Loading branch information
ignatius-j committed Oct 1, 2024
1 parent 0b3525a commit efb6dc2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
28 changes: 15 additions & 13 deletions organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,21 @@ type Capacity struct {

// Entitlements represents the entitlements of an organization.
type Entitlements struct {
ID string `jsonapi:"primary,entitlement-sets"`
Agents bool `jsonapi:"attr,agents"`
AuditLogging bool `jsonapi:"attr,audit-logging"`
CostEstimation bool `jsonapi:"attr,cost-estimation"`
GlobalRunTasks bool `jsonapi:"attr,global-run-tasks"`
Operations bool `jsonapi:"attr,operations"`
PrivateModuleRegistry bool `jsonapi:"attr,private-module-registry"`
RunTasks bool `jsonapi:"attr,run-tasks"`
SSO bool `jsonapi:"attr,sso"`
Sentinel bool `jsonapi:"attr,sentinel"`
StateStorage bool `jsonapi:"attr,state-storage"`
Teams bool `jsonapi:"attr,teams"`
VCSIntegrations bool `jsonapi:"attr,vcs-integrations"`
ID string `jsonapi:"primary,entitlement-sets"`
Agents bool `jsonapi:"attr,agents"`
AuditLogging bool `jsonapi:"attr,audit-logging"`
CostEstimation bool `jsonapi:"attr,cost-estimation"`
GlobalRunTasks bool `jsonapi:"attr,global-run-tasks"`
Operations bool `jsonapi:"attr,operations"`
PrivateModuleRegistry bool `jsonapi:"attr,private-module-registry"`
RunTasks bool `jsonapi:"attr,run-tasks"`
SSO bool `jsonapi:"attr,sso"`
Sentinel bool `jsonapi:"attr,sentinel"`
StateStorage bool `jsonapi:"attr,state-storage"`
Teams bool `jsonapi:"attr,teams"`
VCSIntegrations bool `jsonapi:"attr,vcs-integrations"`
WaypointActions bool `jsonapi:"attr,waypoint-actions"`
WaypointTemplatesAndAddons bool `jsonapi:"attr,waypoint-templates-and-addons"`
}

// RunQueue represents the current run queue of an organization.
Expand Down
6 changes: 5 additions & 1 deletion organization_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ func TestOrganizationsReadEntitlements(t *testing.T) {
ctx := context.Background()

orgTest, orgTestCleanup := createOrganization(t, client)
t.Cleanup(orgTestCleanup)
defer orgTestCleanup()

newSubscriptionUpdater(orgTest).WithPlusEntitlementPlan().Update(t)

t.Run("when the org exists", func(t *testing.T) {
entitlements, err := client.Organizations.ReadEntitlements(ctx, orgTest.Name)
Expand All @@ -473,6 +475,8 @@ func TestOrganizationsReadEntitlements(t *testing.T) {
assert.True(t, entitlements.StateStorage)
assert.True(t, entitlements.Teams)
assert.True(t, entitlements.VCSIntegrations)
assert.True(t, entitlements.WaypointActions)
assert.True(t, entitlements.WaypointTemplatesAndAddons)
})

t.Run("with invalid name", func(t *testing.T) {
Expand Down
24 changes: 19 additions & 5 deletions subscription_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ type featureSetListOptions struct {
type retryableFn func() (interface{}, error)

type updateFeatureSetOptions struct {
Type string `jsonapi:"primary,subscription"`
RunsCeiling *int `jsonapi:"attr,runs-ceiling,omitempty"`
ContractStartAt *time.Time `jsonapi:"attr,contract-start-at,iso8601,omitempty"`
ContractUserLimit *int `jsonapi:"attr,contract-user-limit,omitempty"`
ContractApplyLimit *int `jsonapi:"attr,contract-apply-limit,omitempty"`
Type string `jsonapi:"primary,subscription"`
RunsCeiling *int `jsonapi:"attr,runs-ceiling,omitempty"`
ContractStartAt *time.Time `jsonapi:"attr,contract-start-at,iso8601,omitempty"`
ContractUserLimit *int `jsonapi:"attr,contract-user-limit,omitempty"`
ContractApplyLimit *int `jsonapi:"attr,contract-apply-limit,omitempty"`
ContractManagedResourcesLimit *int `jsonapi:"attr,contract-managed-resources-limit,omitempty"`

FeatureSet *featureSet `jsonapi:"relation,feature-set"`
}
Expand Down Expand Up @@ -71,6 +72,19 @@ func (b *organizationSubscriptionUpdater) WithTrialPlan() *organizationSubscript
return b
}

func (b *organizationSubscriptionUpdater) WithPlusEntitlementPlan() *organizationSubscriptionUpdater {
b.planName = "Plus (entitlement)"

start := time.Now()
ceiling := 1
managedResourcesLimit := 1000

b.updateOpts.ContractStartAt = &start
b.updateOpts.RunsCeiling = &ceiling
b.updateOpts.ContractManagedResourcesLimit = &managedResourcesLimit
return b
}

// Attempts to change an organization's subscription to a different plan. Requires a user token with admin access.
func (b *organizationSubscriptionUpdater) Update(t *testing.T) {
if enterpriseEnabled() {
Expand Down

0 comments on commit efb6dc2

Please sign in to comment.