Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_batch_compute_environment: Better error reporting when status is INVALID #21281

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions aws/internal/service/batch/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package waiter

import (
"errors"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/batch"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func ComputeEnvironmentCreated(conn *batch.Batch, name string, timeout time.Duration) (*batch.ComputeEnvironmentDetail, error) {
Expand All @@ -17,8 +20,12 @@ func ComputeEnvironmentCreated(conn *batch.Batch, name string, timeout time.Dura

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
if output, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
if status := aws.StringValue(output.Status); status == batch.CEStatusInvalid {
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusReason)))
}

return output, err
}

return nil, err
Expand All @@ -34,8 +41,12 @@ func ComputeEnvironmentDeleted(conn *batch.Batch, name string, timeout time.Dura

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
if output, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
if status := aws.StringValue(output.Status); status == batch.CEStatusInvalid {
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusReason)))
}

return output, err
}

return nil, err
Expand All @@ -44,15 +55,19 @@ func ComputeEnvironmentDeleted(conn *batch.Batch, name string, timeout time.Dura
func ComputeEnvironmentDisabled(conn *batch.Batch, name string, timeout time.Duration) (*batch.ComputeEnvironmentDetail, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{batch.CEStatusUpdating},
Target: []string{batch.CEStatusValid, batch.CEStatusInvalid},
Target: []string{batch.CEStatusValid},
Refresh: ComputeEnvironmentStatus(conn, name),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
return v, err
if output, ok := outputRaw.(*batch.ComputeEnvironmentDetail); ok {
if status := aws.StringValue(output.Status); status == batch.CEStatusInvalid {
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusReason)))
}

return output, err
}

return nil, err
Expand Down