In terraform we usually have more than one modules and modules that depend on another module to fully enable infrastructure. In this way one resource is dependent on another resources.
for example let’s update the example to
resource “aws_eip” “ip” {
instance = “${aws_instance.example.id}”
}
This should look familiar from the earlier example of adding an EC2 instance resource, except this time we’re building an “aws_eip” resource type. This resource type allocates and associates anelastic IP to an EC2 instance.
The only parameter for aws_eip is “instance” which is the EC2 instance to assign the IP to. For this value, we use an interpolation to use an attribute from the EC2 instance we managed earlier.
The syntax for this interpolation should be straightforward: it requests the “id” attribute from the “aws_instance.example” resource.