Skip to content

Commit 1582807

Browse files
authored
Merge pull request #1788 from hashicorp/TF-27643-terraform-provider-tfe-gh-issue-1786-error-reading-workspace-over-tfe-workspace-settings-with-0-68-0
fix: invalid include value when reading workspace
2 parents aa0ecd3 + 9afee44 commit 1582807

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
BUG FIXES:
66
* `r/tfe_workspace_settings`: remove the schema default for auto_apply in case it is managed by `r/tfe_workspace` [#1787](https://github.com/hashicorp/terraform-provider-tfe/pull/1787)
7+
* `r/tfe_workspace_settings`: fixes an error when reading the workspace about an invalid include value when used with some versions of Terraform Enterprise [#1788](https://github.com/hashicorp/terraform-provider-tfe/pull/1788)
78

89
## v0.68.0
910

internal/provider/resource_tfe_workspace_settings.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,25 @@ 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.
468+
if errors.Is(err, tfe.ErrResourceNotFound) {
469+
log.Printf("[DEBUG] Workspace %s no longer exists", workspaceID)
470+
return nil, errWorkspaceNoLongerExists
471+
} else if errors.Is(err, tfe.ErrInvalidIncludeValue) {
472+
log.Printf("[DEBUG] Workspace %s read failed due to unsupported Include; retrying without it", workspaceID)
473+
ws, err = r.config.Client.Workspaces.ReadByID(ctx, workspaceID)
470474
if errors.Is(err, tfe.ErrResourceNotFound) {
471-
log.Printf("[DEBUG] Workspace %s no longer exists", workspaceID)
472475
return nil, errWorkspaceNoLongerExists
476+
} else if err != nil {
477+
return nil, fmt.Errorf("Error reading workspace %s without include: %w", workspaceID, err)
473478
}
474-
return nil, fmt.Errorf("couldn't read workspace %s: %s", workspaceID, err.Error())
479+
}
480+
481+
if err != nil {
482+
return nil, fmt.Errorf("Error reading configuration of workspace %s: %w", workspaceID, err)
475483
}
476484

477485
return r.workspaceSettingsModelFromTFEWorkspace(ws), nil
@@ -531,11 +539,15 @@ func (r *workspaceSettings) updateSettings(ctx context.Context, data *modelWorks
531539
}
532540

533541
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)
542+
if errors.Is(err, errWorkspaceNoLongerExists) {
543+
state.RemoveResource(ctx)
536544
}
537-
state.Set(ctx, model)
538-
return nil
545+
546+
if err == nil {
547+
state.Set(ctx, model)
548+
}
549+
550+
return err
539551
}
540552

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

0 commit comments

Comments
 (0)