title: Is it possible to reference the resource name inside the resource itself
body: <p>I'd like to use a resource name inside the resource itself to avoid string duplication and copy/paste errors.</p>
  <pre><code>resource &quot;aws_instance&quot; &quot;bastion-euw3-infra-01&quot; {
    ami           = &quot;ami-078db6d55a16afc82&quot;
    instance_type = &quot;t2.micro&quot;
    key_name      = &quot;sylvain&quot;
  
    user_data = templatefile(&quot;./scripts/cloudinit.yaml&quot;, {
      hostname          = &quot;bastion-euw3-infra-01&quot;
      tailscale_authkey = var.tailscale_authkey
    })
  
    network_interface {
      device_index         = 0
      network_interface_id = aws_network_interface.bastion-euw3-infra-01.id
    }
  
    tags = {
      Name        = &quot;bastion-euw3-infra-01&quot;
      Environment = &quot;infra&quot;
    }
  
    lifecycle {
      ignore_changes = [user_data]
    }
  }
  </code></pre>
  <p>Basically I'd like to replace <code>&quot;bastion-euw3-infra-01&quot;</code> inside the resource with some kind of var, e.g.:</p>
  <pre><code>resource &quot;aws_instance&quot; &quot;bastion-euw3-infra-01&quot; {
    ...
  
    user_data = templatefile(&quot;./scripts/cloudinit.yaml&quot;, {
      hostname          = ___name___
      tailscale_authkey = var.tailscale_authkey
    })
  
    ...
  
    tags = {
      Name        = ___name___
      Environment = &quot;infra&quot;
    }
  
    ...
  }
  </code></pre>
  <p>Does terraform provide a way to do this ?</p>