-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiam.tf
More file actions
130 lines (118 loc) · 2.99 KB
/
Copy pathiam.tf
File metadata and controls
130 lines (118 loc) · 2.99 KB
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
resource "aws_iam_role" "interview_host" {
name = "${var.name_prefix}-host-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
})
}
resource "aws_iam_role_policy_attachment" "ssm_core" {
role = aws_iam_role.interview_host.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
resource "aws_iam_role_policy" "s3_models_read" {
name = "${var.name_prefix}-s3-models-read"
role = aws_iam_role.interview_host.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = [
"s3:ListBucket",
"s3:GetObject"
]
Resource = [
aws_s3_bucket.models.arn,
"${aws_s3_bucket.models.arn}/*",
]
}]
})
}
resource "aws_iam_role_policy" "ecr_pull" {
name = "${var.name_prefix}-ecr-pull"
role = aws_iam_role.interview_host.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ecr:GetAuthorizationToken"
]
Resource = "*"
},
{
Effect = "Allow"
Action = [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
]
Resource = aws_ecr_repository.ollama.arn
}
]
})
}
resource "aws_iam_instance_profile" "interview_host" {
name = "${var.name_prefix}-host-profile"
role = aws_iam_role.interview_host.name
}
resource "aws_iam_role" "interview_candidate" {
name = "${var.name_prefix}-candidate-role"
max_session_duration = 7200
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
AWS = data.aws_caller_identity.current.account_id
}
}]
})
}
resource "aws_iam_role_policy" "candidate_ssm_access" {
name = "${var.name_prefix}-ssm-access"
role = aws_iam_role.interview_candidate.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "AllowSSMStartSession"
Effect = "Allow"
Action = [
"ssm:StartSession"
]
Resource = [
"arn:aws:ec2:${var.region}:${data.aws_caller_identity.current.account_id}:instance/${aws_instance.interview_host.id}",
aws_ssm_document.interview_session.arn
]
},
{
Sid = "AllowSSMSessionCommands"
Effect = "Allow"
Action = [
"ssm:TerminateSession",
"ssm:ResumeSession",
"ssm:DescribeSessions",
"ssm:GetConnectionStatus"
]
Resource = "*"
},
{
Sid = "AllowDescribeInstance"
Effect = "Allow"
Action = [
"ec2:DescribeInstances",
"ec2:DescribeInstanceStatus"
]
Resource = "*"
}
]
})
}