-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIAM.tf
More file actions
55 lines (49 loc) · 1.48 KB
/
IAM.tf
File metadata and controls
55 lines (49 loc) · 1.48 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
# ----------------------------------
# IAM Role for Lambda Function
# ----------------------------------
# Assume Role - For Lambda
data "aws_iam_policy_document" "lambda_assume_role" {
statement {
effect = "Allow"
actions = [
"sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"lambda.amazonaws.com"]
}
}
}
# Inline policy for sagemaker stop start for lambda
data "aws_iam_policy_document" "auto_shutdown_iam_inline" {
statement {
actions = [
"sagemaker:ListTags",
"sagemaker:StopNotebookInstance",
"sagemaker:DescribeNotebookInstance",
"sagemaker:AddTags"
]
resources = [
"arn:aws:sagemaker:${var.aws_region}:${data.aws_caller_identity.current.account_id}:notebook-instance/*",
]
}
statement {
actions = [
"sagemaker:ListNotebookInstances",
]
resources = [
"*",
]
}
}
# Role for Lambda and both assume and inline integrated
resource "aws_iam_role" "lambda_iam_role_terraform" {
name = "Lambda-IAM-Role-For-SageMaker-Auto-ShutDown"
path = "/lambda/"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
description = "IAM role for lambda to stop that SageMaker instance which we used tags AutoStop"
inline_policy {
name = "SageMaker-Auto-ShutDown-Inline-Policy"
policy = data.aws_iam_policy_document.auto_shutdown_iam_inline.json
}
}