Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/48904.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_bedrockagent_knowledge_base: Add support for Managed Knowledge Base type (`type = "MANAGED"`) with `managed_knowledge_base_configuration` block
```

```release-note:enhancement
resource/aws_bedrockagent_data_source: Add support for `MANAGED_KNOWLEDGE_BASE_CONNECTOR` data source type with `connector_parameters`, `media_extraction_configuration`, and `deletion_protection_configuration`
```
118 changes: 112 additions & 6 deletions internal/service/bedrockagent/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,83 @@ func (r *dataSourceResource) Schema(ctx context.Context, request resource.Schema
},
},
},
"managed_knowledge_base_connector_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[managedKnowledgeBaseConnectorConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"connector_parameters": schema.StringAttribute{
Optional: true,
},
},
Blocks: map[string]schema.Block{
"deletion_protection_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[deletionProtectionConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"enable_deletion_protection": schema.BoolAttribute{
Optional: true,
},
},
},
},
"media_extraction_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[mediaExtractionConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Blocks: map[string]schema.Block{
"audio_extraction_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[audioExtractionConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"audio_extraction_status": schema.StringAttribute{
Optional: true,
},
},
},
},
"image_extraction_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[imageExtractionConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"image_extraction_status": schema.StringAttribute{
Optional: true,
},
},
},
},
"video_extraction_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[videoExtractionConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"video_extraction_status": schema.StringAttribute{
Optional: true,
},
},
},
},
},
},
},
},
},
},
"s3_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[s3DataSourceConfigurationModel](ctx),
Validators: []validator.List{
Expand Down Expand Up @@ -1101,12 +1178,41 @@ func (m *dataSourceResourceModel) setID() (string, error) {
}

type dataSourceConfigurationModel struct {
ConfluenceConfiguration fwtypes.ListNestedObjectValueOf[confluenceDataSourceConfigurationModel] `tfsdk:"confluence_configuration"`
S3Configuration fwtypes.ListNestedObjectValueOf[s3DataSourceConfigurationModel] `tfsdk:"s3_configuration"`
SalesforceConfiguration fwtypes.ListNestedObjectValueOf[salesforceDataSourceConfigurationModel] `tfsdk:"salesforce_configuration"`
SharePointConfiguration fwtypes.ListNestedObjectValueOf[sharepointDataSourceConfigurationModel] `tfsdk:"share_point_configuration"`
Type fwtypes.StringEnum[awstypes.DataSourceType] `tfsdk:"type"`
WebConfiguration fwtypes.ListNestedObjectValueOf[webDataSourceConfigurationModel] `tfsdk:"web_configuration"`
ConfluenceConfiguration fwtypes.ListNestedObjectValueOf[confluenceDataSourceConfigurationModel] `tfsdk:"confluence_configuration"`
ManagedKnowledgeBaseConnectorConfiguration fwtypes.ListNestedObjectValueOf[managedKnowledgeBaseConnectorConfigurationModel] `tfsdk:"managed_knowledge_base_connector_configuration"`
S3Configuration fwtypes.ListNestedObjectValueOf[s3DataSourceConfigurationModel] `tfsdk:"s3_configuration"`
SalesforceConfiguration fwtypes.ListNestedObjectValueOf[salesforceDataSourceConfigurationModel] `tfsdk:"salesforce_configuration"`
SharePointConfiguration fwtypes.ListNestedObjectValueOf[sharepointDataSourceConfigurationModel] `tfsdk:"share_point_configuration"`
Type fwtypes.StringEnum[awstypes.DataSourceType] `tfsdk:"type"`
WebConfiguration fwtypes.ListNestedObjectValueOf[webDataSourceConfigurationModel] `tfsdk:"web_configuration"`
}

type managedKnowledgeBaseConnectorConfigurationModel struct {
ConnectorParameters types.String `tfsdk:"connector_parameters"`
DeletionProtectionConfiguration fwtypes.ListNestedObjectValueOf[deletionProtectionConfigurationModel] `tfsdk:"deletion_protection_configuration"`
MediaExtractionConfiguration fwtypes.ListNestedObjectValueOf[mediaExtractionConfigurationModel] `tfsdk:"media_extraction_configuration"`
}

type deletionProtectionConfigurationModel struct {
EnableDeletionProtection types.Bool `tfsdk:"enable_deletion_protection"`
}

type mediaExtractionConfigurationModel struct {
AudioExtractionConfiguration fwtypes.ListNestedObjectValueOf[audioExtractionConfigurationModel] `tfsdk:"audio_extraction_configuration"`
ImageExtractionConfiguration fwtypes.ListNestedObjectValueOf[imageExtractionConfigurationModel] `tfsdk:"image_extraction_configuration"`
VideoExtractionConfiguration fwtypes.ListNestedObjectValueOf[videoExtractionConfigurationModel] `tfsdk:"video_extraction_configuration"`
}

type audioExtractionConfigurationModel struct {
AudioExtractionStatus types.String `tfsdk:"audio_extraction_status"`
}

type imageExtractionConfigurationModel struct {
ImageExtractionStatus types.String `tfsdk:"image_extraction_status"`
}

type videoExtractionConfigurationModel struct {
VideoExtractionStatus types.String `tfsdk:"video_extraction_status"`
}

type confluenceDataSourceConfigurationModel struct {
Expand Down
111 changes: 107 additions & 4 deletions internal/service/bedrockagent/knowledge_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch
listvalidator.SizeAtMost(1),
listvalidator.ExactlyOneOf(
path.MatchRelative().AtParent().AtName("kendra_knowledge_base_configuration"),
path.MatchRelative().AtParent().AtName("managed_knowledge_base_configuration"),
path.MatchRelative().AtParent().AtName("sql_knowledge_base_configuration"),
path.MatchRelative().AtParent().AtName("vector_knowledge_base_configuration"),
),
Expand All @@ -145,6 +146,96 @@ func (r *knowledgeBaseResource) Schema(ctx context.Context, request resource.Sch
},
},
},
"managed_knowledge_base_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[managedKnowledgeBaseConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
PlanModifiers: []planmodifier.List{
listplanmodifier.RequiresReplace(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"embedding_model_arn": schema.StringAttribute{
CustomType: fwtypes.ARNType,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"embedding_model_type": schema.StringAttribute{
CustomType: fwtypes.StringEnumType[awstypes.EmbeddingModelType](),
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.UseStateForUnknown(),
},
},
},
Blocks: map[string]schema.Block{
"embedding_model_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[embeddingModelConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
PlanModifiers: []planmodifier.List{
listplanmodifier.RequiresReplace(),
},
NestedObject: schema.NestedBlockObject{
Blocks: map[string]schema.Block{
"bedrock_embedding_model_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[bedrockEmbeddingModelConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
PlanModifiers: []planmodifier.List{
listplanmodifier.RequiresReplace(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"dimensions": schema.Int64Attribute{
Optional: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplace(),
},
},
"embedding_data_type": schema.StringAttribute{
CustomType: fwtypes.StringEnumType[awstypes.EmbeddingDataType](),
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
},
},
},
},
},
"server_side_encryption_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[managedKBServerSideEncryptionConfigurationModel](ctx),
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
PlanModifiers: []planmodifier.List{
listplanmodifier.RequiresReplace(),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
names.AttrKMSKeyARN: schema.StringAttribute{
CustomType: fwtypes.ARNType,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
},
},
},
},
},
"sql_knowledge_base_configuration": schema.ListNestedBlock{
CustomType: fwtypes.NewListNestedObjectTypeOf[sqlKnowledgeBaseConfigurationModel](ctx),
Validators: []validator.List{
Expand Down Expand Up @@ -1530,10 +1621,11 @@ type knowledgeBaseResourceModel struct {
}

type knowledgeBaseConfigurationModel struct {
KendraKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[kendraKnowledgeBaseConfigurationModel] `tfsdk:"kendra_knowledge_base_configuration"`
SQLKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[sqlKnowledgeBaseConfigurationModel] `tfsdk:"sql_knowledge_base_configuration"`
Type fwtypes.StringEnum[awstypes.KnowledgeBaseType] `tfsdk:"type"`
VectorKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[vectorKnowledgeBaseConfigurationModel] `tfsdk:"vector_knowledge_base_configuration"`
KendraKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[kendraKnowledgeBaseConfigurationModel] `tfsdk:"kendra_knowledge_base_configuration"`
ManagedKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[managedKnowledgeBaseConfigurationModel] `tfsdk:"managed_knowledge_base_configuration"`
SQLKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[sqlKnowledgeBaseConfigurationModel] `tfsdk:"sql_knowledge_base_configuration"`
Type fwtypes.StringEnum[awstypes.KnowledgeBaseType] `tfsdk:"type"`
VectorKnowledgeBaseConfiguration fwtypes.ListNestedObjectValueOf[vectorKnowledgeBaseConfigurationModel] `tfsdk:"vector_knowledge_base_configuration"`
}

type kendraKnowledgeBaseConfigurationModel struct {
Expand Down Expand Up @@ -1626,6 +1718,17 @@ type vectorKnowledgeBaseConfigurationModel struct {
SupplementalDataStorageConfiguration fwtypes.ListNestedObjectValueOf[supplementalDataStorageConfigurationModel] `tfsdk:"supplemental_data_storage_configuration"`
}

type managedKnowledgeBaseConfigurationModel struct {
EmbeddingModelARN fwtypes.ARN `tfsdk:"embedding_model_arn"`
EmbeddingModelConfiguration fwtypes.ListNestedObjectValueOf[embeddingModelConfigurationModel] `tfsdk:"embedding_model_configuration"`
EmbeddingModelType fwtypes.StringEnum[awstypes.EmbeddingModelType] `tfsdk:"embedding_model_type"`
ServerSideEncryptionConfiguration fwtypes.ListNestedObjectValueOf[managedKBServerSideEncryptionConfigurationModel] `tfsdk:"server_side_encryption_configuration"`
}

type managedKBServerSideEncryptionConfigurationModel struct {
KMSKeyARN fwtypes.ARN `tfsdk:"kms_key_arn"`
}

type embeddingModelConfigurationModel struct {
BedrockEmbeddingModelConfiguration fwtypes.ListNestedObjectValueOf[bedrockEmbeddingModelConfigurationModel] `tfsdk:"bedrock_embedding_model_configuration"`
}
Expand Down
84 changes: 84 additions & 0 deletions internal/service/bedrockagent/knowledge_base_managed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright IBM Corp. 2014, 2026
// SPDX-License-Identifier: MPL-2.0

package bedrockagent_test

import (
"fmt"
"testing"

awstypes "github.com/aws/aws-sdk-go-v2/service/bedrockagent/types"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
tfknownvalue "github.com/hashicorp/terraform-provider-aws/internal/acctest/knownvalue"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccBedrockAgentKnowledgeBase_managed(t *testing.T) {
ctx := acctest.Context(t)
var kb awstypes.KnowledgeBase
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
resourceName := "aws_bedrockagent_knowledge_base.test"

acctest.ParallelTest(ctx, t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx, t),
Steps: []resource.TestStep{
{
Config: testAccKnowledgeBaseConfig_managed(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKnowledgeBaseExists(ctx, t, resourceName, &kb),
),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("knowledge_base_configuration").AtSliceIndex(0).AtMapKey(names.AttrType), tfknownvalue.StringExact(awstypes.KnowledgeBaseTypeManaged)),
},
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccKnowledgeBaseConfig_managed(rName string) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_iam_role" "test" {
name = %[1]q

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "bedrock.amazonaws.com" }
Action = "sts:AssumeRole"
Condition = {
StringEquals = {
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
}
}
}]
})
}

resource "aws_bedrockagent_knowledge_base" "test" {
name = %[1]q
role_arn = aws_iam_role.test.arn

knowledge_base_configuration {
type = "MANAGED"

managed_knowledge_base_configuration {
embedding_model_type = "MANAGED"
}
}
}
`, rName)
}
Loading