@@ -488,6 +488,79 @@ func testAccKnowledgeBase_OpenSearchManagedCluster_basic(t *testing.T) {
488488 "pinecone_configuration" : knownvalue .ListSizeExact (0 ),
489489 "rds_configuration" : knownvalue .ListSizeExact (0 ),
490490 "redis_enterprise_cloud_configuration" : knownvalue .ListSizeExact (0 ),
491+ "s3_vectors" : knownvalue .ListSizeExact (0 ),
492+ }),
493+ })),
494+ },
495+ },
496+ },
497+ })
498+ }
499+
500+ func testAccKnowledgeBase_S3Vectors_update (t * testing.T ) {
501+ ctx := acctest .Context (t )
502+ var knowledgebase awstypes.KnowledgeBase
503+ rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
504+ resourceName := "aws_bedrockagent_knowledge_base.test"
505+ foundationModel := "amazon.titan-embed-text-v2:0"
506+
507+ resource .Test (t , resource.TestCase {
508+ PreCheck : func () {
509+ acctest .PreCheck (ctx , t )
510+ },
511+ ErrorCheck : acctest .ErrorCheck (t , names .BedrockAgentServiceID ),
512+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
513+ CheckDestroy : testAccCheckKnowledgeBaseDestroy (ctx ),
514+ Steps : []resource.TestStep {
515+ {
516+ Config : testAccKnowledgeBaseConfig_S3VectorsByIndexARN (rName , foundationModel ),
517+ ConfigPlanChecks : resource.ConfigPlanChecks {
518+ PreApply : []plancheck.PlanCheck {
519+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionCreate ),
520+ },
521+ },
522+ Check : resource .ComposeTestCheckFunc (
523+ testAccCheckKnowledgeBaseExists (ctx , resourceName , & knowledgebase ),
524+ ),
525+ ConfigStateChecks : []statecheck.StateCheck {
526+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("storage_configuration" ), knownvalue .ListExact ([]knownvalue.Check {
527+ knownvalue .MapExact (map [string ]knownvalue.Check {
528+ "opensearch_managed_cluster_configuration" : knownvalue .ListSizeExact (0 ),
529+ "opensearch_serverless_configuration" : knownvalue .ListSizeExact (0 ),
530+ names .AttrType : tfknownvalue .StringExact (awstypes .KnowledgeBaseStorageTypeS3Vectors ),
531+ "pinecone_configuration" : knownvalue .ListSizeExact (0 ),
532+ "rds_configuration" : knownvalue .ListSizeExact (0 ),
533+ "redis_enterprise_cloud_configuration" : knownvalue .ListSizeExact (0 ),
534+ "s3_vectors_configuration" : knownvalue .ListSizeExact (1 ),
535+ }),
536+ })),
537+ },
538+ },
539+ {
540+ ResourceName : resourceName ,
541+ ImportState : true ,
542+ ImportStateVerify : true ,
543+ },
544+ {
545+ Config : testAccKnowledgeBaseConfig_S3VectorsByIndexName (rName , foundationModel ),
546+ ConfigPlanChecks : resource.ConfigPlanChecks {
547+ PreApply : []plancheck.PlanCheck {
548+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionDestroyBeforeCreate ),
549+ },
550+ },
551+ Check : resource .ComposeTestCheckFunc (
552+ testAccCheckKnowledgeBaseExists (ctx , resourceName , & knowledgebase ),
553+ ),
554+ ConfigStateChecks : []statecheck.StateCheck {
555+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("storage_configuration" ), knownvalue .ListExact ([]knownvalue.Check {
556+ knownvalue .MapExact (map [string ]knownvalue.Check {
557+ "opensearch_managed_cluster_configuration" : knownvalue .ListSizeExact (0 ),
558+ "opensearch_serverless_configuration" : knownvalue .ListSizeExact (0 ),
559+ names .AttrType : tfknownvalue .StringExact (awstypes .KnowledgeBaseStorageTypeS3Vectors ),
560+ "pinecone_configuration" : knownvalue .ListSizeExact (0 ),
561+ "rds_configuration" : knownvalue .ListSizeExact (0 ),
562+ "redis_enterprise_cloud_configuration" : knownvalue .ListSizeExact (0 ),
563+ "s3_vectors_configuration" : knownvalue .ListSizeExact (1 ),
491564 }),
492565 })),
493566 },
@@ -1416,3 +1489,140 @@ resource "aws_bedrockagent_knowledge_base" "test" {
14161489}
14171490` , rName , model ))
14181491}
1492+
1493+ func testAccKnowledgeBaseConfig_baseS3Vectors (rName string ) string {
1494+ return fmt .Sprintf (`
1495+ data "aws_region" "current" {}
1496+ data "aws_partition" "current" {}
1497+
1498+ data "aws_iam_policy_document" "assume_role_bedrock" {
1499+ statement {
1500+ effect = "Allow"
1501+ principals {
1502+ type = "Service"
1503+ identifiers = ["bedrock.amazonaws.com"]
1504+ }
1505+ actions = ["sts:AssumeRole"]
1506+ }
1507+ }
1508+
1509+ data "aws_iam_policy_document" "bedrock" {
1510+ statement {
1511+ effect = "Allow"
1512+ actions = ["bedrock:InvokeModel"]
1513+ resources = ["*"]
1514+ }
1515+ statement {
1516+ effect = "Allow"
1517+ actions = ["s3:ListBucket", "s3:GetObject"]
1518+ resources = ["*"]
1519+ }
1520+ statement {
1521+ effect = "Allow"
1522+ actions = [
1523+ "s3vectors:GetIndex",
1524+ "s3vectors:QueryVectors",
1525+ "s3vectors:PutVectors",
1526+ "s3vectors:GetVectors",
1527+ "s3vectors:DeleteVectors"
1528+ ]
1529+ resources = ["*"]
1530+ }
1531+ }
1532+
1533+ resource "aws_iam_role" "test" {
1534+ assume_role_policy = data.aws_iam_policy_document.assume_role_bedrock.json
1535+ name = %[1]q
1536+ }
1537+
1538+ resource "aws_iam_role_policy" "test" {
1539+ role = aws_iam_role.test.name
1540+ policy = data.aws_iam_policy_document.bedrock.json
1541+ }
1542+
1543+ resource "aws_s3vectors_vector_bucket" "test" {
1544+ vector_bucket_name = %[1]q
1545+ force_destroy = true
1546+ }
1547+
1548+ resource "aws_s3vectors_index" "test" {
1549+ index_name = %[1]q
1550+ vector_bucket_name = aws_s3vectors_vector_bucket.test.vector_bucket_name
1551+
1552+ data_type = "float32"
1553+ dimension = 256
1554+ distance_metric = "euclidean"
1555+ }
1556+ ` , rName )
1557+ }
1558+
1559+ func testAccKnowledgeBaseConfig_S3VectorsByIndexARN (rName , model string ) string {
1560+ return acctest .ConfigCompose (testAccKnowledgeBaseConfig_baseS3Vectors (rName ), fmt .Sprintf (`
1561+ resource "aws_bedrockagent_knowledge_base" "test" {
1562+ depends_on = [
1563+ aws_iam_role_policy.test,
1564+ ]
1565+
1566+ name = %[1]q
1567+ role_arn = aws_iam_role.test.arn
1568+
1569+ knowledge_base_configuration {
1570+ type = "VECTOR"
1571+
1572+ vector_knowledge_base_configuration {
1573+ embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.region}::foundation-model/%[2]s"
1574+ embedding_model_configuration {
1575+ bedrock_embedding_model_configuration {
1576+ dimensions = 256
1577+ embedding_data_type = "FLOAT32"
1578+ }
1579+ }
1580+ }
1581+ }
1582+
1583+ storage_configuration {
1584+ type = "S3_VECTORS"
1585+
1586+ s3_vectors_configuration {
1587+ index_arn = aws_s3vectors_index.test.index_arn
1588+ }
1589+ }
1590+ }
1591+ ` , rName , model ))
1592+ }
1593+
1594+ func testAccKnowledgeBaseConfig_S3VectorsByIndexName (rName , model string ) string {
1595+ return acctest .ConfigCompose (testAccKnowledgeBaseConfig_baseS3Vectors (rName ), fmt .Sprintf (`
1596+ resource "aws_bedrockagent_knowledge_base" "test" {
1597+ depends_on = [
1598+ aws_iam_role_policy.test,
1599+ ]
1600+
1601+ name = %[1]q
1602+ role_arn = aws_iam_role.test.arn
1603+
1604+ knowledge_base_configuration {
1605+ type = "VECTOR"
1606+
1607+ vector_knowledge_base_configuration {
1608+ embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.region}::foundation-model/%[2]s"
1609+ embedding_model_configuration {
1610+ bedrock_embedding_model_configuration {
1611+ dimensions = 256
1612+ embedding_data_type = "FLOAT32"
1613+ }
1614+ }
1615+ }
1616+ }
1617+
1618+ storage_configuration {
1619+ type = "S3_VECTORS"
1620+
1621+ s3_vectors_configuration {
1622+ index_name = aws_s3vectors_index.test.index_name
1623+ vector_bucket_arn = aws_s3vectors_vector_bucket.test.vector_bucket_arn
1624+ }
1625+ }
1626+ }
1627+ ` , rName , model ))
1628+ }
0 commit comments