<p>Currently struggling writing a Terraform module to deploy a Helm chart, I was getting:</p>
<pre><code>│ Error: YAML parse error on external-dns/templates/serviceaccount.yaml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go struct field .metadata.annotations of type string
</code></pre>
<p>with a resource definition like this one:</p>
<pre><code>resource &quot;helm_release&quot; &quot;external_dns&quot; {
  name       = &quot;externaldns&quot;
  namespace  = var.external_dns_namespace
  repository = &quot;https://charts.bitnami.com/bitnami&quot;
  chart      = &quot;external-dns&quot;
  version    = &quot;5.3.0&quot;

  set {
    name  = &quot;serviceAccount.annotations.eks.amazonaws.com/role-arn&quot;
    value = resource.aws_iam_role.external_dns_role.arn
  }
}

</code></pre>
<p>When I found a public repository with a similar module: <a href="https://github.com/lablabs/terraform-aws-eks-external-dns/blob/master/main.tf" rel="nofollow noreferrer">https://github.com/lablabs/terraform-aws-eks-external-dns/blob/master/main.tf</a> and see that it has the last parameter defined as</p>
<pre><code>  set {
    name  = &quot;serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn&quot;
    value = aws_iam_role.external_dns[0].arn
  }
</code></pre>
<p>I tried adding those double slashes (\) and everything works! Now I would like to understand... why are these double slash required before the last two &quot;.&quot; but not in the other two?</p>
<p>I understand that, in Terraform, the double slash means literally a slash... but I cannot understand why would it be required there.</p>
<p>This is what I am trying to put into the Terraform module.
<a href="https://i.stack.imgur.com/07tQS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/07tQS.png" alt="enter image description here" /></a></p>
<p>Any help with an explanation for this issue will be appreciated :)</p>

spotHound
<p>in <code>name  = &quot;serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn&quot;</code> you want to define 3 groups, that are separated by dots:</p>
<p><code>serviceAccount</code> -&gt; <code>annotations</code> -&gt; <code>eks.amazonaws.com/role-arn</code></p>
<p>Since your third group happens to contain dots, you successfully found out that you must escape the dot characters in order to preserve proper structure.</p>
<p>Without escaping, the string would somehow mean</p>
<p><code>serviceAccount</code> -&gt; <code>annotations</code> -&gt; <code>eks</code> -&gt; <code>amazonaws</code>-&gt; <code>com/role-arn</code>, which makes no sense here</p>
