From the course: HashiCorp Certified: Terraform Associate (003) Cert Prep by KodeKloud

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Resource targeting

Resource targeting

- [Instructor] In this lecture, we will learn how to use resource targeting with terraform plan or apply command. In the multiple providers lecture, we used an example with two resource blocks, one with the random_string resource and the other with an AWS instance type resource. In this example, you can see these two resource blocks with a slight modification. The AWS instance resource called web has a tag with a key called name that uses the ID that is generated by the random_string resource as a suffix. To do this, we have used what is known as an interpolation sequence, wrapping the resource attribute random_string.server-suffix.id inside dollar curly braces like this. Now, let's say that we want to change the length of the random_string resource from six to five. If we run terraform apply now, as expected, the random_string resource is recreated with a length of five. However, that is not all. Because the tag of the AWS instance resource depends on the random_string resource, it…

Contents