Skip to content

Commit

Permalink
Adding terraform statefile policy to infraci role (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuannie1 authored Sep 20, 2019
1 parent 3a2e69a commit 04f67e0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws-iam-role-infraci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Creates a role useful for running `terraform plan` in CI jobs.
| iam\_path | | string | `"/"` | no |
| role\_name | | string | `"infraci"` | no |
| source\_account\_id | | string | n/a | yes |
| terraform\_state\_lock\_dynamodb\_arn | "The unique identifier (ARN) of the state file DynamoDB table" | string | `""` | yes |

## Outputs

Expand Down
18 changes: 18 additions & 0 deletions aws-iam-role-infraci/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ data "aws_iam_policy_document" "secrets" {
values = ["true"]
}
}

dynamic statement {

for_each = compact([var.terraform_state_lock_dynamodb_arn])


content {
sid = "statefileaccess"

actions = [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:DeleteItem",
]

resources = [statement.value]
}
}
}

resource "aws_iam_policy" "secrets" {
Expand Down
6 changes: 6 additions & 0 deletions aws-iam-role-infraci/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ variable "role_name" {
variable "iam_path" {
default = "/"
}

variable "terraform_state_lock_dynamodb_arn" {
type = "string"
default = ""
description = "The ARN of the state file DynamoDB table"
}

0 comments on commit 04f67e0

Please sign in to comment.