Skip to content

Commit 9b4aca1

Browse files
committed
r/aws_bedrockagentcore_agent_runtime: 'lifecycle_configuration' is Optional+Computed.
1 parent 31ce0ed commit 9b4aca1

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

internal/service/bedrockagentcore/agent_runtime.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (r *agentRuntimeResource) Schema(ctx context.Context, request resource.Sche
8888
CustomType: fwtypes.MapOfStringType,
8989
Optional: true,
9090
},
91+
"lifecycle_configuration": framework.ResourceOptionalComputedListOfObjectsAttribute[lifecycleConfigurationModel](ctx, 1, nil, listplanmodifier.UseStateForUnknown()),
9192
names.AttrRoleARN: schema.StringAttribute{
9293
CustomType: fwtypes.ARNType,
9394
Required: true,
@@ -153,22 +154,6 @@ func (r *agentRuntimeResource) Schema(ctx context.Context, request resource.Sche
153154
},
154155
},
155156
},
156-
"lifecycle_configuration": schema.ListNestedBlock{
157-
CustomType: fwtypes.NewListNestedObjectTypeOf[lifecycleConfigurationModel](ctx),
158-
Validators: []validator.List{
159-
listvalidator.SizeAtMost(1),
160-
},
161-
NestedObject: schema.NestedBlockObject{
162-
Attributes: map[string]schema.Attribute{
163-
"idle_runtime_session_timeout": schema.Int32Attribute{
164-
Optional: true,
165-
},
166-
"max_lifetime": schema.Int32Attribute{
167-
Optional: true,
168-
},
169-
},
170-
},
171-
},
172157
names.AttrNetworkConfiguration: schema.ListNestedBlock{
173158
CustomType: fwtypes.NewListNestedObjectTypeOf[networkConfigurationModel](ctx),
174159
Validators: []validator.List{
@@ -286,14 +271,22 @@ func (r *agentRuntimeResource) Create(ctx context.Context, request resource.Crea
286271
return
287272
}
288273

289-
// Set values for unknowns.
290-
smerr.EnrichAppend(ctx, &response.Diagnostics, fwflex.Flatten(ctx, out, &data, fwflex.WithFieldNamePrefix("AgentRuntime")))
291-
if response.Diagnostics.HasError() {
274+
agentRuntimeID := aws.ToString(out.AgentRuntimeId)
275+
276+
if _, err := waitAgentRuntimeCreated(ctx, conn, agentRuntimeID, r.CreateTimeout(ctx, data.Timeouts)); err != nil {
277+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
292278
return
293279
}
294280

295-
if _, err := waitAgentRuntimeCreated(ctx, conn, data.AgentRuntimeID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)); err != nil {
296-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.AgentRuntimeName.String())
281+
runtime, err := findAgentRuntimeByID(ctx, conn, agentRuntimeID)
282+
if err != nil {
283+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
284+
return
285+
}
286+
287+
// Set values for unknowns.
288+
smerr.EnrichAppend(ctx, &response.Diagnostics, fwflex.Flatten(ctx, runtime, &data, fwflex.WithFieldNamePrefix("AgentRuntime")))
289+
if response.Diagnostics.HasError() {
297290
return
298291
}
299292

@@ -309,14 +302,15 @@ func (r *agentRuntimeResource) Read(ctx context.Context, request resource.ReadRe
309302

310303
conn := r.Meta().BedrockAgentCoreClient(ctx)
311304

312-
out, err := findAgentRuntimeByID(ctx, conn, data.AgentRuntimeID.ValueString())
305+
agentRuntimeID := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID)
306+
out, err := findAgentRuntimeByID(ctx, conn, agentRuntimeID)
313307
if tfresource.NotFound(err) {
314308
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
315309
response.State.RemoveResource(ctx)
316310
return
317311
}
318312
if err != nil {
319-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.AgentRuntimeID.String())
313+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
320314
return
321315
}
322316

@@ -345,6 +339,7 @@ func (r *agentRuntimeResource) Update(ctx context.Context, request resource.Upda
345339
}
346340

347341
if diff.HasChanges() {
342+
agentRuntimeID := fwflex.StringValueFromFramework(ctx, new.AgentRuntimeID)
348343
var input bedrockagentcorecontrol.UpdateAgentRuntimeInput
349344
smerr.EnrichAppend(ctx, &response.Diagnostics, fwflex.Expand(ctx, new, &input, fwflex.WithFieldNamePrefix("AgentRuntime")))
350345
if response.Diagnostics.HasError() {
@@ -356,7 +351,7 @@ func (r *agentRuntimeResource) Update(ctx context.Context, request resource.Upda
356351

357352
out, err := conn.UpdateAgentRuntime(ctx, &input)
358353
if err != nil {
359-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, new.AgentRuntimeID.String())
354+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
360355
return
361356
}
362357

@@ -365,8 +360,8 @@ func (r *agentRuntimeResource) Update(ctx context.Context, request resource.Upda
365360
return
366361
}
367362

368-
if _, err := waitAgentRuntimeUpdated(ctx, conn, new.AgentRuntimeID.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)); err != nil {
369-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, new.AgentRuntimeID.String())
363+
if _, err := waitAgentRuntimeUpdated(ctx, conn, agentRuntimeID, r.UpdateTimeout(ctx, new.Timeouts)); err != nil {
364+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
370365
return
371366
}
372367
} else {
@@ -385,21 +380,22 @@ func (r *agentRuntimeResource) Delete(ctx context.Context, request resource.Dele
385380

386381
conn := r.Meta().BedrockAgentCoreClient(ctx)
387382

383+
agentRuntimeID := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID)
388384
input := bedrockagentcorecontrol.DeleteAgentRuntimeInput{
389-
AgentRuntimeId: fwflex.StringFromFramework(ctx, data.AgentRuntimeID),
385+
AgentRuntimeId: aws.String(agentRuntimeID),
390386
}
391387

392388
_, err := conn.DeleteAgentRuntime(ctx, &input)
393389
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
394390
return
395391
}
396392
if err != nil {
397-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.AgentRuntimeID.String())
393+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
398394
return
399395
}
400396

401-
if _, err := waitAgentRuntimeDeleted(ctx, conn, data.AgentRuntimeID.ValueString(), r.DeleteTimeout(ctx, data.Timeouts)); err != nil {
402-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.AgentRuntimeID.String())
397+
if _, err := waitAgentRuntimeDeleted(ctx, conn, agentRuntimeID, r.DeleteTimeout(ctx, data.Timeouts)); err != nil {
398+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, agentRuntimeID)
403399
return
404400
}
405401
}

internal/service/bedrockagentcore/agent_runtime_endpoint.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (r *agentRuntimeEndpointResource) Create(ctx context.Context, request resou
107107

108108
conn := r.Meta().BedrockAgentCoreClient(ctx)
109109

110+
agentRuntimeID, name := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID), fwflex.StringValueFromFramework(ctx, data.Name)
110111
var input bedrockagentcorecontrol.CreateAgentRuntimeEndpointInput
111112
smerr.EnrichAppend(ctx, &response.Diagnostics, fwflex.Expand(ctx, data, &input, fwflex.WithFieldNamePrefix("AgentRuntimeEndpoint")))
112113
if response.Diagnostics.HasError() {
@@ -119,16 +120,16 @@ func (r *agentRuntimeEndpointResource) Create(ctx context.Context, request resou
119120

120121
out, err := conn.CreateAgentRuntimeEndpoint(ctx, &input)
121122
if err != nil {
122-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.Name.String())
123+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
123124
return
124125
}
125126

126127
data.AgentRuntimeARN = fwflex.StringToFramework(ctx, out.AgentRuntimeArn)
127128
data.AgentRuntimeEndpointARN = fwflex.StringToFramework(ctx, out.AgentRuntimeEndpointArn)
128129
data.AgentRuntimeVersion = fwflex.StringToFramework(ctx, out.TargetVersion)
129130

130-
if _, err := waitAgentRuntimeEndpointCreated(ctx, conn, data.AgentRuntimeID.ValueString(), data.Name.ValueString(), r.CreateTimeout(ctx, data.Timeouts)); err != nil {
131-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.Name.String())
131+
if _, err := waitAgentRuntimeEndpointCreated(ctx, conn, agentRuntimeID, name, r.CreateTimeout(ctx, data.Timeouts)); err != nil {
132+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
132133
return
133134
}
134135

@@ -144,14 +145,15 @@ func (r *agentRuntimeEndpointResource) Read(ctx context.Context, request resourc
144145

145146
conn := r.Meta().BedrockAgentCoreClient(ctx)
146147

147-
out, err := findAgentRuntimeEndpointByTwoPartKey(ctx, conn, data.AgentRuntimeID.ValueString(), data.Name.ValueString())
148+
agentRuntimeID, name := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID), fwflex.StringValueFromFramework(ctx, data.Name)
149+
out, err := findAgentRuntimeEndpointByTwoPartKey(ctx, conn, agentRuntimeID, name)
148150
if tfresource.NotFound(err) {
149151
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
150152
response.State.RemoveResource(ctx)
151153
return
152154
}
153155
if err != nil {
154-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.Name.String())
156+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
155157
return
156158
}
157159

@@ -181,6 +183,7 @@ func (r *agentRuntimeEndpointResource) Update(ctx context.Context, request resou
181183
}
182184

183185
if diff.HasChanges() {
186+
agentRuntimeID, name := fwflex.StringValueFromFramework(ctx, new.AgentRuntimeID), fwflex.StringValueFromFramework(ctx, new.Name)
184187
var input bedrockagentcorecontrol.UpdateAgentRuntimeEndpointInput
185188
smerr.EnrichAppend(ctx, &response.Diagnostics, fwflex.Expand(ctx, new, &input, fwflex.WithFieldNamePrefix("Endpoint")))
186189
if response.Diagnostics.HasError() {
@@ -192,20 +195,20 @@ func (r *agentRuntimeEndpointResource) Update(ctx context.Context, request resou
192195

193196
out, err := conn.UpdateAgentRuntimeEndpoint(ctx, &input)
194197
if err != nil {
195-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, new.Name.String())
198+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
196199
return
197200
}
198201

199202
new.AgentRuntimeVersion = fwflex.StringToFramework(ctx, out.TargetVersion)
203+
204+
if _, err := waitAgentRuntimeEndpointUpdated(ctx, conn, agentRuntimeID, name, r.UpdateTimeout(ctx, new.Timeouts)); err != nil {
205+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
206+
return
207+
}
200208
} else {
201209
new.AgentRuntimeVersion = old.AgentRuntimeVersion
202210
}
203211

204-
if _, err := waitAgentRuntimeEndpointUpdated(ctx, conn, new.AgentRuntimeID.ValueString(), new.Name.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)); err != nil {
205-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, new.Name.String())
206-
return
207-
}
208-
209212
smerr.EnrichAppend(ctx, &response.Diagnostics, response.State.Set(ctx, &new))
210213
}
211214

@@ -218,10 +221,11 @@ func (r *agentRuntimeEndpointResource) Delete(ctx context.Context, request resou
218221

219222
conn := r.Meta().BedrockAgentCoreClient(ctx)
220223

224+
agentRuntimeID, name := fwflex.StringValueFromFramework(ctx, data.AgentRuntimeID), fwflex.StringValueFromFramework(ctx, data.Name)
221225
input := bedrockagentcorecontrol.DeleteAgentRuntimeEndpointInput{
222-
AgentRuntimeId: fwflex.StringFromFramework(ctx, data.AgentRuntimeID),
226+
AgentRuntimeId: aws.String(agentRuntimeID),
223227
ClientToken: aws.String(sdkid.UniqueId()),
224-
EndpointName: fwflex.StringFromFramework(ctx, data.Name),
228+
EndpointName: aws.String(name),
225229
}
226230

227231
_, err := conn.DeleteAgentRuntimeEndpoint(ctx, &input)
@@ -232,12 +236,12 @@ func (r *agentRuntimeEndpointResource) Delete(ctx context.Context, request resou
232236
return
233237
}
234238
if err != nil {
235-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.Name.String())
239+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
236240
return
237241
}
238242

239-
if _, err := waitAgentRuntimeEndpointDeleted(ctx, conn, data.AgentRuntimeID.ValueString(), data.Name.ValueString(), r.DeleteTimeout(ctx, data.Timeouts)); err != nil {
240-
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, data.Name.String())
243+
if _, err := waitAgentRuntimeEndpointDeleted(ctx, conn, agentRuntimeID, name, r.DeleteTimeout(ctx, data.Timeouts)); err != nil {
244+
smerr.AddError(ctx, &response.Diagnostics, err, smerr.ID, name)
241245
return
242246
}
243247
}

0 commit comments

Comments
 (0)