Skip to content

Commit 3036720

Browse files
asri-badlahmatteomallus
authored andcommitted
fix: Canonicalize OpenSearch IAM policy using sort
1 parent 8d48f7f commit 3036720

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ data "aws_iam_policy_document" "default" {
241241

242242
actions = distinct(compact(var.iam_actions))
243243

244-
resources = [
245-
join("", aws_opensearch_domain.default.*.arn),
246-
"${join("", aws_opensearch_domain.default.*.arn)}/*"
247-
]
244+
resources = sort(flatten([
245+
aws_opensearch_domain.default.*.arn,
246+
[for arn in aws_opensearch_domain.default.*.arn : "${arn}/*"]
247+
]))
248248

249249
principals {
250250
type = "AWS"
251-
identifiers = distinct(compact(concat(var.iam_role_arns, aws_iam_role.elasticsearch_user.*.arn)))
251+
identifiers = sort(distinct(compact(concat(var.iam_role_arns, aws_iam_role.elasticsearch_user.*.arn))))
252252
}
253253
}
254254

@@ -261,11 +261,11 @@ data "aws_iam_policy_document" "default" {
261261
effect = "Allow"
262262

263263
actions = distinct(compact(var.iam_actions))
264-
265-
resources = [
266-
join("", aws_opensearch_domain.default.*.arn),
267-
"${join("", aws_opensearch_domain.default.*.arn)}/*"
268-
]
264+
265+
resources = sort(flatten([
266+
aws_opensearch_domain.default.*.arn,
267+
[for arn in aws_opensearch_domain.default.*.arn : "${arn}/*"]
268+
]))
269269

270270
principals {
271271
type = "AWS"
@@ -314,4 +314,4 @@ module "kibana_hostname" {
314314
records = [join("", aws_opensearch_domain.default.*.endpoint)]
315315

316316
context = module.this.context
317-
}
317+
}

0 commit comments

Comments
 (0)