-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam_role.tf
38 lines (33 loc) · 905 Bytes
/
iam_role.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
# ポリシードキュメント
data "aws_iam_policy_document" "allow_describe_regions" {
statement {
effect = "Allow"
actions = ["ec2:DescribeRegions"] # リージョン一覧を取得する
resources = ["*"]
}
}
# IAMポリシー
resource "aws_iam_policy" "example" {
name = "example"
policy = data.aws_iam_policy_document.allow_describe_regions.json
}
# 信頼ポリシー
data "aws_iam_policy_document" "ec2_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
# IAMロール
resource "aws_iam_role" "example" {
name = "example"
assume_role_policy = data.aws_iam_policy_document.ec2_assume_role.json
}
# IAMポリシーのアタッチ
resource "aws_iam_role_policy_attachment" "example" {
role = aws_iam_role.example.name
policy_arn = aws_iam_policy.example.arn
}