Resources and data sources
Resources and data sources play a critical role in Terraform and are probably the most important language constructs to understand as they allow you to access existing and create new resources.
Resources
Resources are the most common block that you use when coding in HCL. The resource
block is what Terraform is all about. You can think of each resource as a digital twin of something Terraform will provision in the real world:
resource "random_string" "foobar" { length = 4 upper = false special = false }
A block’s definition has three parts: the block type, the resource type, and the reference name. In the preceding example, the block type is resource
, the resource type is random_string
, and the reference name is foobar
. To create dependencies...