-
Notifications
You must be signed in to change notification settings - Fork 5
/
knowledge-base.tf
149 lines (138 loc) · 4.94 KB
/
knowledge-base.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# - Knowledge Base Default OpenSearch -
resource "awscc_bedrock_knowledge_base" "knowledge_base_default" {
count = var.create_default_kb ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}"
description = var.kb_description
role_arn = var.kb_role_arn != null ? var.kb_role_arn : aws_iam_role.bedrock_knowledge_base_role[0].arn
storage_configuration = {
type = "OPENSEARCH_SERVERLESS"
opensearch_serverless_configuration = {
collection_arn = awscc_opensearchserverless_collection.default_collection[0].arn
vector_index_name = opensearch_index.default_oss_index[0].name
field_mapping = {
metadata_field = var.metadata_field
text_field = var.text_field
vector_field = var.vector_field
}
}
}
knowledge_base_configuration = {
type = "VECTOR"
vector_knowledge_base_configuration = {
embedding_model_arn = var.kb_embedding_model_arn
}
}
depends_on = [ time_sleep.wait_after_index_creation ]
}
# – Existing KBs –
# - Mongo –
resource "awscc_bedrock_knowledge_base" "knowledge_base_mongo" {
count = var.create_mongo_config ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}"
description = var.kb_description
role_arn = var.kb_role_arn != null ? var.kb_role_arn : aws_iam_role.bedrock_knowledge_base_role[0].arn
tags = var.kb_tags
storage_configuration = {
type = var.kb_storage_type
mongo_db_atlas_configuration = {
collection_name = var.collection_name
credentials_secret_arn = var.credentials_secret_arn
database_name = var.database_name
endpoint = var.endpoint
vector_index_name = var.vector_index_name
field_mapping = {
metadata_field = var.metadata_field
text_field = var.text_field
vector_field = var.vector_field
}
endpoint_service_name = var.endpoint_service_name
}
}
knowledge_base_configuration = {
type = var.kb_type
vector_knowledge_base_configuration = {
embedding_model_arn = var.kb_embedding_model_arn
}
}
}
# – OpenSearch –
resource "awscc_bedrock_knowledge_base" "knowledge_base_opensearch" {
count = var.create_opensearch_config ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}"
description = var.kb_description
role_arn = var.kb_role_arn != null ? var.kb_role_arn : aws_iam_role.bedrock_knowledge_base_role[0].arn
tags = var.kb_tags
storage_configuration = {
type = var.kb_storage_type
opensearch_serverless_configuration = {
collection_arn = var.collection_arn
vector_index_name = var.vector_index_name
field_mapping = {
metadata_field = var.metadata_field
text_field = var.text_field
vector_field = var.vector_field
}
}
}
knowledge_base_configuration = {
type = var.kb_type
vector_knowledge_base_configuration = {
embedding_model_arn = var.kb_embedding_model_arn
}
}
}
# – Pinecone –
resource "awscc_bedrock_knowledge_base" "knowledge_base_pinecone" {
count = var.create_pinecone_config ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}"
description = var.kb_description
role_arn = var.kb_role_arn != null ? var.kb_role_arn : aws_iam_role.bedrock_knowledge_base_role[0].arn
tags = var.kb_tags
storage_configuration = {
type = var.kb_storage_type
pinecone_configuration = {
connection_string = var.connection_string
credentials_secret_arn = var.credentials_secret_arn
field_mapping = {
metadata_field = var.metadata_field
text_field = var.text_field
}
namespace = var.namespace
}
}
knowledge_base_configuration = {
type = var.kb_type
vector_knowledge_base_configuration = {
embedding_model_arn = var.kb_embedding_model_arn
}
}
}
# – RDS –
resource "awscc_bedrock_knowledge_base" "knowledge_base_rds" {
count = var.create_rds_config ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}"
description = var.kb_description
role_arn = var.kb_role_arn != null ? var.kb_role_arn : aws_iam_role.bedrock_knowledge_base_role[0].arn
tags = var.kb_tags
storage_configuration = {
type = var.kb_storage_type
rds_configuration = {
credentials_secret_arn = var.credentials_secret_arn
database_name = var.database_name
resource_arn = var.resource_arn
table_name = var.table_name
field_mapping = {
metadata_field = var.metadata_field
primary_key_field = var.primary_key_field
text_field = var.text_field
vector_field = var.vector_field
}
}
}
knowledge_base_configuration = {
type = var.kb_type
vector_knowledge_base_configuration = {
embedding_model_arn = var.kb_embedding_model_arn
}
}
}