Skip to content

Commit

Permalink
Merge branch 'main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Aug 9, 2024
2 parents d88b903 + 3a6086c commit c892542
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/38799.txt
Original file line number Diff line number Diff line change
@@ -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
```
26 changes: 26 additions & 0 deletions internal/service/bedrockagent/agent_knowledge_base_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -33,12 +35,16 @@ import (
func newAgentKnowledgeBaseAssociationResource(context.Context) (resource.ResourceWithConfigure, error) {
r := &agentKnowledgeBaseAssociationResource{}

r.SetDefaultCreateTimeout(5 * time.Minute)
r.SetDefaultUpdateTimeout(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) {
Expand Down Expand Up @@ -83,6 +89,12 @@ 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,
}),
},
}
}

Expand Down Expand Up @@ -111,6 +123,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)...)
}

Expand Down Expand Up @@ -178,6 +197,12 @@ func (r *agentKnowledgeBaseAssociationResource) Update(ctx context.Context, requ

return
}
_, err = prepareAgent(ctx, conn, new.AgentID.ValueString(), r.UpdateTimeout(ctx, new.Timeouts))
if err != nil {
response.Diagnostics.AddError("preparing Agent", err.Error())

return
}

response.Diagnostics.Append(response.State.Set(ctx, &new)...)
}
Expand Down Expand Up @@ -242,6 +267,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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ 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`)

## 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:
Expand Down

0 comments on commit c892542

Please sign in to comment.