Skip to content

Commit f1b0bb1

Browse files
committed
r/aws_elasticache_user_group(test): split out update case
Over time the `_update` case has become bloated with multiple distinct test scenarios. This change splits this test into multiple distinct tests so they can be parallelized more efficiently. ```console % make testacc PKG=elasticache TESTS=TestAccElastiCacheUserGroup_ make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... make: Running acceptance tests on branch: 🌿 b-aws_ec_user_group-skip-removed-user 🌿... TF_ACC=1 go1.24.6 test ./internal/service/elasticache/... -v -count 1 -parallel 20 -run='TestAccElastiCacheUserGroup_' -timeout 360m -vet=off 2025/09/16 14:38:28 Creating Terraform AWS Provider (SDKv2-style)... 2025/09/16 14:38:28 Initializing Terraform AWS Provider (SDKv2-style)... --- PASS: TestAccElastiCacheUserGroup_disappears (140.26s) --- PASS: TestAccElastiCacheUserGroup_tags (140.39s) --- PASS: TestAccElastiCacheUserGroup_basic (143.97s) --- PASS: TestAccElastiCacheUserGroup_engineValkey (200.12s) --- PASS: TestAccElastiCacheUserGroup_update (262.93s) --- PASS: TestAccElastiCacheUserGroup_rotate (453.03s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/elasticache 459.658s ```
1 parent 20d2e17 commit f1b0bb1

File tree

1 file changed

+98
-2
lines changed

1 file changed

+98
-2
lines changed

internal/service/elasticache/user_group_test.go

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types"
1212
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
13+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1314
"github.com/hashicorp/terraform-plugin-testing/terraform"
1415
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1516
"github.com/hashicorp/terraform-provider-aws/internal/retry"
@@ -52,6 +53,8 @@ func TestAccElastiCacheUserGroup_update(t *testing.T) {
5253
var userGroup awstypes.UserGroup
5354
rName := acctest.RandomWithPrefix(t, "tf-acc")
5455
resourceName := "aws_elasticache_user_group.test"
56+
user1ResourceName := "aws_elasticache_user.test1"
57+
user2ResourceName := "aws_elasticache_user.test2"
5558

5659
acctest.ParallelTest(ctx, t, resource.TestCase{
5760
PreCheck: func() { acctest.PreCheck(ctx, t) },
@@ -69,14 +72,55 @@ func TestAccElastiCacheUserGroup_update(t *testing.T) {
6972
),
7073
},
7174
{
72-
Config: testAccUserGroupConfig_rotate(rName),
75+
Config: testAccUserGroupConfig_multiple(rName),
7376
Check: resource.ComposeTestCheckFunc(
7477
testAccCheckUserGroupExists(ctx, t, resourceName, &userGroup),
7578
resource.TestCheckResourceAttr(resourceName, "user_ids.#", "2"),
7679
resource.TestCheckResourceAttr(resourceName, "user_group_id", rName),
7780
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"),
7881
),
82+
ConfigPlanChecks: resource.ConfigPlanChecks{
83+
PreApply: []plancheck.PlanCheck{
84+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
85+
plancheck.ExpectResourceAction(user1ResourceName, plancheck.ResourceActionNoop),
86+
plancheck.ExpectResourceAction(user2ResourceName, plancheck.ResourceActionNoop),
87+
},
88+
},
7989
},
90+
{
91+
Config: testAccUserGroupConfig_basic(rName),
92+
Check: resource.ComposeTestCheckFunc(
93+
testAccCheckUserGroupExists(ctx, t, resourceName, &userGroup),
94+
resource.TestCheckResourceAttr(resourceName, "user_ids.#", "1"),
95+
resource.TestCheckResourceAttr(resourceName, "user_group_id", rName),
96+
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"),
97+
),
98+
ConfigPlanChecks: resource.ConfigPlanChecks{
99+
PreApply: []plancheck.PlanCheck{
100+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
101+
plancheck.ExpectResourceAction(user1ResourceName, plancheck.ResourceActionNoop),
102+
plancheck.ExpectResourceAction(user2ResourceName, plancheck.ResourceActionNoop),
103+
},
104+
},
105+
},
106+
},
107+
})
108+
}
109+
110+
func TestAccElastiCacheUserGroup_rotate(t *testing.T) {
111+
ctx := acctest.Context(t)
112+
var userGroup awstypes.UserGroup
113+
rName := acctest.RandomWithPrefix(t, "tf-acc")
114+
resourceName := "aws_elasticache_user_group.test"
115+
user1ResourceName := "aws_elasticache_user.test1"
116+
user2ResourceName := "aws_elasticache_user.test2"
117+
118+
acctest.ParallelTest(ctx, t, resource.TestCase{
119+
PreCheck: func() { acctest.PreCheck(ctx, t) },
120+
ErrorCheck: acctest.ErrorCheck(t, names.ElastiCacheServiceID),
121+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
122+
CheckDestroy: testAccCheckUserGroupDestroy(ctx, t),
123+
Steps: []resource.TestStep{
80124
{
81125
Config: testAccUserGroupConfig_basic(rName),
82126
Check: resource.ComposeTestCheckFunc(
@@ -87,14 +131,53 @@ func TestAccElastiCacheUserGroup_update(t *testing.T) {
87131
),
88132
},
89133
{
90-
Config: testAccUserGroupConfig_multiple(rName),
134+
Config: testAccUserGroupConfig_rotate(rName),
91135
Check: resource.ComposeTestCheckFunc(
92136
testAccCheckUserGroupExists(ctx, t, resourceName, &userGroup),
93137
resource.TestCheckResourceAttr(resourceName, "user_ids.#", "2"),
94138
resource.TestCheckResourceAttr(resourceName, "user_group_id", rName),
95139
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"),
96140
),
141+
ConfigPlanChecks: resource.ConfigPlanChecks{
142+
PreApply: []plancheck.PlanCheck{
143+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
144+
plancheck.ExpectResourceAction(user1ResourceName, plancheck.ResourceActionNoop),
145+
plancheck.ExpectResourceAction(user2ResourceName, plancheck.ResourceActionReplace),
146+
},
147+
},
148+
},
149+
{
150+
Config: testAccUserGroupConfig_basic(rName),
151+
Check: resource.ComposeTestCheckFunc(
152+
testAccCheckUserGroupExists(ctx, t, resourceName, &userGroup),
153+
resource.TestCheckResourceAttr(resourceName, "user_ids.#", "1"),
154+
resource.TestCheckResourceAttr(resourceName, "user_group_id", rName),
155+
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"),
156+
),
157+
ConfigPlanChecks: resource.ConfigPlanChecks{
158+
PreApply: []plancheck.PlanCheck{
159+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
160+
plancheck.ExpectResourceAction(user1ResourceName, plancheck.ResourceActionNoop),
161+
plancheck.ExpectResourceAction(user2ResourceName, plancheck.ResourceActionReplace),
162+
},
163+
},
97164
},
165+
},
166+
})
167+
}
168+
169+
func TestAccElastiCacheUserGroup_engineValkey(t *testing.T) {
170+
ctx := acctest.Context(t)
171+
var userGroup awstypes.UserGroup
172+
rName := acctest.RandomWithPrefix(t, "tf-acc")
173+
resourceName := "aws_elasticache_user_group.test"
174+
175+
acctest.ParallelTest(ctx, t, resource.TestCase{
176+
PreCheck: func() { acctest.PreCheck(ctx, t) },
177+
ErrorCheck: acctest.ErrorCheck(t, names.ElastiCacheServiceID),
178+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
179+
CheckDestroy: testAccCheckUserGroupDestroy(ctx, t),
180+
Steps: []resource.TestStep{
98181
{
99182
Config: testAccUserGroupConfig_basic(rName),
100183
Check: resource.ComposeTestCheckFunc(
@@ -186,6 +269,11 @@ func TestAccElastiCacheUserGroup_disappears(t *testing.T) {
186269
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfelasticache.ResourceUserGroup(), resourceName),
187270
),
188271
ExpectNonEmptyPlan: true,
272+
ConfigPlanChecks: resource.ConfigPlanChecks{
273+
PostApplyPostRefresh: []plancheck.PlanCheck{
274+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
275+
},
276+
},
189277
},
190278
},
191279
})
@@ -326,6 +414,14 @@ resource "aws_elasticache_user" "test1" {
326414
passwords = ["password123456789"]
327415
}
328416
417+
resource "aws_elasticache_user" "test2" {
418+
user_id = "%[1]s-2"
419+
user_name = "username1"
420+
access_string = "on ~app::* -@all +@read +@hash +@bitmap +@geo -setbit -bitfield -hset -hsetnx -hmset -hincrby -hincrbyfloat -hdel -bitop -geoadd -georadius -georadiusbymember"
421+
engine = "REDIS"
422+
passwords = ["password123456789"]
423+
}
424+
329425
resource "aws_elasticache_user_group" "test" {
330426
user_group_id = %[1]q
331427
engine = "VALKEY"

0 commit comments

Comments
 (0)