Using a resouce/module local name as variable inside it self

Is is possible to do something like example bellow, but the input “name” be the resource local name instead of a fixed value

resource “aws_instance” “web” {
ami = “ami-a1b2c3d4”
instance_type = “t2.micro”
name = “web”
}

where “name = “web”” is something like:

“aws_instance.web.self”,
“aws_instance.web.local_name”
“self.local_name”

etc etc…

Ty!

Hi @edgdelgado,

If you want to set the remote system’s name to the same string as you are using to track the resource in Terraform then what you’ve written here is the correct way to do that.

In practice this is typically not desirable because of a difference in scope: resource names in Terraform need to be unique only within a particular Terraform module, whereas resource names in the remote system often need to include more context because different modules or instances of the same module might all be contributing objects into the same AWS account and region.

If you want these two names to match in your particular case then there’s no reason you can’t set it that way, but there is no way to do that other than to explicitly set it as you’ve shown in your example.