terraform

Can a terraform resource name have a dot in it?


Can I have a resource like

resource "foo" "bar.baz"{
  ...
}

or will the . mess me up later? In particular, will this be allowed:

resource "foo" "other"{
  ...
  depends_on = [ "foo.bar.baz" ]
}

I'm currently doing something like that but getting an invalid resource error and I'm unsure if its from that dot or not. I checked on this page, but its not clear from there if its valid to have a . in a resource name.


Solution

  • You should avoid using the . in resource identifiers, as . is used by Terraform to access attributes from resources.

    Attributes of other resources

    The syntax is TYPE.NAME.ATTRIBUTE. For example, ${aws_instance.web.id} will interpolate the ID attribute from the aws_instance resource named web. If the resource has a count attribute set, you can access individual attributes with a zero-based index, such as ${aws_instance.web.0.id}. You can also use the splat syntax to get a list of all the attributes: ${aws_instance.web.*.id}.