Understanding the blocks of Terraform
Terraform is based on blocks, where each block has a specific function in defining infrastructure.
Some of the main blocks include:
resource: This block is used to declare a resource that will be created/managed by Terraform. A resource can be any object within the infrastructure that you want to manage, such as app service, resource groups, networks, etc.
data: This block is used to query existing data within the platform, such as information about an existing virtual machine, available images, etc. It allows you to bring external information into your Terraform code.
variable: This block is used to define variables, which can be used to parameterize your modules or configurations. Variables enable greater flexibility and code reusability.
output: This block is used to define values that will be displayed when the infrastructure is provisioned. It can be useful for obtaining specific information after Terraform execution.
provider: This block is used to configure credentials and specific settings for the cloud provider you are using (e.g., Azure, AWS, Google Cloud).
Example:
module: This block is used to encapsulate resources and configurations into a separate Terraform module. This is useful to promote modularity and reusability of the code, allowing you to organize and share specific parts of your infrastructure.