@@ -9,32 +9,30 @@ import (
9
9
"testing"
10
10
11
11
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
12
- sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
13
12
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14
13
"github.com/hashicorp/terraform-plugin-testing/terraform"
15
14
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
16
- "github.com/hashicorp/terraform-provider-aws/internal/conns "
15
+ "github.com/hashicorp/terraform-provider-aws/internal/retry "
17
16
tflogs "github.com/hashicorp/terraform-provider-aws/internal/service/logs"
18
- "github.com/hashicorp/terraform-provider-aws/internal/tfresource"
19
17
"github.com/hashicorp/terraform-provider-aws/names"
20
18
)
21
19
22
20
func TestAccLogsAccountPolicy_basicSubscriptionFilter (t * testing.T ) {
23
21
ctx := acctest .Context (t )
24
- rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
22
+ rName := acctest .RandomWithPrefix (t , acctest .ResourcePrefix )
25
23
resourceName := "aws_cloudwatch_log_account_policy.test"
26
24
var accountPolicy types.AccountPolicy
27
25
28
- resource .ParallelTest (t , resource.TestCase {
26
+ acctest .ParallelTest (ctx , t , resource.TestCase {
29
27
PreCheck : func () { acctest .PreCheck (ctx , t ) },
30
28
ErrorCheck : acctest .ErrorCheck (t , names .LogsServiceID ),
31
29
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
32
- CheckDestroy : testAccCheckAccountPolicyDestroy (ctx ),
30
+ CheckDestroy : testAccCheckAccountPolicyDestroy (ctx , t ),
33
31
Steps : []resource.TestStep {
34
32
{
35
33
Config : testAccAccountPolicyConfig_basicSubscriptionFilter (rName ),
36
34
Check : resource .ComposeTestCheckFunc (
37
- testAccCheckAccountPolicyExists (ctx , resourceName , & accountPolicy ),
35
+ testAccCheckAccountPolicyExists (ctx , t , resourceName , & accountPolicy ),
38
36
resource .TestCheckResourceAttr (resourceName , "policy_name" , rName ),
39
37
testAccCheckAccountHasSubscriptionFilterPolicy (ctx , resourceName , rName ),
40
38
),
@@ -51,52 +49,52 @@ func TestAccLogsAccountPolicy_basicSubscriptionFilter(t *testing.T) {
51
49
52
50
func TestAccLogsAccountPolicy_basicDataProtection (t * testing.T ) {
53
51
ctx := acctest .Context (t )
54
- rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
52
+ rName := acctest .RandomWithPrefix (t , acctest .ResourcePrefix )
55
53
resourceName := "aws_cloudwatch_log_account_policy.test"
56
54
var accountPolicy types.AccountPolicy
57
55
58
- resource .ParallelTest (t , resource.TestCase {
56
+ acctest .ParallelTest (ctx , t , resource.TestCase {
59
57
PreCheck : func () { acctest .PreCheck (ctx , t ) },
60
58
ErrorCheck : acctest .ErrorCheck (t , names .LogsServiceID ),
61
59
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
62
- CheckDestroy : testAccCheckAccountPolicyDestroy (ctx ),
60
+ CheckDestroy : testAccCheckAccountPolicyDestroy (ctx , t ),
63
61
Steps : []resource.TestStep {
64
62
{
65
63
Config : testAccAccountPolicyConfig_basicDataProtection (rName ),
66
64
Check : resource .ComposeTestCheckFunc (
67
- testAccCheckAccountPolicyExists (ctx , resourceName , & accountPolicy ),
65
+ testAccCheckAccountPolicyExists (ctx , t , resourceName , & accountPolicy ),
68
66
resource .TestCheckResourceAttr (resourceName , "policy_name" , rName ),
69
67
resource .TestCheckResourceAttr (resourceName , "policy_type" , "DATA_PROTECTION_POLICY" ),
70
68
acctest .CheckResourceAttrEquivalentJSON (resourceName , "policy_document" , `
71
- {
72
- "Name": "Test",
73
- "Version": "2021-06-01",
74
- "Statement": [
75
- {
76
- "Sid": "Audit",
77
- "DataIdentifier": [
78
- "arn:aws:dataprotection::aws:data-identifier/EmailAddress"
79
- ],
80
- "Operation": {
81
- "Audit": {
82
- "FindingsDestination": {}
83
- }
84
- }
85
- },
86
- {
87
- "Sid": "Redact",
88
- "DataIdentifier": [
89
- "arn:aws:dataprotection::aws:data-identifier/EmailAddress"
90
- ],
91
- "Operation": {
92
- "Deidentify": {
93
- "MaskConfig": {}
94
- }
95
- }
96
- }
97
- ]
98
- }
99
- ` ), //lintignore:AWSAT005
69
+ {
70
+ "Name": "Test",
71
+ "Version": "2021-06-01",
72
+ "Statement": [
73
+ {
74
+ "Sid": "Audit",
75
+ "DataIdentifier": [
76
+ "arn:aws:dataprotection::aws:data-identifier/EmailAddress"
77
+ ],
78
+ "Operation": {
79
+ "Audit": {
80
+ "FindingsDestination": {}
81
+ }
82
+ }
83
+ },
84
+ {
85
+ "Sid": "Redact",
86
+ "DataIdentifier": [
87
+ "arn:aws:dataprotection::aws:data-identifier/EmailAddress"
88
+ ],
89
+ "Operation": {
90
+ "Deidentify": {
91
+ "MaskConfig": {}
92
+ }
93
+ }
94
+ }
95
+ ]
96
+ }
97
+ ` ), //lintignore:AWSAT005
100
98
),
101
99
},
102
100
{
@@ -111,20 +109,20 @@ func TestAccLogsAccountPolicy_basicDataProtection(t *testing.T) {
111
109
112
110
func TestAccLogsAccountPolicy_disappears (t * testing.T ) {
113
111
ctx := acctest .Context (t )
114
- rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
112
+ rName := acctest .RandomWithPrefix (t , acctest .ResourcePrefix )
115
113
resourceName := "aws_cloudwatch_log_account_policy.test"
116
114
var accountPolicy types.AccountPolicy
117
115
118
- resource .ParallelTest (t , resource.TestCase {
116
+ acctest .ParallelTest (ctx , t , resource.TestCase {
119
117
PreCheck : func () { acctest .PreCheck (ctx , t ) },
120
118
ErrorCheck : acctest .ErrorCheck (t , names .LogsServiceID ),
121
119
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
122
- CheckDestroy : testAccCheckAccountPolicyDestroy (ctx ),
120
+ CheckDestroy : testAccCheckAccountPolicyDestroy (ctx , t ),
123
121
Steps : []resource.TestStep {
124
122
{
125
123
Config : testAccAccountPolicyConfig_basicDataProtection (rName ),
126
124
Check : resource .ComposeTestCheckFunc (
127
- testAccCheckAccountPolicyExists (ctx , resourceName , & accountPolicy ),
125
+ testAccCheckAccountPolicyExists (ctx , t , resourceName , & accountPolicy ),
128
126
acctest .CheckResourceDisappears (ctx , acctest .Provider , tflogs .ResourceAccountPolicy (), resourceName ),
129
127
),
130
128
ExpectNonEmptyPlan : true ,
@@ -135,21 +133,21 @@ func TestAccLogsAccountPolicy_disappears(t *testing.T) {
135
133
136
134
func TestAccLogsAccountPolicy_selectionCriteria (t * testing.T ) {
137
135
ctx := acctest .Context (t )
138
- rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
136
+ rName := acctest .RandomWithPrefix (t , acctest .ResourcePrefix )
139
137
rSelectionCriteria := fmt .Sprintf ("LogGroupName NOT IN [\" %s\" ]" , rName )
140
138
resourceName := "aws_cloudwatch_log_account_policy.test"
141
139
var accountPolicy types.AccountPolicy
142
140
143
- resource .ParallelTest (t , resource.TestCase {
141
+ acctest .ParallelTest (ctx , t , resource.TestCase {
144
142
PreCheck : func () { acctest .PreCheck (ctx , t ) },
145
143
ErrorCheck : acctest .ErrorCheck (t , names .LogsServiceID ),
146
144
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
147
- CheckDestroy : testAccCheckAccountPolicyDestroy (ctx ),
145
+ CheckDestroy : testAccCheckAccountPolicyDestroy (ctx , t ),
148
146
Steps : []resource.TestStep {
149
147
{
150
148
Config : testAccAccountPolicyConfig_selectionCriteria (rName , rSelectionCriteria ),
151
149
Check : resource .ComposeTestCheckFunc (
152
- testAccCheckAccountPolicyExists (ctx , resourceName , & accountPolicy ),
150
+ testAccCheckAccountPolicyExists (ctx , t , resourceName , & accountPolicy ),
153
151
resource .TestCheckResourceAttr (resourceName , "policy_name" , rName ),
154
152
resource .TestCheckResourceAttr (resourceName , "selection_criteria" , rSelectionCriteria ),
155
153
),
@@ -164,14 +162,14 @@ func TestAccLogsAccountPolicy_selectionCriteria(t *testing.T) {
164
162
})
165
163
}
166
164
167
- func testAccCheckAccountPolicyExists (ctx context.Context , n string , v * types.AccountPolicy ) resource.TestCheckFunc {
165
+ func testAccCheckAccountPolicyExists (ctx context.Context , t * testing. T , n string , v * types.AccountPolicy ) resource.TestCheckFunc {
168
166
return func (s * terraform.State ) error {
169
167
rs , ok := s .RootModule ().Resources [n ]
170
168
if ! ok {
171
169
return fmt .Errorf ("Not found: %s" , n )
172
170
}
173
171
174
- conn := acctest .Provider . Meta ().( * conns. AWSClient ).LogsClient (ctx )
172
+ conn := acctest .ProviderMeta ( ctx , t ).LogsClient (ctx )
175
173
176
174
output , err := tflogs .FindAccountPolicyByTwoPartKey (ctx , conn , types .PolicyType (rs .Primary .Attributes ["policy_type" ]), rs .Primary .ID )
177
175
@@ -185,9 +183,9 @@ func testAccCheckAccountPolicyExists(ctx context.Context, n string, v *types.Acc
185
183
}
186
184
}
187
185
188
- func testAccCheckAccountPolicyDestroy (ctx context.Context ) resource.TestCheckFunc {
186
+ func testAccCheckAccountPolicyDestroy (ctx context.Context , t * testing. T ) resource.TestCheckFunc {
189
187
return func (s * terraform.State ) error {
190
- conn := acctest .Provider . Meta ().( * conns. AWSClient ).LogsClient (ctx )
188
+ conn := acctest .ProviderMeta ( ctx , t ).LogsClient (ctx )
191
189
192
190
for _ , rs := range s .RootModule ().Resources {
193
191
if rs .Type != "aws_cloudwatch_log_account_policy" {
@@ -196,7 +194,7 @@ func testAccCheckAccountPolicyDestroy(ctx context.Context) resource.TestCheckFun
196
194
197
195
_ , err := tflogs .FindAccountPolicyByTwoPartKey (ctx , conn , types .PolicyType (rs .Primary .Attributes ["policy_type" ]), rs .Primary .ID )
198
196
199
- if tfresource .NotFound (err ) {
197
+ if retry .NotFound (err ) {
200
198
continue
201
199
}
202
200
@@ -230,7 +228,7 @@ func testAccCheckAccountHasSubscriptionFilterPolicy(ctx context.Context, resourc
230
228
return func (s * terraform.State ) error {
231
229
expectedJSONTemplate := `{
232
230
"DestinationArn": "arn:%s:lambda:%s:%s:function:%s",
233
- "FilterPattern" : " ",
231
+ "FilterPattern" : "",
234
232
"Distribution" : "Random"
235
233
}`
236
234
expectedJSON := fmt .Sprintf (expectedJSONTemplate , acctest .Partition (), acctest .Region (), acctest .AccountID (ctx ), rName )
@@ -295,7 +293,7 @@ resource "aws_cloudwatch_log_account_policy" "test" {
295
293
296
294
policy_document = jsonencode({
297
295
DestinationArn = aws_lambda_function.test.arn
298
- FilterPattern = " "
296
+ FilterPattern = ""
299
297
Distribution = "Random"
300
298
})
301
299
}
@@ -310,7 +308,7 @@ resource "aws_cloudwatch_log_account_policy" "test" {
310
308
311
309
policy_document = jsonencode({
312
310
DestinationArn = aws_lambda_function.test.arn
313
- FilterPattern = " "
311
+ FilterPattern = ""
314
312
Distribution = "Random"
315
313
})
316
314
0 commit comments