From 5e22dfc379ba52d0775c53fbcbfe3218ed813afc Mon Sep 17 00:00:00 2001 From: Andrew Babichev Date: Fri, 27 Nov 2020 09:56:53 +0200 Subject: [PATCH] aws_workspaces_workspace: Add error code for the failed requests --- aws/resource_aws_workspaces_workspace.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_workspaces_workspace.go b/aws/resource_aws_workspaces_workspace.go index aff74faabd3..8a8f71d374b 100644 --- a/aws/resource_aws_workspaces_workspace.go +++ b/aws/resource_aws_workspaces_workspace.go @@ -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) @@ -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), @@ -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 {