-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathopensearch.tf
85 lines (80 loc) · 2.35 KB
/
opensearch.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
# – OpenSearch Serverless Default –
module "oss_knowledgebase" {
count = var.create_default_kb ? 1 : 0
source = "aws-ia/opensearch-serverless/aws"
version = "0.0.2"
allow_public_access_network_policy = var.allow_opensearch_public_access
create_vector_index = true
vector_index_mappings = <<-EOF
{
"properties": {
"bedrock-knowledge-base-default-vector": {
"type": "knn_vector",
"dimension": ${var.vector_dimension},
"method": {
"name": "hnsw",
"engine": "faiss",
"parameters": {
"m": 16,
"ef_construction": 512
},
"space_type": "l2"
}
},
"AMAZON_BEDROCK_METADATA": {
"type": "text",
"index": "false"
},
"AMAZON_BEDROCK_TEXT_CHUNK": {
"type": "text",
"index": "true"
}
}
}
EOF
}
resource "aws_opensearchserverless_access_policy" "updated_data_policy" {
count = var.create_default_kb ? 1 : 0
name = "os-access-policy-${random_string.solution_prefix.result}"
type = "data"
policy = jsonencode([
{
Rules = [
{
ResourceType = "index"
Resource = [
"index/${module.oss_knowledgebase[0].opensearch_serverless_collection.name}/*"
]
Permission = [
"aoss:UpdateIndex",
"aoss:DeleteIndex",
"aoss:DescribeIndex",
"aoss:ReadDocument",
"aoss:WriteDocument",
"aoss:CreateIndex"
]
},
{
ResourceType = "collection"
Resource = [
"collection/${module.oss_knowledgebase[0].opensearch_serverless_collection.name}"
]
Permission = [
"aoss:DescribeCollectionItems",
"aoss:DeleteCollectionItems",
"aoss:CreateCollectionItems",
"aoss:UpdateCollectionItems"
]
}
],
Principal = [
var.kb_role_arn != null ? var.kb_role_arn : aws_iam_role.bedrock_knowledge_base_role[0].arn
]
}
])
}
resource "time_sleep" "wait_after_index_creation" {
count = var.create_default_kb ? 1 : 0
depends_on = [ module.oss_knowledgebase[0].vector_index ]
create_duration = "60s" # Wait for 60 seconds before creating the index
}