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

rds/instance: Fix create returns unready instances #32287

Merged
merged 4 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions .changelog/32287.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_db_instance: Fix resource Create returning instance not in the `available` state
```
14 changes: 7 additions & 7 deletions internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in

var instance *rds.DBInstance
var err error
if instance, err = waitDBInstanceAvailableSDKv1(ctx, conn, d.Get("identifier").(string), d.Timeout(schema.TimeoutCreate)); err != nil {
if instance, err = waitDBInstanceAvailableSDKv1(ctx, conn, identifier, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) create: %s", identifier, err)
}

Expand Down Expand Up @@ -2373,17 +2373,16 @@ func findDBInstanceByIDSDKv1(ctx context.Context, conn *rds.RDS, id string) (*rd
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || len(output.DBInstances) == 0 || output.DBInstances[0] == nil {
if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

dbInstance := output.DBInstances[0]

return dbInstance, nil
return tfresource.AssertSinglePtrResult(output.DBInstances)
}

// findDBInstanceByIDSDKv2 in general should be called with a DbiResourceId of the form
Expand Down Expand Up @@ -2419,15 +2418,16 @@ func findDBInstanceByIDSDKv2(ctx context.Context, conn *rds_sdkv2.Client, id str
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || len(output.DBInstances) == 0 {
if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return &output.DBInstances[0], nil
return tfresource.AssertSingleValueResult(output.DBInstances)
}

func statusDBInstanceSDKv1(ctx context.Context, conn *rds.RDS, id string) retry.StateRefreshFunc {
Expand Down