Skip to content

Commit 1e9f842

Browse files
Merge pull request #955 from hashicorp/fix-no-code-upgrade
Fix no-code upgrade return value
2 parents e75d2b5 + 73d881f commit 1e9f842

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# UNRELEASED
22

3+
## Bug Fixes
4+
5+
* Fixed `RegistryNoCodeModules` method `UpgradeWorkspace` to return a `WorkspaceUpgrade` type. This resulted in a BREAKING CHANGE, yet the previous type was not properly decoded nor reflective of the actual API result by @paladin-devops [#955](https://github.com/hashicorp/go-tfe/pull/955)
6+
37
# v1.64.2
48

59
## Enhancements

mocks/registry_no_code_module_mocks.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

registry_no_code_module.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type RegistryNoCodeModules interface {
3838
CreateWorkspace(ctx context.Context, noCodeModuleID string, options *RegistryNoCodeModuleCreateWorkspaceOptions) (*Workspace, error)
3939

4040
// UpgradeWorkspace initiates an upgrade of an existing no-code module workspace.
41-
UpgradeWorkspace(ctx context.Context, noCodeModuleID string, workspaceID string, options *RegistryNoCodeModuleUpgradeWorkspaceOptions) (*Workspace, error)
41+
UpgradeWorkspace(ctx context.Context, noCodeModuleID string, workspaceID string, options *RegistryNoCodeModuleUpgradeWorkspaceOptions) (*WorkspaceUpgrade, error)
4242
}
4343

4444
type RegistryNoCodeModuleCreateWorkspaceOptions struct {
@@ -181,6 +181,19 @@ type RegistryNoCodeModuleUpdateOptions struct {
181181
VariableOptions []*NoCodeVariableOption `jsonapi:"relation,variable-options,omitempty"`
182182
}
183183

184+
// WorkspaceUpgrade contains the data returned by the no-code workspace upgrade
185+
// API endpoint.
186+
type WorkspaceUpgrade struct {
187+
// Status is the status of the run of the upgrade
188+
Status string `jsonapi:"attr,status"`
189+
190+
// PlanURL is the URL to the plan of the upgrade
191+
PlanURL string `jsonapi:"attr,plan-url"`
192+
193+
// Message is the message returned by the API when an upgrade is not available.
194+
Message string `jsonapi:"attr,message"`
195+
}
196+
184197
// Create a new registry no-code module
185198
func (r *registryNoCodeModules) Create(ctx context.Context, organization string, options RegistryNoCodeModuleCreateOptions) (*RegistryNoCodeModule, error) {
186199
if !validStringID(&organization) {
@@ -304,7 +317,7 @@ func (r *registryNoCodeModules) UpgradeWorkspace(
304317
noCodeModuleID string,
305318
workspaceID string,
306319
options *RegistryNoCodeModuleUpgradeWorkspaceOptions,
307-
) (*Workspace, error) {
320+
) (*WorkspaceUpgrade, error) {
308321
if err := options.valid(); err != nil {
309322
return nil, err
310323
}
@@ -318,13 +331,13 @@ func (r *registryNoCodeModules) UpgradeWorkspace(
318331
return nil, err
319332
}
320333

321-
w := &Workspace{}
322-
err = req.Do(ctx, w)
334+
wu := &WorkspaceUpgrade{}
335+
err = req.Do(ctx, wu)
323336
if err != nil {
324337
return nil, err
325338
}
326339

327-
return w, nil
340+
return wu, nil
328341
}
329342

330343
func (o RegistryNoCodeModuleCreateOptions) valid() error {

registry_no_code_module_integration_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,16 @@ func TestRegistryNoCodeModuleWorkspaceUpgrade(t *testing.T) {
470470
r.NotNil(uncm)
471471

472472
t.Run("test upgrading a workspace via a no-code module", func(t *testing.T) {
473-
ws, err := client.RegistryNoCodeModules.UpgradeWorkspace(
473+
wu, err := client.RegistryNoCodeModules.UpgradeWorkspace(
474474
ctx,
475475
ncm.ID,
476476
w.ID,
477477
&RegistryNoCodeModuleUpgradeWorkspaceOptions{},
478478
)
479479
r.NoError(err)
480-
r.NotNil(ws)
481-
r.Equal(w.ID, ws.ID)
480+
r.NotNil(wu)
481+
r.NotEmpty(wu.Status)
482+
r.NotEmpty(wu.PlanURL)
482483
})
483484

484485
t.Run("fail to upgrade workspace with invalid no-code module", func(t *testing.T) {

0 commit comments

Comments
 (0)