-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
129 lines (112 loc) · 3.06 KB
/
iam.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
data "aws_iam_policy_document" "assume_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"sagemaker.amazonaws.com",
"events.amazonaws.com",
]
}
}
}
data "aws_iam_policy_document" "default" {
statement {
actions = ["iam:PassRole"]
resources = ["arn:aws:iam::*:role/*"]
condition {
test = "StringLike"
variable = "iam:PassedToService"
values = ["sagemaker.amazonaws.com"]
}
}
statement {
actions = ["sagemaker:ListTags"]
resources = [
"arn:aws:sagemaker:*:*:user-profile/*",
"arn:aws:sagemaker:*:*:space/*",
"arn:aws:sagemaker:*:*:training-job/*",
"arn:aws:sagemaker:*:*:pipeline/*",
]
}
statement {
actions = ["sagemaker:AddTags"]
resources = [
"arn:aws:sagemaker:*:*:training-job/*",
"arn:aws:sagemaker:*:*:pipeline/*",
]
}
statement {
actions = [
"ec2:CreateNetworkInterface",
"ec2:CreateNetworkInterfacePermission",
"ec2:CreateVpcEndpoint",
"ec2:DeleteNetworkInterface",
"ec2:DeleteNetworkInterfacePermission",
"ec2:DescribeDhcpOptions",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeRouteTables",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcEndpoints",
"ec2:DescribeVpcs",
]
resources = ["*"]
}
statement {
actions = [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken",
]
resources = ["*"]
}
statement {
actions = [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:GetEncryptionConfiguration",
"s3:PutObject",
"s3:DeleteObject",
"s3:GetObject",
]
resources = ["*"]
}
statement {
actions = [
"sagemaker:DescribeDomain",
"sagemaker:DescribeUserProfile",
"sagemaker:DescribeSpace",
"sagemaker:DescribeStudioLifecycleConfig",
"sagemaker:DescribeImageVersion",
"sagemaker:DescribeAppImageConfig",
"sagemaker:CreateTrainingJob",
"sagemaker:DescribeTrainingJob",
"sagemaker:StopTrainingJob",
"sagemaker:Search",
"sagemaker:CreatePipeline",
"sagemaker:DescribePipeline",
"sagemaker:DeletePipeline",
"sagemaker:StartPipelineExecution",
]
resources = ["*"]
}
}
resource "aws_iam_role" "default" {
count = var.role_arn == null ? 1 : 0
name = "SageMakerExecutionRole-${var.name}"
assume_role_policy = data.aws_iam_policy_document.assume_policy.json
tags = var.tags
}
resource "aws_iam_role_policy" "default" {
count = var.role_arn == null ? 1 : 0
name = "SageMakerExecutionRole-${var.name}"
role = aws_iam_role.default[0].id
policy = data.aws_iam_policy_document.default.json
}
resource "aws_iam_role_policy_attachment" "default" {
count = var.role_arn == null ? 1 : 0
role = aws_iam_role.default[0].id
policy_arn = "arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"
}