-
Notifications
You must be signed in to change notification settings - Fork 5
/
data-source.tf
227 lines (213 loc) · 9.15 KB
/
data-source.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
locals {
create_cwl = var.create_default_kb && var.create_kb_log_group
create_delivery = local.create_cwl || var.kb_monitoring_arn != null
create_s3_data_source = var.create_default_kb == true || var.create_s3_data_source == true
vector_ingestion_configuration = {
chunking_configuration = var.chunking_strategy == null ? null : {
chunking_strategy = var.chunking_strategy
fixed_size_chunking_configuration = {
max_tokens = var.chunking_strategy_max_tokens
overlap_percentage = var.chunking_strategy_overlap_percentage
}
hierarchical_chunking_configuration = var.heirarchical_overlap_tokens == null && var.level_configurations_list == null ? null : {
level_configurations = var.level_configurations_list
overlap_tokens = var.heirarchical_overlap_tokens
}
semantic_chunking_configuration = var.breakpoint_percentile_threshold == null && var.semantic_buffer_size == null && var.semantic_max_tokens ? null : {
breakpoint_percentile_threshold = var.breakpoint_percentile_threshold
buffer_size = var.semantic_buffer_size
max_tokens = var.semantic_max_tokens
}
}
custom_transformation_configuration = var.create_custom_tranformation_config == false ? null : {
intermediate_storage = {
s3_location = {
uri = var.s3_location_uri
}
}
transformations = var.transformations_list
}
parsing_configuration = var.create_parsing_configuration == false ? null : {
bedrock_foundation_model_configuration = {
model_arn = var.parsing_config_model_arn
parsing_prompt = {
parsing_prompt_text = var.parsing_prompt_text
}
}
parsing_strategy = var.parsing_strategy
}
}
}
# - Knowledge Base S3 Data Source –
resource "awscc_s3_bucket" "s3_data_source" {
count = local.create_s3_data_source && var.kb_s3_data_source == null ? 1 : 0
bucket_name = "${random_string.solution_prefix.result}-${var.kb_name}-default-bucket"
public_access_block_configuration = {
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
bucket_encryption = {
server_side_encryption_configuration = [{
bucket_key_enabled = true
server_side_encryption_by_default = {
sse_algorithm = var.kb_s3_data_source_kms_arn == null ? "AES256" : "aws:kms"
kms_master_key_id = var.kb_s3_data_source_kms_arn
}
}]
}
tags = [{
key = "Name"
value = "S3 Data Source"
}]
}
resource "aws_bedrockagent_data_source" "knowledge_base_ds" {
count = local.create_s3_data_source ? 1 : 0
knowledge_base_id = var.create_default_kb ? awscc_bedrock_knowledge_base.knowledge_base_default[0].id : var.existing_kb
name = "${random_string.solution_prefix.result}-${var.kb_name}DataSource"
data_source_configuration {
type = "S3"
s3_configuration {
bucket_arn = var.kb_s3_data_source == null ? awscc_s3_bucket.s3_data_source[0].arn : var.kb_s3_data_source # Create an S3 bucket or reference existing
bucket_owner_account_id = var.bucket_owner_account_id
inclusion_prefixes = var.s3_inclusion_prefixes
}
}
}
resource "aws_cloudwatch_log_group" "knowledge_base_cwl" {
#tfsec:ignore:log-group-customer-key
#checkov:skip=CKV_AWS_158:Encryption not required for log group
count = local.create_cwl ? 1 : 0
name = "/aws/vendedlogs/bedrock/knowledge-base/APPLICATION_LOGS/${awscc_bedrock_knowledge_base.knowledge_base_default[0].id}"
retention_in_days = var.kb_log_group_retention_in_days
}
resource "awscc_logs_delivery_source" "knowledge_base_log_source" {
count = local.create_delivery ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}-delivery-source"
log_type = "APPLICATION_LOGS"
resource_arn = awscc_bedrock_knowledge_base.knowledge_base_default[0].knowledge_base_arn
}
resource "awscc_logs_delivery_destination" "knowledge_base_log_destination" {
count = local.create_delivery ? 1 : 0
name = "${random_string.solution_prefix.result}-${var.kb_name}-delivery-destination"
output_format = "json"
destination_resource_arn = local.create_cwl ? aws_cloudwatch_log_group.knowledge_base_cwl[0].arn : var.kb_monitoring_arn
tags = [{
key = "Name"
value = "${random_string.solution_prefix.result}-${var.kb_name}-delivery-destination"
}]
}
resource "awscc_logs_delivery" "knowledge_base_log_delivery" {
count = local.create_delivery ? 1 : 0
delivery_destination_arn = awscc_logs_delivery_destination.knowledge_base_log_destination[0].arn
delivery_source_name = awscc_logs_delivery_source.knowledge_base_log_source[0].name
tags = [{
key = "Name"
value = "${random_string.solution_prefix.result}-${var.kb_name}-delivery"
}]
}
# – Knowledge Base Web Crawler Data Source
resource "awscc_bedrock_data_source" "knowledge_base_web_crawler" {
count = var.create_web_crawler ? 1 : 0
knowledge_base_id = var.create_default_kb ? awscc_bedrock_knowledge_base.knowledge_base_default[0].id : var.existing_kb
name = "${random_string.solution_prefix.result}-${var.kb_name}DataSourceWebCrawler"
data_source_configuration = {
type = "WEB"
web_configuration = {
crawler_configuration = {
crawler_limits = {
rate_limit = var.rate_limit
}
exclusion_filters = var.exclusion_filters
inclusion_filters = var.inclusion_filters
scope = var.crawler_scope
}
source_configuration = {
url_configuration = {
seed_urls = var.seed_urls
}
}
}
}
vector_ingestion_configuration = var.create_vector_ingestion_configuration == false ? null : local.vector_ingestion_configuration
}
# – Knowledge Base Confluence Data Source
resource "awscc_bedrock_data_source" "knowledge_base_confluence" {
count = var.create_confluence ? 1 : 0
knowledge_base_id = var.create_default_kb ? awscc_bedrock_knowledge_base.knowledge_base_default[0].id : var.existing_kb
name = "${random_string.solution_prefix.result}-${var.kb_name}DataSourceConfluence"
data_source_configuration = {
type = "CONFLUENCE"
confluence_configuration = {
crawler_configuration = {
filter_configuration = {
pattern_object_filter = {
filters = var.pattern_object_filter_list
}
type = var.crawl_filter_type
}
}
source_configuration = {
auth_type = var.auth_type
credentials_secret_arn = var.confluence_credentials_secret_arn
host_type = var.host_type
host_url = var.host_url
}
}
}
vector_ingestion_configuration = var.create_vector_ingestion_configuration == false ? null : local.vector_ingestion_configuration
}
# – Knowledge Base Sharepoint Data Source
resource "awscc_bedrock_data_source" "knowledge_base_sharepoint" {
count = var.create_sharepoint ? 1 : 0
knowledge_base_id = var.create_default_kb ? awscc_bedrock_knowledge_base.knowledge_base_default[0].id : var.existing_kb
name = "${random_string.solution_prefix.result}-${var.kb_name}DataSourceSharepoint"
data_source_configuration = {
type = "SHAREPOINT"
share_point_configuration = {
crawler_configuration = {
filter_configuration = {
pattern_object_filter ={
filters = var.pattern_object_filter_list
}
type = var.crawl_filter_type
}
}
source_configuration = {
auth_type = var.auth_type
credentials_secret_arn = var.share_point_credentials_secret_arn
domain = var.share_point_domain
host_type = var.host_type
site_urls = var.share_point_site_urls
tenant_id = var.tenant_id
}
}
}
vector_ingestion_configuration = var.create_vector_ingestion_configuration == false ? null : local.vector_ingestion_configuration
}
# – Knowledge Base Salesforce Data Source
resource "awscc_bedrock_data_source" "knowledge_base_salesforce" {
count = var.create_salesforce ? 1 : 0
knowledge_base_id = var.create_default_kb ? awscc_bedrock_knowledge_base.knowledge_base_default[0].id : var.existing_kb
name = "${random_string.solution_prefix.result}-${var.kb_name}DataSourceSalesforce"
data_source_configuration = {
type = "SALESFORCE"
salesforce_configuration = {
crawler_configuration = {
filter_configuration = {
pattern_object_filter = {
filters = var.pattern_object_filter_list
}
type = var.crawl_filter_type
}
}
source_configuration = {
auth_type = var.auth_type
credentials_secret_arn = var.salesforce_credentials_secret_arn
host_url = var.host_url
}
}
}
vector_ingestion_configuration = var.create_vector_ingestion_configuration == false ? null : local.vector_ingestion_configuration
}