-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.tf
109 lines (101 loc) · 2.74 KB
/
data.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
data "aws_caller_identity" "this" {}
data "aws_region" "this" {}
data "aws_iam_session_context" "this" {
arn = data.aws_caller_identity.this.arn
}
data "aws_bedrock_foundation_model" "agent" {
model_id = var.agent_model_id
}
data "aws_bedrock_foundation_model" "knowledgebase" {
model_id = var.knowledgebase_model_id
}
data "aws_iam_policy_document" "agent_trust" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["bedrock.amazonaws.com"]
type = "Service"
}
condition {
test = "StringEquals"
values = [data.aws_caller_identity.this.account_id]
variable = "aws:SourceAccount"
}
condition {
test = "ArnLike"
values = ["arn:aws:bedrock:${data.aws_region.this.name}:${data.aws_caller_identity.this.account_id}:agent/*"]
variable = "AWS:SourceArn"
}
}
}
data "aws_iam_policy_document" "agent_permissions" {
statement {
actions = ["bedrock:InvokeModel"]
resources = [
data.aws_bedrock_foundation_model.agent.model_arn,
]
}
statement {
actions = ["bedrock:Retrieve"]
resources = [
aws_bedrockagent_knowledge_base.this.arn
]
}
}
data "aws_iam_policy_document" "knowledgebase_trust" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["bedrock.amazonaws.com"]
type = "Service"
}
condition {
test = "StringEquals"
values = [data.aws_caller_identity.this.account_id]
variable = "aws:SourceAccount"
}
condition {
test = "ArnLike"
values = ["arn:aws:bedrock:${data.aws_region.this.name}:${data.aws_caller_identity.this.account_id}:knowledge-base/*"]
variable = "AWS:SourceArn"
}
}
}
data "aws_iam_policy_document" "knowledgebase_permissions" {
statement {
actions = ["bedrock:InvokeModel"]
resources = [
data.aws_bedrock_foundation_model.knowledgebase.model_arn,
]
}
statement {
actions = ["aoss:APIAccessAll"]
resources = [
aws_opensearchserverless_collection.this.arn
]
}
statement {
actions = ["s3:ListBucket"]
resources = [
var.s3_configuration.bucket_arn
]
condition {
test = "StringEquals"
values = [data.aws_caller_identity.this.account_id]
variable = "aws:ResourceAccount"
}
}
statement {
actions = ["s3:GetObject"]
resources = var.s3_configuration.inclusion_prefixes == null ? [
"${var.s3_configuration.bucket_arn}/*"
] : [for prefix in var.s3_configuration.inclusion_prefixes :
"${var.s3_configuration.bucket_arn}/${prefix}*"
]
condition {
test = "StringEquals"
values = [data.aws_caller_identity.this.account_id]
variable = "aws:ResourceAccount"
}
}
}