Skip to content

Commit 189b52e

Browse files
committed
fix: invalid include value when reading workspace
1 parent aa0ecd3 commit 189b52e

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

internal/provider/resource_tfe_workspace_settings.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,21 @@ func (r *workspaceSettings) Read(ctx context.Context, req resource.ReadRequest,
461461
}
462462

463463
func (r *workspaceSettings) readSettings(ctx context.Context, workspaceID string) (*modelWorkspaceSettings, error) {
464+
log.Printf("[DEBUG] Read configuration of workspace: %s", workspaceID)
464465
ws, err := r.config.Client.Workspaces.ReadByIDWithOptions(ctx, workspaceID, &tfe.WorkspaceReadOptions{
465466
Include: []tfe.WSIncludeOpt{tfe.WSEffectiveTagBindings},
466467
})
467-
468-
if err != nil {
469-
// If it's gone: that's not an error, but we are done.
470-
if errors.Is(err, tfe.ErrResourceNotFound) {
471-
log.Printf("[DEBUG] Workspace %s no longer exists", workspaceID)
472-
return nil, errWorkspaceNoLongerExists
468+
if err != nil && errors.Is(err, tfe.ErrInvalidIncludeValue) {
469+
log.Printf("[DEBUG] Workspace %s read failed due to unsupported Include; retrying without it", workspaceID)
470+
ws, err = r.config.Client.Workspaces.ReadByID(ctx, workspaceID)
471+
if err != nil && errors.Is(err, tfe.ErrResourceNotFound) {
472+
return nil, err
473+
} else if err != nil {
474+
return nil, fmt.Errorf("Error reading workspace %s without include: %w", workspaceID, err)
473475
}
474-
return nil, fmt.Errorf("couldn't read workspace %s: %s", workspaceID, err.Error())
476+
}
477+
if err != nil {
478+
return nil, fmt.Errorf("Error reading configuration of workspace %s: %w", workspaceID, err)
475479
}
476480

477481
return r.workspaceSettingsModelFromTFEWorkspace(ws), nil
@@ -531,11 +535,15 @@ func (r *workspaceSettings) updateSettings(ctx context.Context, data *modelWorks
531535
}
532536

533537
model, err := r.readSettings(ctx, ws.ID)
534-
if err != nil {
535-
return fmt.Errorf("couldn't read workspace %s after update: %w", workspaceID, err)
538+
if errors.Is(err, errWorkspaceNoLongerExists) {
539+
state.RemoveResource(ctx)
536540
}
537-
state.Set(ctx, model)
538-
return nil
541+
542+
if err == nil {
543+
state.Set(ctx, model)
544+
}
545+
546+
return err
539547
}
540548

541549
func (r *workspaceSettings) addAndRemoveRemoteStateConsumers(workspaceID string, newWorkspaceIDsSet types.Set, state *tfsdk.State) error {

0 commit comments

Comments
 (0)