<p><strong>CONTEXT:</strong> I am trying to setup fluent bit for logging activities in pods in a number of node groups included in a cluster. And so it requires that each node group have an IAM role assigned to it with all the required policies so, fluent bit's daemonset could record and save logs into log groups in cloud watch. <a href="https://github.com/gretelai/FluentBitLogging/blob/master/terraform/applications/main.tf" rel="nofollow noreferrer">Here's</a> the repo of the solution I am following.</p>
<p><strong>WHAT HAVE I TRIED:</strong></p>
<ol>
<li>create individual node group roles and attach policies by passing inputs into relevant variables of the modules. Like so:</li>
</ol>
<pre><code>module &quot;eks&quot; {
...
        eks_managed_node_groups = {
            one = {

              create_iam_role          = true
              iam_role_name            = &quot;fluent-bit-logger&quot;
              iam_role_use_name_prefix = true
              iam_role_description     = &quot;Fluent-bit-logging for node group 1&quot;
              iam_role_tags = {
                Name = &quot;fb-ng-2&quot;
              }
            two = {
               (same config, with obvious naming changes)
              }
           }
...
}
</code></pre>
<ol start="2">
<li><p>The above step worked but I am trying to setup fluent bit through terraform's helm resource and based on the solution I am following I am required to input only one IAM node role or that's what I make of it.</p>
</li>
<li><p>Use the <code>eks_managed_node_group_defaults</code> attribute to create and
assign <em>hopefully the same</em> IAM role to both the node groups and this is how I did it.</p>
</li>
</ol>
<pre><code>module &quot;eks&quot; {
  source  = &quot;terraform-aws-modules/eks/aws&quot;
  version = &quot;18.26.6&quot;

  cluster_name    = local.cluster_name
  cluster_version = &quot;1.21&quot;

  vpc_id     = module.vpc.vpc_id
  subnet_ids = module.vpc.private_subnets

  eks_managed_node_group_defaults = {
    ami_type = &quot;AL2_x86_64&quot;

    attach_cluster_primary_security_group = true

    # Disabling and using externally provided security groups
    create_security_group = false

    # fluent-bit (IAM-policy-role)
    create_iam_role          = true
    iam_role_name            = &quot;fluent-bit-logger&quot;
    iam_role_use_name_prefix = false
    iam_role_description     = &quot;Fluent-bit-logging - default for node groups&quot;
    iam_role_tags = {
      Name = &quot;fb-ng-default&quot;
      }

</code></pre>
<p><strong>WHAT I EXPECT TO GET</strong>
A message of successful eks cluster module execution (including the expected common node group role for the both node groups within.</p>
<p><strong>THE ERROR I GET</strong></p>
<pre><code>Error: failed creating IAM Role (fluent-bit-logger): EntityAlreadyExists: Role with name fluent-bit-logger already exists.
│   status code: 409, request id: fx11xxax-axex-4xxx-b749-09xx8x8xx17x
│ 
│   with module.eks-cluster.module.eks.module.eks_managed_node_group[&quot;two&quot;].aws_iam_role.this[0],
│   on .terraform/modules/eks-cluster.eks/modules/eks-managed-node-group/main.tf line 431, in resource &quot;aws_iam_role&quot; &quot;this&quot;:
│  431: resource &quot;aws_iam_role&quot; &quot;this&quot; {

</code></pre>

Vishak Arudhra
<p>The error message states that you are attempting to create the same role twice, which would cause the AWS API to error. This is consistent with your config given the argument value:</p>
<pre><code>create_iam_role = true
</code></pre>
<p>for two different EKS node groups. You would need to change the value to <code>false</code>, manage the role with e.g. <code>aws_iam_role.fluent_bit_logger</code>, and then (best practices) update accordingly:</p>
<pre><code>iam_role_name = aws_iam_role.fluent_bit_logger.name
</code></pre>
<p>Otherwise, you could manage the role within the EKS module declaration by using the config you shared in the first part of the question.</p>
