@@ -8,43 +8,46 @@ import (
8
8
"log"
9
9
"time"
10
10
11
- "github.com/aws/aws-sdk-go/aws"
12
- "github.com/aws/aws-sdk-go/service/macie2"
13
- "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
11
+ "github.com/aws/aws-sdk-go-v2/aws"
12
+ "github.com/aws/aws-sdk-go-v2/service/macie2"
13
+ awstypes "github.com/aws/aws-sdk-go-v2/service/macie2/types"
14
+ "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
14
15
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
15
16
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
16
17
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
17
18
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
19
19
"github.com/hashicorp/terraform-provider-aws/internal/conns"
20
+ "github.com/hashicorp/terraform-provider-aws/internal/enum"
21
+ "github.com/hashicorp/terraform-provider-aws/internal/errs"
20
22
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
21
23
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
22
24
"github.com/hashicorp/terraform-provider-aws/names"
23
25
)
24
26
25
- // @SDKResource("aws_macie2_account")
26
- func ResourceAccount () * schema.Resource {
27
+ // @SDKResource("aws_macie2_account", name="Account" )
28
+ func resourceAccount () * schema.Resource {
27
29
return & schema.Resource {
28
30
CreateWithoutTimeout : resourceAccountCreate ,
29
31
ReadWithoutTimeout : resourceAccountRead ,
30
32
UpdateWithoutTimeout : resourceAccountUpdate ,
31
33
DeleteWithoutTimeout : resourceAccountDelete ,
34
+
32
35
Importer : & schema.ResourceImporter {
33
36
StateContext : schema .ImportStatePassthroughContext ,
34
37
},
35
38
36
39
Schema : map [string ]* schema.Schema {
37
40
"finding_publishing_frequency" : {
38
- Type : schema .TypeString ,
39
- Optional : true ,
40
- Computed : true ,
41
- ValidateFunc : validation . StringInSlice ( macie2 . FindingPublishingFrequency_Values (), false ),
41
+ Type : schema .TypeString ,
42
+ Optional : true ,
43
+ Computed : true ,
44
+ ValidateDiagFunc : enum . Validate [awstypes. FindingPublishingFrequency ]( ),
42
45
},
43
46
names .AttrStatus : {
44
- Type : schema .TypeString ,
45
- Optional : true ,
46
- Computed : true ,
47
- ValidateFunc : validation . StringInSlice ( macie2 . MacieStatus_Values (), false ),
47
+ Type : schema .TypeString ,
48
+ Optional : true ,
49
+ Computed : true ,
50
+ ValidateDiagFunc : enum . Validate [awstypes. MacieStatus ]( ),
48
51
},
49
52
names .AttrServiceRole : {
50
53
Type : schema .TypeString ,
@@ -65,23 +68,23 @@ func ResourceAccount() *schema.Resource {
65
68
func resourceAccountCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
66
69
var diags diag.Diagnostics
67
70
68
- conn := meta .(* conns.AWSClient ).Macie2Conn (ctx )
71
+ conn := meta .(* conns.AWSClient ).Macie2Client (ctx )
69
72
70
73
input := & macie2.EnableMacieInput {
71
74
ClientToken : aws .String (id .UniqueId ()),
72
75
}
73
76
74
77
if v , ok := d .GetOk ("finding_publishing_frequency" ); ok {
75
- input .FindingPublishingFrequency = aws . String (v .(string ))
78
+ input .FindingPublishingFrequency = awstypes . FindingPublishingFrequency (v .(string ))
76
79
}
77
80
if v , ok := d .GetOk (names .AttrStatus ); ok {
78
- input .Status = aws . String (v .(string ))
81
+ input .Status = awstypes . MacieStatus (v .(string ))
79
82
}
80
83
81
84
err := retry .RetryContext (ctx , 4 * time .Minute , func () * retry.RetryError {
82
- _ , err := conn .EnableMacieWithContext (ctx , input )
85
+ _ , err := conn .EnableMacie (ctx , input )
83
86
if err != nil {
84
- if tfawserr .ErrCodeEquals (err , macie2 .ErrorCodeClientError ) {
87
+ if tfawserr .ErrCodeEquals (err , string ( awstypes .ErrorCodeClientError ) ) {
85
88
return retry .RetryableError (err )
86
89
}
87
90
@@ -92,7 +95,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, meta int
92
95
})
93
96
94
97
if tfresource .TimedOut (err ) {
95
- _ , err = conn .EnableMacieWithContext (ctx , input )
98
+ _ , err = conn .EnableMacie (ctx , input )
96
99
}
97
100
98
101
if err != nil {
@@ -107,14 +110,14 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, meta int
107
110
func resourceAccountRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
108
111
var diags diag.Diagnostics
109
112
110
- conn := meta .(* conns.AWSClient ).Macie2Conn (ctx )
113
+ conn := meta .(* conns.AWSClient ).Macie2Client (ctx )
111
114
112
115
input := & macie2.GetMacieSessionInput {}
113
116
114
- resp , err := conn .GetMacieSessionWithContext (ctx , input )
117
+ resp , err := conn .GetMacieSession (ctx , input )
115
118
116
- if ! d .IsNewResource () && (tfawserr . ErrCodeEquals (err , macie2 . ErrCodeResourceNotFoundException ) ||
117
- tfawserr . ErrMessageContains (err , macie2 . ErrCodeAccessDeniedException , "Macie is not enabled" )) {
119
+ if ! d .IsNewResource () && (errs. IsA [ * awstypes. ResourceNotFoundException ] (err ) ||
120
+ errs . IsAErrorMessageContains [ * awstypes. AccessDeniedException ] (err , "Macie is not enabled" )) {
118
121
log .Printf ("[WARN] Macie not enabled for AWS account (%s), removing from state" , d .Id ())
119
122
d .SetId ("" )
120
123
return diags
@@ -127,28 +130,28 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, meta inter
127
130
d .Set (names .AttrStatus , resp .Status )
128
131
d .Set ("finding_publishing_frequency" , resp .FindingPublishingFrequency )
129
132
d .Set (names .AttrServiceRole , resp .ServiceRole )
130
- d .Set (names .AttrCreatedAt , aws .TimeValue (resp .CreatedAt ).Format (time .RFC3339 ))
131
- d .Set ("updated_at" , aws .TimeValue (resp .UpdatedAt ).Format (time .RFC3339 ))
133
+ d .Set (names .AttrCreatedAt , aws .ToTime (resp .CreatedAt ).Format (time .RFC3339 ))
134
+ d .Set ("updated_at" , aws .ToTime (resp .UpdatedAt ).Format (time .RFC3339 ))
132
135
133
136
return diags
134
137
}
135
138
136
139
func resourceAccountUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
137
140
var diags diag.Diagnostics
138
141
139
- conn := meta .(* conns.AWSClient ).Macie2Conn (ctx )
142
+ conn := meta .(* conns.AWSClient ).Macie2Client (ctx )
140
143
141
144
input := & macie2.UpdateMacieSessionInput {}
142
145
143
146
if d .HasChange ("finding_publishing_frequency" ) {
144
- input .FindingPublishingFrequency = aws . String (d .Get ("finding_publishing_frequency" ).(string ))
147
+ input .FindingPublishingFrequency = awstypes . FindingPublishingFrequency (d .Get ("finding_publishing_frequency" ).(string ))
145
148
}
146
149
147
150
if d .HasChange (names .AttrStatus ) {
148
- input .Status = aws . String (d .Get (names .AttrStatus ).(string ))
151
+ input .Status = awstypes . MacieStatus (d .Get (names .AttrStatus ).(string ))
149
152
}
150
153
151
- _ , err := conn .UpdateMacieSessionWithContext (ctx , input )
154
+ _ , err := conn .UpdateMacieSession (ctx , input )
152
155
if err != nil {
153
156
return sdkdiag .AppendErrorf (diags , "updating Macie Account (%s): %s" , d .Id (), err )
154
157
}
@@ -159,20 +162,20 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, meta int
159
162
func resourceAccountDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
160
163
var diags diag.Diagnostics
161
164
162
- conn := meta .(* conns.AWSClient ).Macie2Conn (ctx )
165
+ conn := meta .(* conns.AWSClient ).Macie2Client (ctx )
163
166
164
167
input := & macie2.DisableMacieInput {}
165
168
166
169
err := retry .RetryContext (ctx , 4 * time .Minute , func () * retry.RetryError {
167
- _ , err := conn .DisableMacieWithContext (ctx , input )
170
+ _ , err := conn .DisableMacie (ctx , input )
168
171
169
- if tfawserr . ErrMessageContains (err , macie2 . ErrCodeConflictException , "Cannot disable Macie while associated with an administrator account" ) {
172
+ if errs . IsAErrorMessageContains [ * awstypes. ConflictException ] (err , "Cannot disable Macie while associated with an administrator account" ) {
170
173
return retry .RetryableError (err )
171
174
}
172
175
173
176
if err != nil {
174
- if tfawserr . ErrCodeEquals (err , macie2 . ErrCodeResourceNotFoundException ) ||
175
- tfawserr . ErrMessageContains (err , macie2 . ErrCodeAccessDeniedException , "Macie is not enabled" ) {
177
+ if errs. IsA [ * awstypes. ResourceNotFoundException ] (err ) ||
178
+ errs . IsAErrorMessageContains [ * awstypes. AccessDeniedException ] (err , "Macie is not enabled" ) {
176
179
return nil
177
180
}
178
181
return retry .NonRetryableError (err )
@@ -182,12 +185,12 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, meta int
182
185
})
183
186
184
187
if tfresource .TimedOut (err ) {
185
- _ , err = conn .DisableMacieWithContext (ctx , input )
188
+ _ , err = conn .DisableMacie (ctx , input )
186
189
}
187
190
188
191
if err != nil {
189
- if tfawserr . ErrCodeEquals (err , macie2 . ErrCodeResourceNotFoundException ) ||
190
- tfawserr . ErrMessageContains (err , macie2 . ErrCodeAccessDeniedException , "Macie is not enabled" ) {
192
+ if errs. IsA [ * awstypes. ResourceNotFoundException ] (err ) ||
193
+ errs . IsAErrorMessageContains [ * awstypes. AccessDeniedException ] (err , "Macie is not enabled" ) {
191
194
return diags
192
195
}
193
196
return sdkdiag .AppendErrorf (diags , "disabling Macie Account (%s): %s" , d .Id (), err )
0 commit comments