attach a policy to an EKS cluster node group role

Viewed 17

I'd like to attach a policy created via the aws_iam_policy to a node group NodeInstanceRole, so far the only thing I've come across which would allow me to do this (if I understand this correctly) is the following code:

resource "aws_iam_role_policy_attachment" "additional" {
  for_each = {
    for node_group, group_details in module.eks.eks_managed_node_groups : node_group => group_details
    # We have to add if condition as the module output contains all node names,
    # even if they are not created.
    if group_details.iam_role_name != ""
  }

  policy_arn = aws_iam_policy.s3_write_policy.arn
  role       = each.value.iam_role_name
}

This is from https://github.com/terraform-aws-modules/terraform-aws-eks/issues/2053, is this the way to go ?, or is there a better way for me to add my policy to my EKS cluster's node group role ?

I know how to attach a policy to a role, that is not the issue here, my issue is with getting to the name of the role.

0 Answers
Related