-
Notifications
You must be signed in to change notification settings - Fork 0
/
policies.tf
78 lines (66 loc) · 1.85 KB
/
policies.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
## Craft a IAM policy for all terraform roles
data "aws_iam_policy_document" "base" {
statement {
actions = [
"s3:ListBucket",
]
resources = [
format("arn:aws:s3:::%s-tfstate", local.tf_state_prefix),
format("arn:aws:s3:::%s-tfstate/*", local.tf_state_prefix),
]
}
statement {
actions = [
"s3:HeadObject",
"s3:GetObject",
"s3:ListBucket",
]
resources = [
format("arn:aws:s3:::%s-tfstate/%s%s.tfstate", local.tf_state_prefix, local.repo_name, local.tf_state_suffix),
]
}
}
## Craft a IAM policy for access to the DynamoDB table
data "aws_iam_policy_document" "dynamo" {
statement {
actions = [
"dynamodb:DeleteItem",
"dynamodb:DescribeTable",
"dynamodb:GetItem",
"dynamodb:PutItem",
]
resources = [
format("arn:aws:dynamodb:*:%s:table/%s-tflock", local.account_id, local.tf_state_prefix),
]
}
}
## Craft an IAM policy with the necessary permissions for terraform apply
data "aws_iam_policy_document" "tfstate_apply" {
source_policy_documents = [
data.aws_iam_policy_document.base.json,
data.aws_iam_policy_document.dynamo.json,
]
statement {
actions = [
"s3:DeleteObject",
"s3:ListBucket",
"s3:PutObject",
]
resources = [
format("arn:aws:s3:::%s-tfstate/%s%s.tfstate", local.tf_state_prefix, local.repo_name, local.tf_state_suffix)
]
}
}
## Craft an IAM policy with the necessary permissions for terraform plan
data "aws_iam_policy_document" "tfstate_plan" {
source_policy_documents = [
data.aws_iam_policy_document.base.json,
data.aws_iam_policy_document.dynamo.json,
]
}
## Craft an IAM policy with the necessary permissions for terraform remote state
data "aws_iam_policy_document" "tfstate_remote" {
source_policy_documents = [
data.aws_iam_policy_document.base.json,
]
}