Skip to content

Commit fa0bed2

Browse files
committed
fix: resolve tf race condition related to for each keys
1 parent c14524e commit fa0bed2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

main.tf

+9-5
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,17 @@ resource "aws_iam_role" "this" {
256256
}
257257

258258
resource "aws_iam_role_policy_attachment" "this" {
259-
for_each = toset(module.this.enabled ? [
260-
"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore",
261-
resource.aws_iam_policy.this[0].arn
262-
] : [])
259+
count = module.this.enabled ? 1 : 0
260+
261+
role = resource.aws_iam_role.this[0].name
262+
policy_arn = resource.aws_iam_policy.this[0].arn
263+
}
264+
265+
resource "aws_iam_role_policy_attachment" "ssm_managed_instance_core" {
266+
count = module.this.enabled ? 1 : 0
263267

264268
role = resource.aws_iam_role.this[0].name
265-
policy_arn = each.key
269+
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
266270
}
267271

268272
resource "aws_iam_policy" "this" {

0 commit comments

Comments
 (0)