Skip to content

Commit 98fa76d

Browse files
committed
events: Replace 'PlanOnly' acceptance test steps with 'plancheck's.
1 parent a68ce02 commit 98fa76d

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

internal/service/events/bus_policy.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1616
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
17-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1817
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1918
"github.com/hashicorp/terraform-provider-aws/internal/errs"
2019
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
20+
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
2121
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2222
"github.com/hashicorp/terraform-provider-aws/internal/verify"
2323
"github.com/hashicorp/terraform-provider-aws/names"
@@ -46,17 +46,7 @@ func resourceBusPolicy() *schema.Resource {
4646
ValidateFunc: validBusName,
4747
Default: DefaultEventBusName,
4848
},
49-
names.AttrPolicy: {
50-
Type: schema.TypeString,
51-
Required: true,
52-
ValidateFunc: validation.StringIsJSON,
53-
DiffSuppressFunc: verify.SuppressEquivalentPolicyDiffs,
54-
DiffSuppressOnRefresh: true,
55-
StateFunc: func(v any) string {
56-
json, _ := structure.NormalizeJsonString(v)
57-
return json
58-
},
59-
},
49+
names.AttrPolicy: sdkv2.IAMPolicyDocumentSchemaRequired(),
6050
},
6151
}
6252
}

internal/service/events/bus_policy_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
awspolicy "github.com/hashicorp/awspolicyequivalence"
1414
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1515
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
16+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1617
"github.com/hashicorp/terraform-plugin-testing/terraform"
1718
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1819
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -72,10 +73,22 @@ func TestAccEventsBusPolicy_ignoreEquivalent(t *testing.T) {
7273
testAccCheckBusPolicyExists(ctx, resourceName),
7374
testAccBusPolicyDocument(ctx, resourceName),
7475
),
76+
ConfigPlanChecks: resource.ConfigPlanChecks{
77+
PreApply: []plancheck.PlanCheck{
78+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
79+
},
80+
},
7581
},
7682
{
77-
Config: testAccBusPolicyConfig_newOrder(rName),
78-
PlanOnly: true,
83+
Config: testAccBusPolicyConfig_newOrder(rName),
84+
ConfigPlanChecks: resource.ConfigPlanChecks{
85+
PreApply: []plancheck.PlanCheck{
86+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
87+
},
88+
PostApplyPostRefresh: []plancheck.PlanCheck{
89+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
90+
},
91+
},
7992
},
8093
},
8194
})

internal/service/events/permission_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/YakDriver/regexache"
1212
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1313
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1415
"github.com/hashicorp/terraform-plugin-testing/terraform"
1516
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1617
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -70,22 +71,39 @@ func TestAccEventsPermission_basic(t *testing.T) {
7071
resource.TestCheckResourceAttr(resourceName, "statement_id", statementID),
7172
resource.TestCheckResourceAttr(resourceName, "event_bus_name", tfevents.DefaultEventBusName),
7273
),
74+
ConfigPlanChecks: resource.ConfigPlanChecks{
75+
PreApply: []plancheck.PlanCheck{
76+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
77+
},
78+
},
7379
},
7480
{
7581
Config: testAccPermissionConfig_basic(principal2, statementID),
7682
Check: resource.ComposeTestCheckFunc(
7783
testAccCheckPermissionExists(ctx, resourceName),
7884
resource.TestCheckResourceAttr(resourceName, names.AttrPrincipal, principal2),
7985
),
86+
ConfigPlanChecks: resource.ConfigPlanChecks{
87+
PreApply: []plancheck.PlanCheck{
88+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
89+
},
90+
},
8091
},
8192
{
8293
ResourceName: resourceName,
8394
ImportState: true,
8495
ImportStateVerify: true,
8596
},
8697
{
87-
Config: testAccPermissionConfig_defaultBusName(principal2, statementID),
88-
PlanOnly: true,
98+
Config: testAccPermissionConfig_defaultBusName(principal2, statementID),
99+
ConfigPlanChecks: resource.ConfigPlanChecks{
100+
PreApply: []plancheck.PlanCheck{
101+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
102+
},
103+
PostApplyPostRefresh: []plancheck.PlanCheck{
104+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
105+
},
106+
},
89107
},
90108
},
91109
})

internal/service/events/target_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
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"
@@ -228,6 +229,11 @@ func TestAccEventsTarget_basic(t *testing.T) {
228229
resource.TestCheckResourceAttr(resourceName, "target_id", rName),
229230
resource.TestCheckResourceAttr(resourceName, "appsync_target.#", "0"),
230231
),
232+
ConfigPlanChecks: resource.ConfigPlanChecks{
233+
PreApply: []plancheck.PlanCheck{
234+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
235+
},
236+
},
231237
},
232238
{
233239
ResourceName: resourceName,
@@ -244,8 +250,15 @@ func TestAccEventsTarget_basic(t *testing.T) {
244250
ImportStateVerifyIgnore: []string{names.AttrForceDestroy},
245251
},
246252
{
247-
Config: testAccTargetConfig_defaultBusName(rName),
248-
PlanOnly: true,
253+
Config: testAccTargetConfig_defaultBusName(rName),
254+
ConfigPlanChecks: resource.ConfigPlanChecks{
255+
PreApply: []plancheck.PlanCheck{
256+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
257+
},
258+
PostApplyPostRefresh: []plancheck.PlanCheck{
259+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
260+
},
261+
},
249262
},
250263
},
251264
})

0 commit comments

Comments
 (0)