From a3dd4fc028b418884a7489a2f5c5dcc39bbd854c Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 9 Aug 2024 16:09:07 +0100 Subject: [PATCH 1/7] Prepare agent after knowledge base association --- .../agent_knowledge_base_association.go | 28 +++++++++++++++++++ ...t_knowledge_base_association.html.markdown | 9 ++++++ 2 files changed, 37 insertions(+) diff --git a/internal/service/bedrockagent/agent_knowledge_base_association.go b/internal/service/bedrockagent/agent_knowledge_base_association.go index 4a5d0d25b05..ea6fdd20578 100644 --- a/internal/service/bedrockagent/agent_knowledge_base_association.go +++ b/internal/service/bedrockagent/agent_knowledge_base_association.go @@ -6,10 +6,12 @@ package bedrockagent import ( "context" "fmt" + "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/bedrockagent" awstypes "github.com/aws/aws-sdk-go-v2/service/bedrockagent/types" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -33,12 +35,17 @@ import ( func newAgentKnowledgeBaseAssociationResource(context.Context) (resource.ResourceWithConfigure, error) { r := &agentKnowledgeBaseAssociationResource{} + r.SetDefaultCreateTimeout(5 * time.Minute) + r.SetDefaultUpdateTimeout(5 * time.Minute) + r.SetDefaultDeleteTimeout(5 * time.Minute) + return r, nil } type agentKnowledgeBaseAssociationResource struct { framework.ResourceWithConfigure framework.WithImportByID + framework.WithTimeouts } func (*agentKnowledgeBaseAssociationResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { @@ -83,6 +90,13 @@ func (r *agentKnowledgeBaseAssociationResource) Schema(ctx context.Context, requ CustomType: fwtypes.StringEnumType[awstypes.KnowledgeBaseState](), }, }, + Blocks: map[string]schema.Block{ + names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{ + Create: true, + Update: true, + Delete: true, + }), + }, } } @@ -111,6 +125,13 @@ func (r *agentKnowledgeBaseAssociationResource) Create(ctx context.Context, requ // Set values for unknowns. data.setID() + _, err = prepareAgent(ctx, conn, data.AgentID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) + if err != nil { + response.Diagnostics.AddError("preparing Agent", err.Error()) + + return + } + response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -178,6 +199,12 @@ func (r *agentKnowledgeBaseAssociationResource) Update(ctx context.Context, requ return } + _, err = prepareAgent(ctx, conn, new.AgentID.ValueString(), r.CreateTimeout(ctx, new.Timeouts)) + if err != nil { + response.Diagnostics.AddError("preparing Agent", err.Error()) + + return + } response.Diagnostics.Append(response.State.Set(ctx, &new)...) } @@ -242,6 +269,7 @@ type agentKnowledgeBaseAssociationResourceModel struct { ID types.String `tfsdk:"id"` KnowledgeBaseID types.String `tfsdk:"knowledge_base_id"` KnowledgeBaseState fwtypes.StringEnum[awstypes.KnowledgeBaseState] `tfsdk:"knowledge_base_state"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } const ( diff --git a/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown b/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown index 3fbb4d839fe..62ab1ebc931 100644 --- a/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown +++ b/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown @@ -41,6 +41,15 @@ This resource exports the following attributes in addition to the arguments abov * `id` - Agent ID, agent version, and knowledge base ID separated by `,`. +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `5m`) +* `update` - (Default `5m`) +* `delete` - (Default `5m`) + + ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Agents for Amazon Bedrock Agent Knowledge Base Association using the agent ID, the agent version, and the knowledge base ID separated by `,`. For example: From 7ea82e2791678934903310e78ad7e82b5b282113 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 9 Aug 2024 16:12:43 +0100 Subject: [PATCH 2/7] Add changelog --- .changelog/38799.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/38799.txt diff --git a/.changelog/38799.txt b/.changelog/38799.txt new file mode 100644 index 00000000000..7ed197f932d --- /dev/null +++ b/.changelog/38799.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_bedrockagent_agent_knowledge_base_association: Prepare agent when associating a knowledge base so it can be used. +``` From 966e83093500380d2aed96fedf1e0e7ed68f14e4 Mon Sep 17 00:00:00 2001 From: Andrew Tulloch Date: Fri, 9 Aug 2024 16:51:20 +0100 Subject: [PATCH 3/7] Fix extra newline --- .../bedrockagent_agent_knowledge_base_association.html.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown b/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown index 62ab1ebc931..991aa61d961 100644 --- a/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown +++ b/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown @@ -49,7 +49,6 @@ This resource exports the following attributes in addition to the arguments abov * `update` - (Default `5m`) * `delete` - (Default `5m`) - ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Agents for Amazon Bedrock Agent Knowledge Base Association using the agent ID, the agent version, and the knowledge base ID separated by `,`. For example: From 4e33447ea70e3f0fb264f53ca1f8b0d736304678 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 9 Aug 2024 13:20:27 -0400 Subject: [PATCH 4/7] chore: tweak changelog --- .changelog/38799.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/38799.txt b/.changelog/38799.txt index 7ed197f932d..65c9299a188 100644 --- a/.changelog/38799.txt +++ b/.changelog/38799.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_bedrockagent_agent_knowledge_base_association: Prepare agent when associating a knowledge base so it can be used. +resource/aws_bedrockagent_agent_knowledge_base_association: Prepare agent when associating a knowledge base so it can be used ``` From a718c5c7c9bbb7695d248ada45997a6880a4ef94 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 9 Aug 2024 13:23:51 -0400 Subject: [PATCH 5/7] r/aws_bedrock_agent_knowledge_base: use update timeout during update --- .../service/bedrockagent/agent_knowledge_base_association.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/bedrockagent/agent_knowledge_base_association.go b/internal/service/bedrockagent/agent_knowledge_base_association.go index ea6fdd20578..8cdfbeefc61 100644 --- a/internal/service/bedrockagent/agent_knowledge_base_association.go +++ b/internal/service/bedrockagent/agent_knowledge_base_association.go @@ -199,7 +199,7 @@ func (r *agentKnowledgeBaseAssociationResource) Update(ctx context.Context, requ return } - _, err = prepareAgent(ctx, conn, new.AgentID.ValueString(), r.CreateTimeout(ctx, new.Timeouts)) + _, err = prepareAgent(ctx, conn, new.AgentID.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) if err != nil { response.Diagnostics.AddError("preparing Agent", err.Error()) From 1a7656c4e48fe18aa71c01e3d125ab6a5783295b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 9 Aug 2024 13:25:22 -0400 Subject: [PATCH 6/7] r/aws_bedrock_agent_knowledge_base: remove unused delete timeout --- .../service/bedrockagent/agent_knowledge_base_association.go | 2 -- .../bedrockagent_agent_knowledge_base_association.html.markdown | 1 - 2 files changed, 3 deletions(-) diff --git a/internal/service/bedrockagent/agent_knowledge_base_association.go b/internal/service/bedrockagent/agent_knowledge_base_association.go index 8cdfbeefc61..92c787fdb93 100644 --- a/internal/service/bedrockagent/agent_knowledge_base_association.go +++ b/internal/service/bedrockagent/agent_knowledge_base_association.go @@ -37,7 +37,6 @@ func newAgentKnowledgeBaseAssociationResource(context.Context) (resource.Resourc r.SetDefaultCreateTimeout(5 * time.Minute) r.SetDefaultUpdateTimeout(5 * time.Minute) - r.SetDefaultDeleteTimeout(5 * time.Minute) return r, nil } @@ -94,7 +93,6 @@ func (r *agentKnowledgeBaseAssociationResource) Schema(ctx context.Context, requ names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{ Create: true, Update: true, - Delete: true, }), }, } diff --git a/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown b/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown index 991aa61d961..430a456831e 100644 --- a/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown +++ b/website/docs/r/bedrockagent_agent_knowledge_base_association.html.markdown @@ -47,7 +47,6 @@ This resource exports the following attributes in addition to the arguments abov * `create` - (Default `5m`) * `update` - (Default `5m`) -* `delete` - (Default `5m`) ## Import From c2f986e89824ec230a4c8f07ef8f9dcd9e469fdb Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 9 Aug 2024 14:36:54 -0400 Subject: [PATCH 7/7] chore: make clean-tidy (#38802) --- go.mod | 2 +- tools/tfsdk2fw/go.mod | 1 + tools/tfsdk2fw/go.sum | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index feea6a5caf7..fc4705c2ebf 100644 --- a/go.mod +++ b/go.mod @@ -188,6 +188,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/route53 v1.42.3 github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.3 github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.3 + github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3 github.com/aws/aws-sdk-go-v2/service/rum v1.19.3 github.com/aws/aws-sdk-go-v2/service/s3 v1.58.3 github.com/aws/aws-sdk-go-v2/service/s3control v1.46.3 @@ -294,7 +295,6 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.16 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15 // indirect - github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/boombuler/barcode v1.0.1 // indirect diff --git a/tools/tfsdk2fw/go.mod b/tools/tfsdk2fw/go.mod index b5672af610c..c1681c487e1 100644 --- a/tools/tfsdk2fw/go.mod +++ b/tools/tfsdk2fw/go.mod @@ -210,6 +210,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/route53 v1.42.3 // indirect github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.3 // indirect github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.3 // indirect + github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3 // indirect github.com/aws/aws-sdk-go-v2/service/rum v1.19.3 // indirect github.com/aws/aws-sdk-go-v2/service/s3 v1.58.3 // indirect github.com/aws/aws-sdk-go-v2/service/s3control v1.46.3 // indirect diff --git a/tools/tfsdk2fw/go.sum b/tools/tfsdk2fw/go.sum index b5d73e9a632..18cd73310ed 100644 --- a/tools/tfsdk2fw/go.sum +++ b/tools/tfsdk2fw/go.sum @@ -406,6 +406,8 @@ github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.3 h1:VGLIgiClxmwxBpGzH github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.3/go.mod h1:Kgq5O7ZaDk0mTZmX6YCL+ZtZ1YcJHtGsVubp0OT77MA= github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.3 h1:N4f5sliNiWcp3abC+8YpcaVjXuaNJIlz/dBd+saimm0= github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.3/go.mod h1:r2B4BvTn3zSMK+BFHGl0q63B/nJMOk9/NukLZzqO8sY= +github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3 h1:M6D+IRT6YdeL+qLIdy4u4zEoMOqq3lJnNUGt0cxEI04= +github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3/go.mod h1:y4m7VlTWV77mBzMdAZWjudnobe0E77tKy5Z9+IQIku0= github.com/aws/aws-sdk-go-v2/service/rum v1.19.3 h1:DR+GYJRPL7eEZknnGdwm+lH686LmUBB/X2YVQDHLNY4= github.com/aws/aws-sdk-go-v2/service/rum v1.19.3/go.mod h1:5jFxbuc05P/+BbJvVbBspMbzDR2IFU0LegQG3iUvj8g= github.com/aws/aws-sdk-go-v2/service/s3 v1.58.3 h1:hT8ZAZRIfqBqHbzKTII+CIiY8G2oC9OpLedkZ51DWl8=