Gotchas
In this section, you will see some recommendations that are typically not covered in the Terraform documentation. These are not very obvious unless you go through them in your setup, hence the name “Gotchas.” This section is followed by general tips.
Avoid Lists Where Possible
- When you are dealing with use cases that warrant using lists, try using maps or sets wherever possible.
- When you use a list, Terraform uses the index position to map it to the resource that gets created. Using the index position may be fine for use cases where you do not see many deletions of values in the list, but it should not be used for use cases where you expect the values to be deleted and added to the list in random order. This may sound confusing or may not make sense in the first read. Try reading this again after going through the following example.
- Say, for example, you are creating IAM users using the
list
type. The following code can be used to create users...