1+ resource "aws_iam_policy" "bedrock_permissions" {
2+ name = " ${ var . role_name } -bedrock-policy"
3+
4+ policy = jsonencode ({
5+ Version = " 2012-10-17"
6+ Statement = [
7+ {
8+ Sid = " BedrockPermissions"
9+ Effect = " Allow"
10+ Action = [
11+ " bedrock:InvokeModel" ,
12+ " bedrock:InvokeModelWithResponseStream"
13+ ]
14+ Resource = " *"
15+ }
16+ ]
17+ })
18+ }
19+
20+ resource "aws_iam_policy" "ecr_permissions" {
21+ name = " ${ var . role_name } -ecr-policy"
22+
23+ policy = jsonencode ({
24+ Version = " 2012-10-17"
25+ Statement = [
26+ {
27+ Sid = " ECRImageAccess"
28+ Effect = " Allow"
29+ Action = [
30+ " ecr:BatchGetImage" ,
31+ " ecr:GetDownloadUrlForLayer" ,
32+ " ecr:GetAuthorizationToken"
33+ ]
34+ Resource = [
35+ " arn:aws:ecr:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :repository/*"
36+ ]
37+ },
38+ {
39+ Sid = " ECRTokenAccess"
40+ Effect = " Allow"
41+ Action = [
42+ " ecr:GetAuthorizationToken"
43+ ]
44+ Resource = " *"
45+ }
46+ ]
47+ })
48+ }
49+
50+ resource "aws_iam_policy" "logging_permissions" {
51+ name = " ${ var . role_name } -logging-policy"
52+
53+ policy = jsonencode ({
54+ Version = " 2012-10-17"
55+ Statement = [
56+ {
57+ Effect = " Allow"
58+ Action = [
59+ " logs:DescribeLogStreams" ,
60+ " logs:CreateLogGroup"
61+ ]
62+ Resource = [
63+ " arn:aws:logs:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :log-group:/aws/bedrock-agentcore/runtimes/*"
64+ ]
65+ },
66+ {
67+ Effect = " Allow"
68+ Action = [
69+ " logs:DescribeLogGroups"
70+ ]
71+ Resource = [
72+ " arn:aws:logs:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :log-group:*"
73+ ]
74+ },
75+ {
76+ Effect = " Allow"
77+ Action = [
78+ " logs:CreateLogStream" ,
79+ " logs:PutLogEvents"
80+ ]
81+ Resource = [
82+ " arn:aws:logs:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :log-group:/aws/bedrock-agentcore/runtimes/*:log-stream:*"
83+ ]
84+ }
85+ ]
86+ })
87+ }
88+
89+ resource "aws_iam_policy" "monitoring_permissions" {
90+ name = " ${ var . role_name } -monitoring-policy"
91+
92+ policy = jsonencode ({
93+ Version = " 2012-10-17"
94+ Statement = [
95+ {
96+ Effect = " Allow"
97+ Action = [
98+ " xray:PutTraceSegments" ,
99+ " xray:PutTelemetryRecords" ,
100+ " xray:GetSamplingRules" ,
101+ " xray:GetSamplingTargets"
102+ ]
103+ Resource = " *"
104+ },
105+ {
106+ Effect = " Allow"
107+ Resource = " *"
108+ Action = " cloudwatch:PutMetricData"
109+ Condition = {
110+ StringEquals = {
111+ " cloudwatch:namespace" = " bedrock-agentcore"
112+ }
113+ }
114+ }
115+ ]
116+ })
117+ }
118+
119+ resource "aws_iam_policy" "agentcore_permissions" {
120+ name = " ${ var . role_name } -agentcore-policy"
121+
122+ policy = jsonencode ({
123+ Version = " 2012-10-17"
124+ Statement = [
125+ {
126+ Sid = " GetAgentAccessToken"
127+ Effect = " Allow"
128+ Action = [
129+ " bedrock-agentcore:GetWorkloadAccessToken" ,
130+ " bedrock-agentcore:GetWorkloadAccessTokenForJWT" ,
131+ " bedrock-agentcore:GetWorkloadAccessTokenForUserId"
132+ ]
133+ Resource = [
134+ " arn:aws:bedrock-agentcore:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :workload-identity-directory/default" ,
135+ " arn:aws:bedrock-agentcore:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :workload-identity-directory/default/workload-identity/*"
136+ ]
137+ }
138+ ]
139+ })
140+ }
141+
142+ resource "aws_iam_policy" "config_permissions" {
143+ name = " ${ var . role_name } -config-policy"
144+
145+ policy = jsonencode ({
146+ Version = " 2012-10-17"
147+ Statement = [
148+ {
149+ Effect = " Allow"
150+ Action = [
151+ " ssm:GetParameter" ,
152+ " ssm:GetParameters"
153+ ]
154+ Resource = [
155+ " arn:aws:ssm:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :parameter/amazon/*" ,
156+ " arn:aws:ssm:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :parameter/cognito/*"
157+ ]
158+ },
159+ {
160+ Effect = " Allow"
161+ Action = [
162+ " secretsmanager:GetSecretValue"
163+ ]
164+ Resource = [
165+ " arn:aws:secretsmanager:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :secret:cognito_client_secret*" ,
166+ " arn:aws:secretsmanager:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :secret:zendesk_credentials*" ,
167+ " arn:aws:secretsmanager:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :secret:langfuse_credentials*" ,
168+ " arn:aws:secretsmanager:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :secret:gateway_credentials*" ,
169+ " arn:aws:secretsmanager:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :secret:tavily_key*"
170+ ]
171+ }
172+ ]
173+ })
174+ }
175+
176+ resource "aws_iam_policy" "bedrock_services_permissions" {
177+ name = " ${ var . role_name } -bedrock-services-policy"
178+
179+ policy = jsonencode ({
180+ Version = " 2012-10-17"
181+ Statement = [
182+ {
183+ Effect = " Allow"
184+ Action = [
185+ " bedrock:Retrieve" ,
186+ " bedrock:RetrieveAndGenerate"
187+ ]
188+ Resource = [
189+ " arn:aws:bedrock:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :knowledge-base/${ var . knowledge_base_id } "
190+ ]
191+ },
192+ {
193+ Effect = " Allow"
194+ Action = [
195+ " bedrock:ApplyGuardrail"
196+ ]
197+ Resource = [
198+ " arn:aws:bedrock:${ data . aws_region . current . name } :${ data . aws_caller_identity . current . account_id } :guardrail/${ var . guardrail_id } "
199+ ]
200+ },
201+ {
202+ Effect = " Allow"
203+ Action = [
204+ " bedrock:InvokeModel" ,
205+ " bedrock:InvokeModelWithResponseStream"
206+ ]
207+ Resource = [
208+ " arn:aws:bedrock:${ data . aws_region . current . name } ::foundation-model/*"
209+ ]
210+ }
211+ ]
212+ })
213+ }
0 commit comments