Skip to content

Commit

Permalink
add aws_elasticache_user create test with timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Hernan Garcia committed May 1, 2023
1 parent 563015f commit c44b140
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .changelog/31076.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_elasticache_user: Add support for defining custom timeouts
```
24 changes: 11 additions & 13 deletions internal/service/elasticache/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func ResourceUser() *schema.Resource {
CustomizeDiff: verify.SetTagsDiff,

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

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

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

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
if tags := KeyValueTags(ctx, GetTagsIn(ctx)); input.Tags == nil && len(tags) > 0 {
err := UpdateTags(ctx, conn, aws.StringValue(output.ARN), nil, tags)
Expand Down Expand Up @@ -245,7 +247,7 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "updating ElastiCache User (%s): %s", d.Id(), err)
}

if _, err := waitUserUpdated(ctx, conn, d.Id()); err != nil {
if _, err := waitUserUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache User (%s) update: %s", d.Id(), err)
}
}
Expand All @@ -270,7 +272,7 @@ func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "deleting ElastiCache User (%s): %s", d.Id(), err)
}

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

Expand Down Expand Up @@ -347,10 +349,8 @@ func waitUserCreated(ctx context.Context, conn *elasticache.ElastiCache, id stri
return nil, err
}

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

stateConf := &retry.StateChangeConf{
Pending: []string{userStatusModifying},
Target: []string{userStatusActive},
Expand All @@ -367,10 +367,8 @@ func waitUserUpdated(ctx context.Context, conn *elasticache.ElastiCache, id stri
return nil, err
}

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

stateConf := &retry.StateChangeConf{
Pending: []string{userStatusDeleting},
Target: []string{},
Expand Down
6 changes: 6 additions & 0 deletions internal/service/elasticache/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ resource "aws_elasticache_user" "test" {
access_string = "on ~app::* -@all +@read +@hash +@bitmap +@geo -setbit -bitfield -hset -hsetnx -hmset -hincrby -hincrbyfloat -hdel -bitop -geoadd -georadius -georadiusbymember"
engine = "REDIS"
passwords = ["password123456789"]
timeouts {
create = "10m"
delete = "10m"
update = "10m"
}
}
`, rName)
}
Expand Down

0 comments on commit c44b140

Please sign in to comment.