Skip to content

Commit

Permalink
aws_workspaces_workspace: Add error code for the failed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tensho committed Dec 4, 2020
1 parent b31cce2 commit 5e22dfc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions aws/resource_aws_workspaces_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func resourceAwsWorkspacesWorkspaceCreate(d *schema.ResourceData, meta interface

wsFail := resp.FailedRequests
if len(wsFail) > 0 {
return fmt.Errorf("workspace creation failed: %s", *wsFail[0].ErrorMessage)
return fmt.Errorf("workspace creation failed: %s: %s", aws.StringValue(wsFail[0].ErrorCode), aws.StringValue(wsFail[0].ErrorMessage))
}

workspaceID := aws.StringValue(resp.PendingRequests[0].WorkspaceId)
Expand Down Expand Up @@ -288,7 +288,7 @@ func resourceAwsWorkspacesWorkspaceDelete(d *schema.ResourceData, meta interface

func workspaceDelete(conn *workspaces.WorkSpaces, id string, timeout time.Duration) error {
log.Printf("[DEBUG] Terminating workspace %q", id)
_, err := conn.TerminateWorkspaces(&workspaces.TerminateWorkspacesInput{
resp, err := conn.TerminateWorkspaces(&workspaces.TerminateWorkspacesInput{
TerminateWorkspaceRequests: []*workspaces.TerminateRequest{
{
WorkspaceId: aws.String(id),
Expand All @@ -299,6 +299,11 @@ func workspaceDelete(conn *workspaces.WorkSpaces, id string, timeout time.Durati
return err
}

wsFail := resp.FailedRequests
if len(wsFail) > 0 {
return fmt.Errorf("workspace termination failed: %s: %s", aws.StringValue(wsFail[0].ErrorCode), aws.StringValue(wsFail[0].ErrorMessage))
}

log.Printf("[DEBUG] Waiting for workspace %q to be terminated", id)
_, err = waiter.WorkspaceTerminated(conn, id, timeout)
if err != nil {
Expand Down

0 comments on commit 5e22dfc

Please sign in to comment.