-
Notifications
You must be signed in to change notification settings - Fork 1
/
iam.tf
47 lines (41 loc) · 1.59 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
# ---------------------------------------------
# インスタンスプロフィール
# ---------------------------------------------
resource "aws_iam_instance_profile" "app_ec2_profile" {
name = aws_iam_role.app_iam_role.name
role = aws_iam_role.app_iam_role.name
}
# ---------------------------------------------
# IAM role
# ---------------------------------------------
resource "aws_iam_role" "app_iam_role" {
name = "${var.project}-${var.environment}-app-iam-role"
assume_role_policy = data.aws_iam_policy_document.ec2_assume_role.json
}
# ---------------------------------------------
# 信頼ポリシー
# ---------------------------------------------
data "aws_iam_policy_document" "ec2_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
# ---------------------------------------------
# ロールポリシーアタッチ
# ---------------------------------------------
resource "aws_iam_role_policy_attachment" "app_iam_role_ec2_readonly" {
role = aws_iam_role.app_iam_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "app_iam_role_ssm_managed" {
role = aws_iam_role.app_iam_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
resource "aws_iam_role_policy_attachment" "app_iam_role_ssm_readonly" {
role = aws_iam_role.app_iam_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess"
}