Skip to content

Commit 04f67e0

Browse files
authored
Adding terraform statefile policy to infraci role (#126)
1 parent 3a2e69a commit 04f67e0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

aws-iam-role-infraci/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Creates a role useful for running `terraform plan` in CI jobs.
1010
| iam\_path | | string | `"/"` | no |
1111
| role\_name | | string | `"infraci"` | no |
1212
| source\_account\_id | | string | n/a | yes |
13+
| terraform\_state\_lock\_dynamodb\_arn | "The unique identifier (ARN) of the state file DynamoDB table" | string | `""` | yes |
1314

1415
## Outputs
1516

aws-iam-role-infraci/main.tf

+18
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ data "aws_iam_policy_document" "secrets" {
6363
values = ["true"]
6464
}
6565
}
66+
67+
dynamic statement {
68+
69+
for_each = compact([var.terraform_state_lock_dynamodb_arn])
70+
71+
72+
content {
73+
sid = "statefileaccess"
74+
75+
actions = [
76+
"dynamodb:GetItem",
77+
"dynamodb:PutItem",
78+
"dynamodb:DeleteItem",
79+
]
80+
81+
resources = [statement.value]
82+
}
83+
}
6684
}
6785

6886
resource "aws_iam_policy" "secrets" {

aws-iam-role-infraci/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ variable "role_name" {
99
variable "iam_path" {
1010
default = "/"
1111
}
12+
13+
variable "terraform_state_lock_dynamodb_arn" {
14+
type = "string"
15+
default = ""
16+
description = "The ARN of the state file DynamoDB table"
17+
}

0 commit comments

Comments
 (0)