Skip to content

Commit 67557e8

Browse files
evanshoshanEvan Shoshanbryantbiggs
authored
feat: Allow for additional policy statements on sqs queue policy (#3543)
* feat: allow for additional policy statements on sqs queue policy * fix: Update variable type and run `pre-commit` * fix: Update variable name and description --------- Co-authored-by: Evan Shoshan <[email protected]> Co-authored-by: Bryant Biggs <[email protected]>
1 parent e4bc4d8 commit 67557e8

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.101.0
3+
rev: v1.103.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs

modules/karpenter/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ No modules.
142142
| <a name="input_iam_policy_description"></a> [iam\_policy\_description](#input\_iam\_policy\_description) | IAM policy description | `string` | `"Karpenter controller IAM policy"` | no |
143143
| <a name="input_iam_policy_name"></a> [iam\_policy\_name](#input\_iam\_policy\_name) | Name of the IAM policy | `string` | `"KarpenterController"` | no |
144144
| <a name="input_iam_policy_path"></a> [iam\_policy\_path](#input\_iam\_policy\_path) | Path of the IAM policy | `string` | `"/"` | no |
145-
| <a name="input_iam_policy_statements"></a> [iam\_policy\_statements](#input\_iam\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific IAM permissions as needed | <pre>list(object({<br/> sid = optional(string)<br/> actions = optional(list(string))<br/> not_actions = optional(list(string))<br/> effect = optional(string)<br/> resources = optional(list(string))<br/> not_resources = optional(list(string))<br/> principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> not_principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> condition = optional(list(object({<br/> test = string<br/> values = list(string)<br/> variable = string<br/> })))<br/> }))</pre> | `null` | no |
145+
| <a name="input_iam_policy_statements"></a> [iam\_policy\_statements](#input\_iam\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific IAM permissions as needed | <pre>list(object({ # TODO - change to `map(object({...}))` in next major version<br/> sid = optional(string)<br/> actions = optional(list(string))<br/> not_actions = optional(list(string))<br/> effect = optional(string)<br/> resources = optional(list(string))<br/> not_resources = optional(list(string))<br/> principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> not_principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> condition = optional(list(object({<br/> test = string<br/> values = list(string)<br/> variable = string<br/> })))<br/> }))</pre> | `null` | no |
146146
| <a name="input_iam_policy_use_name_prefix"></a> [iam\_policy\_use\_name\_prefix](#input\_iam\_policy\_use\_name\_prefix) | Determines whether the name of the IAM policy (`iam_policy_name`) is used as a prefix | `bool` | `true` | no |
147147
| <a name="input_iam_role_description"></a> [iam\_role\_description](#input\_iam\_role\_description) | IAM role description | `string` | `"Karpenter controller IAM role"` | no |
148148
| <a name="input_iam_role_max_session_duration"></a> [iam\_role\_max\_session\_duration](#input\_iam\_role\_max\_session\_duration) | Maximum API session duration in seconds between 3600 and 43200 | `number` | `null` | no |
@@ -169,6 +169,7 @@ No modules.
169169
| <a name="input_queue_kms_master_key_id"></a> [queue\_kms\_master\_key\_id](#input\_queue\_kms\_master\_key\_id) | The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK | `string` | `null` | no |
170170
| <a name="input_queue_managed_sse_enabled"></a> [queue\_managed\_sse\_enabled](#input\_queue\_managed\_sse\_enabled) | Boolean to enable server-side encryption (SSE) of message content with SQS-owned encryption keys | `bool` | `true` | no |
171171
| <a name="input_queue_name"></a> [queue\_name](#input\_queue\_name) | Name of the SQS queue | `string` | `null` | no |
172+
| <a name="input_queue_policy_statements"></a> [queue\_policy\_statements](#input\_queue\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific SQS queue policy permissions as needed | <pre>map(object({<br/> sid = optional(string)<br/> actions = optional(list(string))<br/> not_actions = optional(list(string))<br/> effect = optional(string)<br/> resources = optional(list(string))<br/> not_resources = optional(list(string))<br/> principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> not_principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> condition = optional(list(object({<br/> test = string<br/> values = list(string)<br/> variable = string<br/> })))<br/> }))</pre> | `null` | no |
172173
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
173174
| <a name="input_rule_name_prefix"></a> [rule\_name\_prefix](#input\_rule\_name\_prefix) | Prefix used for all event bridge rules | `string` | `"Karpenter"` | no |
174175
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | Service account to associate with the Karpenter Pod Identity | `string` | `"karpenter"` | no |

modules/karpenter/main.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ data "aws_iam_policy_document" "queue" {
145145
]
146146
}
147147
}
148+
148149
statement {
149150
sid = "DenyHTTP"
150151
effect = "Deny"
@@ -166,6 +167,47 @@ data "aws_iam_policy_document" "queue" {
166167
]
167168
}
168169
}
170+
171+
dynamic "statement" {
172+
for_each = var.queue_policy_statements != null ? var.queue_policy_statements : {}
173+
174+
content {
175+
sid = try(coalesce(statement.value.sid, statement.key))
176+
actions = statement.value.actions
177+
not_actions = statement.value.not_actions
178+
effect = statement.value.effect
179+
resources = statement.value.resources
180+
not_resources = statement.value.not_resources
181+
182+
dynamic "principals" {
183+
for_each = statement.value.principals != null ? statement.value.principals : []
184+
185+
content {
186+
type = principals.value.type
187+
identifiers = principals.value.identifiers
188+
}
189+
}
190+
191+
dynamic "not_principals" {
192+
for_each = statement.value.not_principals != null ? statement.value.not_principals : []
193+
194+
content {
195+
type = not_principals.value.type
196+
identifiers = not_principals.value.identifiers
197+
}
198+
}
199+
200+
dynamic "condition" {
201+
for_each = statement.value.condition != null ? statement.value.condition : []
202+
203+
content {
204+
test = condition.value.test
205+
values = condition.value.values
206+
variable = condition.value.variable
207+
}
208+
}
209+
}
210+
}
169211
}
170212

171213
resource "aws_sqs_queue_policy" "this" {

modules/karpenter/variables.tf

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ variable "iam_role_source_assume_policy_documents" {
112112

113113
variable "iam_policy_statements" {
114114
description = "A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific IAM permissions as needed"
115-
type = list(object({
115+
type = list(object({ # TODO - change to `map(object({...}))` in next major version
116116
sid = optional(string)
117117
actions = optional(list(string))
118118
not_actions = optional(list(string))
@@ -204,6 +204,32 @@ variable "queue_kms_data_key_reuse_period_seconds" {
204204
default = null
205205
}
206206

207+
variable "queue_policy_statements" {
208+
description = "A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific SQS queue policy permissions as needed"
209+
type = map(object({
210+
sid = optional(string)
211+
actions = optional(list(string))
212+
not_actions = optional(list(string))
213+
effect = optional(string)
214+
resources = optional(list(string))
215+
not_resources = optional(list(string))
216+
principals = optional(list(object({
217+
type = string
218+
identifiers = list(string)
219+
})))
220+
not_principals = optional(list(object({
221+
type = string
222+
identifiers = list(string)
223+
})))
224+
condition = optional(list(object({
225+
test = string
226+
values = list(string)
227+
variable = string
228+
})))
229+
}))
230+
default = null
231+
}
232+
207233
################################################################################
208234
# Node IAM Role
209235
################################################################################

0 commit comments

Comments
 (0)