Skip to content

Commit

Permalink
add timeouts to aws_elasticache_user create
Browse files Browse the repository at this point in the history
  • Loading branch information
Hernan Garcia committed Apr 30, 2023
1 parent 6a8e26c commit 563015f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/service/elasticache/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func ResourceUser() *schema.Resource {
},
CustomizeDiff: verify.SetTagsDiff,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"access_string": {
Type: schema.TypeString,
Expand Down Expand Up @@ -147,6 +151,10 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "creating ElastiCache User (%s): %s", userID, err)
}

if _, err := waitUserCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache User (%s) create: %s", d.Id(), err)
}

d.SetId(aws.StringValue(output.UserId))

// In some partitions, only post-create tagging supported
Expand Down Expand Up @@ -316,10 +324,29 @@ func statusUser(ctx context.Context, conn *elasticache.ElastiCache, id string) r

const (
userStatusActive = "active"
userStatusCreating = "creating"
userStatusDeleting = "deleting"
userStatusModifying = "modifying"
)

func waitUserCreated(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.User, error) {

stateConf := &retry.StateChangeConf{
Pending: []string{userStatusCreating},
Target: []string{userStatusActive},
Refresh: statusUser(ctx, conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*elasticache.User); ok {
return output, err
}

return nil, err
}

func waitUserUpdated(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.User, error) {
const (
timeout = 5 * time.Minute
Expand Down

0 comments on commit 563015f

Please sign in to comment.