-
Notifications
You must be signed in to change notification settings - Fork 5
/
iam.tf
91 lines (75 loc) · 2.14 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
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "lambda" {
statement {
sid = "AllowAutoScalingGroupDescribe"
effect = "Allow"
actions = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeInstanceRefreshes",
]
resources = ["*"]
}
statement {
sid = "AllowAutoScalingGroupInstanceRefresh"
effect = "Allow"
actions = ["autoscaling:StartInstanceRefresh"]
resources = [
data.aws_autoscaling_group.group.arn,
]
}
statement {
sid = "AllowLaunchTemplateDescribe"
effect = "Allow"
actions = ["ec2:DescribeLaunchTemplateVersions"]
resources = ["*"]
}
statement {
sid = "AllowLaunchTemplateCreateAndModify"
effect = "Allow"
actions = [
"ec2:CreateLaunchTemplateVersion",
"ec2:ModifyLaunchTemplate",
]
resources = var.launch_templates_arns
}
statement {
sid = "AllowWritingToCloudWatchLogs"
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/${aws_lambda_function.refresh.function_name}:*",
]
}
statement {
sid = "AllowSSMGetParameter"
effect = "Allow"
actions = ["ssm:GetParameter"]
resources = [
"arn:aws:ssm:${data.aws_region.current.name}:*:parameter${var.ami_ssm_parameter}",
"arn:aws:ssm:${data.aws_region.current.name}:*:parameter${var.ami_ssm_parameter_arm}",
]
}
}
resource "aws_iam_role" "lambda" {
name = var.lambda_role_name
assume_role_policy = data.aws_iam_policy_document.assume_role.json
description = var.lambda_role_description
}
resource "aws_iam_role_policy" "lambda" {
name_prefix = var.lambda_role_name
policy = data.aws_iam_policy_document.lambda.json
role = aws_iam_role.lambda.id
}