Skip to content

Commit d10daf4

Browse files
committed
feat: Support for S3 lock file IAM permissions
1 parent a9dd4f2 commit d10daf4

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ See [the official document](https://www.terraform.io/docs/backends/types/s3.html
127127
| <a name="input_s3_logging_target_prefix"></a> [s3\_logging\_target\_prefix](#input\_s3\_logging\_target\_prefix) | The prefix to apply on bucket logs, e.g "logs/". | `string` | no |
128128
| <a name="input_state_bucket_prefix"></a> [state\_bucket\_prefix](#input\_state\_bucket\_prefix) | Creates a unique state bucket name beginning with the specified prefix. | `string` | no |
129129
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to resources. | `map(string)` | no |
130+
| <a name="input_terraform_iam_policy_add_lockfile_permissions"></a> [terraform\_iam\_policy\_add\_lockfile\_permissions](#input\_terraform\_iam\_policy\_add\_lockfile\_permissions) | Whether to add permissions for the S3 lockfile (recommended for Terraform 1.11+). | `bool` | no |
130131
| <a name="input_terraform_iam_policy_create"></a> [terraform\_iam\_policy\_create](#input\_terraform\_iam\_policy\_create) | Specifies whether to terraform IAM policy is created. | `bool` | no |
131132
| <a name="input_terraform_iam_policy_name"></a> [terraform\_iam\_policy\_name](#input\_terraform\_iam\_policy\_name) | If override\_terraform\_iam\_policy\_name is true, use this policy name instead of dynamic name with policy\_prefix | `string` | no |
132133
| <a name="input_terraform_iam_policy_name_prefix"></a> [terraform\_iam\_policy\_name\_prefix](#input\_terraform\_iam\_policy\_name\_prefix) | Creates a unique name beginning with the specified prefix. | `string` | no |

policy.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ data "aws_iam_policy_document" "terraform" {
1919
}
2020

2121
statement {
22-
actions = [
23-
"s3:GetObject",
24-
"s3:PutObject"
25-
]
22+
actions = concat(
23+
[
24+
"s3:GetObject",
25+
"s3:PutObject"
26+
],
27+
var.terraform_iam_policy_add_lockfile_permissions ? ["s3:DeleteObject"] : []
28+
)
2629
resources = ["${aws_s3_bucket.state.arn}/*"]
2730
}
2831

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ variable "terraform_iam_policy_name_prefix" {
2626
default = "terraform"
2727
}
2828

29+
variable "terraform_iam_policy_add_lockfile_permissions" {
30+
description = "Whether to add permissions for the S3 lockfile (recommended for Terraform 1.11+)."
31+
type = bool
32+
default = false
33+
}
34+
2935
#---------------------------------------------------------------------------------------------------
3036
# KMS Key for Encrypting S3 Buckets
3137
#---------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)