<p>I'm trying to create a tpl file. So i can give my role,  access to multiple k8s cluster. But i'm getting a tuple error.</p>
<p>How should we pass vars to tpl file when it has some interpolation?
Please also let me know what does this error mean and where i'm wrong.</p>
<p>Terraform version: 0.12.28</p>
<p>locals.tf</p>
<pre><code> federated = [
    &quot;xxxxxxxxxxxxxxxx&quot;,
    &quot;yyyyyyyyyyyyyyyy&quot;
  ]

federatedList1 = [for oidc in local.federated : &quot;arn:aws:iam::11111111111:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/${oidc}&quot;]
  federatedList2 = join(&quot;&quot;, [for oidc in local.federated : &quot;\&quot;oidc.eks.us-east-1.amazonaws.com/id/${oidc}:sub:\&quot;, \&quot;system:serviceaccount:%s:%s\&quot;&quot;])
</code></pre>
<p>eks_assume_policy.json.tpl</p>
<pre><code>{
  &quot;Version&quot;: &quot;2012-10-17&quot;,
  &quot;Statement&quot;: [
    {
      &quot;Effect&quot;: &quot;Allow&quot;,
      &quot;Principal&quot;: {
        &quot;Federated&quot;: &quot;${federatedList1}&quot;
      },
      &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,
      &quot;Condition&quot;: {
        &quot;StringEquals&quot;: {
          &quot;${federatedList2}&quot;
        }
      }
    }
  ]
}
</code></pre>
<p>IAM role</p>
<pre><code>resource &quot;aws_iam_role&quot; &quot;route53_role&quot; {
  name = &quot;xxxxx&quot;
  assume_role_policy = format(templatefile(&quot;./eks_assume_policy.json.tpl&quot;, {
    federatedList1 = [for oidc in local.federated : &quot;arn:aws:iam::1111111111:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/${oidc}&quot;]
    federatedList2 = join(&quot;&quot;, [for oidc in local.federated : &quot;\&quot;oidc.eks.us-east-1.amazonaws.com/id/${oidc}:sub:\&quot;, \&quot;system:serviceaccount:%s:%s\&quot;&quot;])
  }), &quot;namespace&quot;, local.name)

  tags = {
    terraform = &quot;true&quot;
    owner     = &quot;test&quot;
  }
}
</code></pre>
<p>Error: Error in function call</p>
<pre><code> on main.tf line 49, in resource &quot;aws_iam_role&quot; &quot;route_53_role&quot;:
  49:   assume_role_policy = format(templatefile(&quot;./eks_assume_policy.json.tpl&quot;, {
  50:
  51:
  52:
    |----------------
    | local.federated is tuple with 2 elements

Call to function &quot;templatefile&quot; failed: ./eks_assume_policy.json.tpl:7,25-39:
Invalid template interpolation value; Cannot include the given value in a
string template: string required..
</code></pre>
<p>Update1:</p>
<p>I'm trying eks_assume_policy.json.tpl to access both cluster</p>
<pre><code>{
  &quot;Version&quot;: &quot;2012-10-17&quot;,
  &quot;Statement&quot;: [
    {
      &quot;Effect&quot;: &quot;Allow&quot;,
      &quot;Principal&quot;: {
        &quot;Federated&quot;: [
          &quot;arn:aws:iam::111111111:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/xxxxxxxxxxxx&quot;,
          &quot;arn:aws:iam::111111111:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/yyyyyyyyyyy&quot;
        ]
      },
      &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,
      &quot;Condition&quot;: {
        &quot;StringEquals&quot;: {
          &quot;oidc.eks.us-east-1.amazonaws.com/id/xxxxxxxxxxxx:sub&quot;: &quot;system:serviceaccount:%s:%s&quot;,
          &quot;oidc.eks.us-east-1.amazonaws.com/id/yyyyyyyyy:sub&quot;: &quot;system:serviceaccount:%s:%s&quot;
        }
      }
    }
  ]
}
</code></pre>

user6826691
<p>Often, a pattern used to overcome this issue is through <a href="https://www.terraform.io/docs/configuration/functions/jsonencode.html" rel="nofollow noreferrer">jsonencode</a>. In this case the template file would be:</p>
<pre><code>{
  &quot;Version&quot;: &quot;2012-10-17&quot;,
  &quot;Statement&quot;: [
    {
      &quot;Effect&quot;: &quot;Allow&quot;,
      &quot;Principal&quot;: {
        &quot;Federated&quot;: ${jsonencode(federatedList1)}
      },
      &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,
      &quot;Condition&quot;: {
        &quot;StringEquals&quot;: 
          ${jsonencode(federatedList2)}
      }
    }
  ]
}
</code></pre>
<p>The <code>federatedList1</code> should be correct now.  I'm not sure what you are trying to achieve with <code>federatedList2</code>, thus the modifications to <code>federatedList2</code> may need more tinkering.</p>
