-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
68 lines (57 loc) · 1.36 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
data "aws_caller_identity" "current" {}
locals {
principal_arns = var.principal_arns != null ? var.principal_arns : [data.aws_caller_identity.current.arn]
}
resource "aws_iam_role" "iam_role" {
name = "${local.namespace}-tf-assume-role"
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"AWS": ${jsonencode(local.principal_arns)}
},
"Effect": "Allow"
}
]
}
EOF
tags = {
ResourceGroup = local.namespace
}
}
data "aws_iam_policy_document" "policy_doc" {
statement {
actions = [
"s3:ListBucket",
]
resources = [
aws_s3_bucket.s3_bucket.arn
]
}
statement {
actions = ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"]
resources = [
"${aws_s3_bucket.s3_bucket.arn}/*",
]
}
statement {
actions = [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:DeleteItem"
]
resources = [aws_dynamodb_table.dynamodb_table.arn]
}
}
resource "aws_iam_policy" "iam_policy" {
name = "${local.namespace}-tf-policy"
path = "/"
policy = data.aws_iam_policy_document.policy_doc.json
}
resource "aws_iam_role_policy_attachment" "policy_attach" {
role = aws_iam_role.iam_role.name
policy_arn = aws_iam_policy.iam_policy.arn
}