Skip to content

Commit 842ec2e

Browse files
authored
Merge pull request hashicorp#44931 from hashicorp/smarterr-bedrockcoreagent
smarterrify bedrockagentcore
2 parents fd1bf8a + a0b06d1 commit 842ec2e

File tree

13 files changed

+89
-56
lines changed

13 files changed

+89
-56
lines changed

.ci/semgrep/smarterr/enforce.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rules:
88
paths:
99
include:
1010
- "/internal/service/appsync/"
11+
- "/internal/service/bedrockagentcore/"
1112
- "/internal/service/cloudwatch/"
1213
- "/internal/service/invoicing/"
1314

@@ -20,6 +21,7 @@ rules:
2021
paths:
2122
include:
2223
- "/internal/service/appsync/"
24+
- "/internal/service/bedrockagentcore/"
2325
- "/internal/service/cloudwatch/"
2426
- "/internal/service/invoicing/"
2527

@@ -33,6 +35,7 @@ rules:
3335
paths:
3436
include:
3537
- "/internal/service/appsync/"
38+
- "/internal/service/bedrockagentcore/"
3639
- "/internal/service/cloudwatch/"
3740
- "/internal/service/invoicing/"
3841

@@ -44,6 +47,7 @@ rules:
4447
paths:
4548
include:
4649
- "/internal/service/appsync/"
50+
- "/internal/service/bedrockagentcore/"
4751
- "/internal/service/cloudwatch/"
4852
- "/internal/service/invoicing/"
4953

@@ -59,6 +63,7 @@ rules:
5963
paths:
6064
include:
6165
- "/internal/service/appsync/"
66+
- "/internal/service/bedrockagentcore/"
6267
- "/internal/service/cloudwatch/"
6368
- "/internal/service/invoicing/"
6469

@@ -70,6 +75,7 @@ rules:
7075
paths:
7176
include:
7277
- "/internal/service/appsync/"
78+
- "/internal/service/bedrockagentcore/"
7379
- "/internal/service/cloudwatch/"
7480
- "/internal/service/invoicing/"
7581

@@ -83,6 +89,7 @@ rules:
8389
paths:
8490
include:
8591
- "/internal/service/appsync/"
92+
- "/internal/service/bedrockagentcore/"
8693
- "/internal/service/cloudwatch/"
8794
- "/internal/service/invoicing/"
8895

@@ -94,6 +101,7 @@ rules:
94101
paths:
95102
include:
96103
- "/internal/service/appsync/"
104+
- "/internal/service/bedrockagentcore/"
97105
- "/internal/service/cloudwatch/"
98106
- "/internal/service/invoicing/"
99107

@@ -105,6 +113,7 @@ rules:
105113
paths:
106114
include:
107115
- "/internal/service/appsync/"
116+
- "/internal/service/bedrockagentcore/"
108117
- "/internal/service/cloudwatch/"
109118
- "/internal/service/invoicing/"
110119

@@ -119,6 +128,7 @@ rules:
119128
paths:
120129
include:
121130
- "/internal/service/appsync/"
131+
- "/internal/service/bedrockagentcore/"
122132
- "/internal/service/cloudwatch/"
123133
- "/internal/service/invoicing/"
124134

@@ -131,9 +141,20 @@ rules:
131141
return nil, $ERR
132142
- pattern-not-inside: |
133143
return nil, smarterr.NewError(...)
144+
- pattern-not-inside: |
145+
func $FUNC(...) (..., diag.Diagnostics) {
146+
...
147+
return nil, $ERR
148+
}
149+
- pattern-not-inside: |
150+
smerr.AddEnrich(...)
151+
if $DIAGS.HasError() {
152+
return nil, $ERR
153+
}
134154
paths:
135155
include:
136156
- "/internal/service/appsync/"
157+
- "/internal/service/bedrockagentcore/"
137158
- "/internal/service/cloudwatch/"
138159
- "/internal/service/invoicing/"
139160

@@ -148,9 +169,20 @@ rules:
148169
return $VALUE, nil
149170
- pattern-not-inside: |
150171
return $VALUE, smarterr.NewError(...)
172+
- pattern-not-inside: |
173+
func $FUNC(...) (..., diag.Diagnostics) {
174+
...
175+
return $VALUE, $ERR
176+
}
177+
- pattern-not-inside: |
178+
smerr.AddEnrich(...)
179+
if $DIAGS.HasError() {
180+
return $VALUE, $ERR
181+
}
151182
paths:
152183
include:
153184
- "/internal/service/appsync/"
185+
- "/internal/service/bedrockagentcore/"
154186
- "/internal/service/cloudwatch/"
155187
- "/internal/service/invoicing/"
156188
exclude:
@@ -168,6 +200,7 @@ rules:
168200
paths:
169201
include:
170202
- "/internal/service/appsync/"
203+
- "/internal/service/bedrockagentcore/"
171204
- "/internal/service/cloudwatch/"
172205
- "/internal/service/invoicing/"
173206
exclude:
@@ -184,6 +217,7 @@ rules:
184217
paths:
185218
include:
186219
- "/internal/service/appsync/"
220+
- "/internal/service/bedrockagentcore/"
187221
- "/internal/service/cloudwatch/"
188222
- "/internal/service/invoicing/"
189223

@@ -198,6 +232,7 @@ rules:
198232
paths:
199233
include:
200234
- "/internal/service/appsync/"
235+
- "/internal/service/bedrockagentcore/"
201236
- "/internal/service/cloudwatch/"
202237
- "/internal/service/invoicing/"
203238
exclude:
@@ -217,6 +252,7 @@ rules:
217252
paths:
218253
include:
219254
- "/internal/service/appsync/"
255+
- "/internal/service/bedrockagentcore/"
220256
- "/internal/service/cloudwatch/"
221257
- "/internal/service/invoicing/"
222258
exclude:
@@ -234,6 +270,7 @@ rules:
234270
paths:
235271
include:
236272
- "/internal/service/appsync/"
273+
- "/internal/service/bedrockagentcore/"
237274
- "/internal/service/cloudwatch/"
238275
- "/internal/service/invoicing/"
239276
exclude:
@@ -251,6 +288,7 @@ rules:
251288
paths:
252289
include:
253290
- "/internal/service/appsync/"
291+
- "/internal/service/bedrockagentcore/"
254292
- "/internal/service/cloudwatch/"
255293
- "/internal/service/invoicing/"
256294
exclude:
@@ -267,5 +305,6 @@ rules:
267305
paths:
268306
include:
269307
- "/internal/service/appsync/"
308+
- "/internal/service/bedrockagentcore/"
270309
- "/internal/service/cloudwatch/"
271310
- "/internal/service/invoicing/"

internal/service/bedrockagentcore/agent_runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ func (r *agentRuntimeResource) Read(ctx context.Context, request resource.ReadRe
303303

304304
agentRuntimeID := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID)
305305
out, err := findAgentRuntimeByID(ctx, conn, agentRuntimeID)
306-
if tfresource.NotFound(err) {
307-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
306+
if retry.NotFound(err) {
307+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
308308
response.State.RemoveResource(ctx)
309309
return
310310
}

internal/service/bedrockagentcore/agent_runtime_endpoint.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
3232
"github.com/hashicorp/terraform-provider-aws/internal/framework"
3333
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
34+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
3435
"github.com/hashicorp/terraform-provider-aws/internal/smerr"
3536
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3637
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
@@ -147,8 +148,8 @@ func (r *agentRuntimeEndpointResource) Read(ctx context.Context, request resourc
147148

148149
agentRuntimeID, name := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID), fwflex.StringValueFromFramework(ctx, data.Name)
149150
out, err := findAgentRuntimeEndpointByTwoPartKey(ctx, conn, agentRuntimeID, name)
150-
if tfresource.NotFound(err) {
151-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
151+
if retry.NotFound(err) {
152+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
152153
response.State.RemoveResource(ctx)
153154
return
154155
}
@@ -249,7 +250,7 @@ func (r *agentRuntimeEndpointResource) Delete(ctx context.Context, request resou
249250
func (r *agentRuntimeEndpointResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) {
250251
parts := strings.Split(request.ID, ",")
251252
if len(parts) != 2 {
252-
response.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "agent_runtime_id,name"`, request.ID))
253+
smerr.AddError(ctx, &response.Diagnostics, fmt.Errorf(`Unexpected format for import ID (%s), use: "agent_runtime_id,name"`, request.ID))
253254
return
254255
}
255256

@@ -315,7 +316,7 @@ func waitAgentRuntimeEndpointDeleted(ctx context.Context, conn *bedrockagentcore
315316
func statusAgentRuntimeEndpoint(ctx context.Context, conn *bedrockagentcorecontrol.Client, agentRuntimeID, endpointName string) sdkretry.StateRefreshFunc {
316317
return func() (any, string, error) {
317318
out, err := findAgentRuntimeEndpointByTwoPartKey(ctx, conn, agentRuntimeID, endpointName)
318-
if tfresource.NotFound(err) {
319+
if retry.NotFound(err) {
319320
return nil, "", nil
320321
}
321322

internal/service/bedrockagentcore/api_key_credential_provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/hashicorp/terraform-provider-aws/internal/framework"
2828
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
2929
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
30+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
3031
"github.com/hashicorp/terraform-provider-aws/internal/smerr"
3132
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
3233
"github.com/hashicorp/terraform-provider-aws/names"
@@ -148,8 +149,8 @@ func (r *apiKeyCredentialProviderResource) Read(ctx context.Context, request res
148149

149150
name := fwflex.StringValueFromFramework(ctx, data.Name)
150151
out, err := findAPIKeyCredentialProviderByName(ctx, conn, name)
151-
if tfresource.NotFound(err) {
152-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
152+
if retry.NotFound(err) {
153+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
153154
response.State.RemoveResource(ctx)
154155
return
155156
}

internal/service/bedrockagentcore/browser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ func (r *browserResource) Read(ctx context.Context, request resource.ReadRequest
265265

266266
browserID := fwflex.StringValueFromFramework(ctx, data.BrowserID)
267267
out, err := findBrowserByID(ctx, conn, browserID)
268-
if tfresource.NotFound(err) {
269-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
268+
if retry.NotFound(err) {
269+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
270270
response.State.RemoveResource(ctx)
271271
return
272272
}
@@ -352,7 +352,7 @@ func waitBrowserDeleted(ctx context.Context, conn *bedrockagentcorecontrol.Clien
352352
func statusBrowser(conn *bedrockagentcorecontrol.Client, id string) retry.StateRefreshFunc {
353353
return func(ctx context.Context) (any, string, error) {
354354
out, err := findBrowserByID(ctx, conn, id)
355-
if tfresource.NotFound(err) {
355+
if retry.NotFound(err) {
356356
return nil, "", nil
357357
}
358358

internal/service/bedrockagentcore/code_interpreter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ func (r *codeInterpreterResource) Read(ctx context.Context, request resource.Rea
219219

220220
codeInterpreterID := fwflex.StringValueFromFramework(ctx, data.CodeInterpreterID)
221221
out, err := findCodeInterpreterByID(ctx, conn, codeInterpreterID)
222-
if tfresource.NotFound(err) {
223-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
222+
if retry.NotFound(err) {
223+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
224224
response.State.RemoveResource(ctx)
225225
return
226226
}
@@ -306,7 +306,7 @@ func waitCodeInterpreterDeleted(ctx context.Context, conn *bedrockagentcorecontr
306306
func statusCodeInterpreter(conn *bedrockagentcorecontrol.Client, id string) retry.StateRefreshFunc {
307307
return func(ctx context.Context) (any, string, error) {
308308
out, err := findCodeInterpreterByID(ctx, conn, id)
309-
if tfresource.NotFound(err) {
309+
if retry.NotFound(err) {
310310
return nil, "", nil
311311
}
312312

internal/service/bedrockagentcore/gateway.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (r *gatewayResource) Schema(ctx context.Context, request resource.SchemaReq
190190

191191
func (r *gatewayResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
192192
var data gatewayResourceModel
193-
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
193+
smerr.AddEnrich(ctx, &resp.Diagnostics, req.Config.Get(ctx, &data))
194194
if resp.Diagnostics.HasError() {
195195
return
196196
}
@@ -264,8 +264,8 @@ func (r *gatewayResource) Read(ctx context.Context, request resource.ReadRequest
264264

265265
gatewayID := fwflex.StringValueFromFramework(ctx, data.GatewayID)
266266
out, err := findGatewayByID(ctx, conn, gatewayID)
267-
if tfresource.NotFound(err) {
268-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
267+
if retry.NotFound(err) {
268+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
269269
response.State.RemoveResource(ctx)
270270
return
271271
}
@@ -412,7 +412,7 @@ func waitGatewayDeleted(ctx context.Context, conn *bedrockagentcorecontrol.Clien
412412
func statusGateway(conn *bedrockagentcorecontrol.Client, id string) retry.StateRefreshFunc {
413413
return func(ctx context.Context) (any, string, error) {
414414
out, err := findGatewayByID(ctx, conn, id)
415-
if tfresource.NotFound(err) {
415+
if retry.NotFound(err) {
416416
return nil, "", nil
417417
}
418418

internal/service/bedrockagentcore/gateway_target.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ func (r *gatewayTargetResource) Read(ctx context.Context, request resource.ReadR
525525

526526
gatewayIdentifier, targetID := fwflex.StringValueFromFramework(ctx, data.GatewayIdentifier), fwflex.StringValueFromFramework(ctx, data.TargetID)
527527
out, err := findGatewayTargetByTwoPartKey(ctx, conn, gatewayIdentifier, targetID)
528-
if tfresource.NotFound(err) {
529-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
528+
if retry.NotFound(err) {
529+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
530530
response.State.RemoveResource(ctx)
531531
return
532532
}
@@ -616,7 +616,7 @@ func (r *gatewayTargetResource) ImportState(ctx context.Context, request resourc
616616
parts := strings.Split(request.ID, ",")
617617

618618
if len(parts) != 2 {
619-
response.Diagnostics.AddError("Resource Import Invalid ID", fmt.Sprintf(`Unexpected format for import ID (%s), use: "GatewayIdentifier,TargetId"`, request.ID))
619+
smerr.AddError(ctx, &response.Diagnostics, fmt.Errorf(`Unexpected format for import ID (%s), use: "GatewayIdentifier,TargetId"`, request.ID))
620620
return
621621
}
622622

@@ -709,7 +709,7 @@ func waitGatewayTargetDeleted(ctx context.Context, conn *bedrockagentcorecontrol
709709
func statusGatewayTarget(conn *bedrockagentcorecontrol.Client, gatewayIdentifier, targetID string) retry.StateRefreshFunc {
710710
return func(ctx context.Context) (any, string, error) {
711711
out, err := findGatewayTargetByTwoPartKey(ctx, conn, gatewayIdentifier, targetID)
712-
if tfresource.NotFound(err) {
712+
if retry.NotFound(err) {
713713
return nil, "", nil
714714
}
715715

internal/service/bedrockagentcore/memory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ func (r *memoryResource) Read(ctx context.Context, request resource.ReadRequest,
177177

178178
memoryID := fwflex.StringValueFromFramework(ctx, data.ID)
179179
out, err := findMemoryByID(ctx, conn, memoryID)
180-
if tfresource.NotFound(err) {
181-
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
180+
if retry.NotFound(err) {
181+
smerr.AddOne(ctx, &response.Diagnostics, fwdiag.NewResourceNotFoundWarningDiagnostic(err))
182182
response.State.RemoveResource(ctx)
183183
return
184184
}
@@ -299,7 +299,7 @@ func waitMemoryDeleted(ctx context.Context, conn *bedrockagentcorecontrol.Client
299299
func statusMemory(conn *bedrockagentcorecontrol.Client, id string) retry.StateRefreshFunc {
300300
return func(ctx context.Context) (any, string, error) {
301301
out, err := findMemoryByID(ctx, conn, id)
302-
if tfresource.NotFound(err) {
302+
if retry.NotFound(err) {
303303
return nil, "", nil
304304
}
305305

0 commit comments

Comments
 (0)