Skip to content

Commit a68ce02

Browse files
committed
elbv2: Replace 'PlanOnly' acceptance test steps with 'plancheck's.
1 parent 1f1ea58 commit a68ce02

File tree

3 files changed

+74
-21
lines changed

3 files changed

+74
-21
lines changed

internal/service/elbv2/listener_rule_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
1818
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1919
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
2021
"github.com/hashicorp/terraform-plugin-testing/terraform"
2122
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
2223
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -1485,6 +1486,11 @@ func TestAccELBV2ListenerRule_redirectWithTargetGroupARN(t *testing.T) {
14851486
resource.TestCheckResourceAttr(resourceName, "action.0.forward.#", "0"),
14861487
resource.TestCheckResourceAttr(resourceName, "action.0.target_group_arn", ""),
14871488
),
1489+
ConfigPlanChecks: resource.ConfigPlanChecks{
1490+
PreApply: []plancheck.PlanCheck{
1491+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
1492+
},
1493+
},
14881494
},
14891495
{
14901496
ExternalProviders: map[string]resource.ExternalProvider{
@@ -1493,9 +1499,15 @@ func TestAccELBV2ListenerRule_redirectWithTargetGroupARN(t *testing.T) {
14931499
VersionConstraint: "5.36.0",
14941500
},
14951501
},
1496-
Config: testAccListenerRuleConfig_redirectWithTargetGroupARN(lbName),
1497-
PlanOnly: true,
1498-
ExpectNonEmptyPlan: false,
1502+
Config: testAccListenerRuleConfig_redirectWithTargetGroupARN(lbName),
1503+
ConfigPlanChecks: resource.ConfigPlanChecks{
1504+
PreApply: []plancheck.PlanCheck{
1505+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
1506+
},
1507+
PostApplyPostRefresh: []plancheck.PlanCheck{
1508+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
1509+
},
1510+
},
14991511
},
15001512
},
15011513
})

internal/service/elbv2/listener_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,11 @@ func TestAccELBV2Listener_redirectWithTargetGroupARN(t *testing.T) {
21862186
resource.TestCheckResourceAttr(resourceName, "default_action.0.forward.#", "0"),
21872187
resource.TestCheckResourceAttr(resourceName, "default_action.0.target_group_arn", ""),
21882188
),
2189+
ConfigPlanChecks: resource.ConfigPlanChecks{
2190+
PreApply: []plancheck.PlanCheck{
2191+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
2192+
},
2193+
},
21892194
},
21902195
{
21912196
ExternalProviders: map[string]resource.ExternalProvider{
@@ -2194,9 +2199,15 @@ func TestAccELBV2Listener_redirectWithTargetGroupARN(t *testing.T) {
21942199
VersionConstraint: "5.36.0",
21952200
},
21962201
},
2197-
Config: testAccListenerConfig_redirectWithTargetGroupARN(rName),
2198-
PlanOnly: true,
2199-
ExpectNonEmptyPlan: false,
2202+
Config: testAccListenerConfig_redirectWithTargetGroupARN(rName),
2203+
ConfigPlanChecks: resource.ConfigPlanChecks{
2204+
PreApply: []plancheck.PlanCheck{
2205+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
2206+
},
2207+
PostApplyPostRefresh: []plancheck.PlanCheck{
2208+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
2209+
},
2210+
},
22002211
},
22012212
},
22022213
})

internal/service/elbv2/target_group_test.go

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
awstypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
1717
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1818
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1920
"github.com/hashicorp/terraform-plugin-testing/terraform"
2021
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
2122
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -1260,6 +1261,7 @@ func TestAccELBV2TargetGroup_Stickiness_defaultNLB(t *testing.T) {
12601261
func TestAccELBV2TargetGroup_Stickiness_invalidALB(t *testing.T) {
12611262
ctx := acctest.Context(t)
12621263
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
1264+
resourceName := "aws_lb_target_group.test"
12631265

12641266
resource.ParallelTest(t, resource.TestCase{
12651267
PreCheck: func() { acctest.PreCheck(ctx, t) },
@@ -1288,9 +1290,13 @@ func TestAccELBV2TargetGroup_Stickiness_invalidALB(t *testing.T) {
12881290
ExpectError: regexache.MustCompile("You cannot enable stickiness on target groups with the TLS protocol"),
12891291
},
12901292
{
1291-
Config: testAccTargetGroupConfig_stickinessValidity(rName, "TCP_UDP", "lb_cookie", false, "round_robin"),
1292-
PlanOnly: true,
1293-
ExpectNonEmptyPlan: true,
1293+
Config: testAccTargetGroupConfig_stickinessValidity(rName, "TCP_UDP", "lb_cookie", false, "round_robin"),
1294+
ConfigPlanChecks: resource.ConfigPlanChecks{
1295+
PreApply: []plancheck.PlanCheck{
1296+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionReplace),
1297+
},
1298+
},
1299+
ExpectError: regexache.MustCompile("Stickiness type 'lb_cookie' is not supported for target groups with"),
12941300
},
12951301
},
12961302
})
@@ -3716,7 +3722,7 @@ func TestAccELBV2TargetGroup_Instance_protocolVersion_MigrateV0(t *testing.T) {
37163722
Config: testAccTargetGroupConfig_Instance_protocolVersion(protocol, "HTTP1"),
37173723
PreCheck: preCheck,
37183724
PostCheck: postCheck,
3719-
}.Steps(),
3725+
}.Steps(resourceName),
37203726
})
37213727
})
37223728
}
@@ -3788,7 +3794,7 @@ func TestAccELBV2TargetGroup_Lambda_defaults_MigrateV0(t *testing.T) {
37883794
resource.TestCheckResourceAttr(resourceName, "health_check.#", "1"),
37893795
resource.TestCheckResourceAttr(resourceName, "health_check.0.enabled", acctest.CtFalse),
37903796
),
3791-
}.Steps(),
3797+
}.Steps(resourceName),
37923798
})
37933799
}
37943800

@@ -3840,7 +3846,7 @@ func TestAccELBV2TargetGroup_Lambda_vpc_MigrateV0(t *testing.T) {
38403846
resource.TestCheckResourceAttr(resourceName, "target_type", string(awstypes.TargetTypeEnumLambda)),
38413847
resource.TestCheckResourceAttr(resourceName, names.AttrVPCID, ""), // Should be Null
38423848
),
3843-
}.Steps(),
3849+
}.Steps(resourceName),
38443850
})
38453851
}
38463852

@@ -3906,7 +3912,7 @@ func TestAccELBV2TargetGroup_Lambda_protocol_MigrateV0(t *testing.T) {
39063912
resource.TestCheckResourceAttr(resourceName, "target_type", string(awstypes.TargetTypeEnumLambda)),
39073913
resource.TestCheckResourceAttr(resourceName, names.AttrProtocol, ""), // Should be Null
39083914
),
3909-
}.Steps(),
3915+
}.Steps(resourceName),
39103916
})
39113917
})
39123918
}
@@ -3960,7 +3966,7 @@ func TestAccELBV2TargetGroup_Lambda_protocolVersion_MigrateV0(t *testing.T) {
39603966
resource.TestCheckResourceAttr(resourceName, "target_type", string(awstypes.TargetTypeEnumLambda)),
39613967
resource.TestCheckNoResourceAttr(resourceName, "protocol_version"),
39623968
),
3963-
}.Steps(),
3969+
}.Steps(resourceName),
39643970
})
39653971
}
39663972

@@ -4012,7 +4018,7 @@ func TestAccELBV2TargetGroup_Lambda_port_MigrateV0(t *testing.T) {
40124018
resource.TestCheckResourceAttr(resourceName, "target_type", string(awstypes.TargetTypeEnumLambda)),
40134019
resource.TestCheckResourceAttr(resourceName, names.AttrPort, "0"), // Should be Null
40144020
),
4015-
}.Steps(),
4021+
}.Steps(resourceName),
40164022
})
40174023
}
40184024

@@ -4088,7 +4094,7 @@ func TestAccELBV2TargetGroup_Lambda_HealthCheck_basic_MigrateV0(t *testing.T) {
40884094
resource.TestCheckResourceAttr(resourceName, "health_check.0.timeout", "35"),
40894095
resource.TestCheckResourceAttr(resourceName, "health_check.0.unhealthy_threshold", "3"),
40904096
),
4091-
}.Steps(),
4097+
}.Steps(resourceName),
40924098
})
40934099
}
40944100

@@ -4203,6 +4209,11 @@ func TestAccELBV2TargetGroup_Lambda_HealthCheck_protocol_MigrateV0(t *testing.T)
42034209
resource.TestCheckResourceAttr(resourceName, "health_check.0.enabled", acctest.CtTrue),
42044210
resource.TestCheckResourceAttr(resourceName, "health_check.0.protocol", ""),
42054211
)
4212+
step.ConfigPlanChecks = resource.ConfigPlanChecks{
4213+
PreApply: []plancheck.PlanCheck{
4214+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
4215+
},
4216+
}
42064217
} else {
42074218
t.Fatal("invalid test case, one of invalidHealthCheckProtocol or warning must be set")
42084219
}
@@ -4217,8 +4228,15 @@ func TestAccELBV2TargetGroup_Lambda_HealthCheck_protocol_MigrateV0(t *testing.T)
42174228
VersionConstraint: "5.26.0",
42184229
},
42194230
},
4220-
Config: config,
4221-
PlanOnly: true,
4231+
Config: config,
4232+
ConfigPlanChecks: resource.ConfigPlanChecks{
4233+
PreApply: []plancheck.PlanCheck{
4234+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
4235+
},
4236+
PostApplyPostRefresh: []plancheck.PlanCheck{
4237+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
4238+
},
4239+
},
42224240
})
42234241
}
42244242

@@ -4332,7 +4350,7 @@ type testAccMigrateTest struct {
43324350
PostCheck resource.TestCheckFunc
43334351
}
43344352

4335-
func (t testAccMigrateTest) Steps() []resource.TestStep {
4353+
func (t testAccMigrateTest) Steps(resourceName string) []resource.TestStep {
43364354
return []resource.TestStep{
43374355
{
43384356
ExternalProviders: map[string]resource.ExternalProvider{
@@ -4343,6 +4361,11 @@ func (t testAccMigrateTest) Steps() []resource.TestStep {
43434361
},
43444362
Config: t.Config,
43454363
Check: t.PreCheck,
4364+
ConfigPlanChecks: resource.ConfigPlanChecks{
4365+
PreApply: []plancheck.PlanCheck{
4366+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
4367+
},
4368+
},
43464369
},
43474370
{
43484371
ExternalProviders: map[string]resource.ExternalProvider{
@@ -4351,8 +4374,15 @@ func (t testAccMigrateTest) Steps() []resource.TestStep {
43514374
VersionConstraint: t.NextVersion,
43524375
},
43534376
},
4354-
Config: t.Config,
4355-
PlanOnly: true,
4377+
Config: t.Config,
4378+
ConfigPlanChecks: resource.ConfigPlanChecks{
4379+
PreApply: []plancheck.PlanCheck{
4380+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
4381+
},
4382+
PostApplyPostRefresh: []plancheck.PlanCheck{
4383+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
4384+
},
4385+
},
43564386
},
43574387
{
43584388
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,

0 commit comments

Comments
 (0)