Skip to main content
Terraform configurations use the HashiCorp Configuration Language (HCL), a block-oriented syntax designed to be both human-readable and machine-friendly. Understanding HCL’s block structure is key to writing clear, maintainable, and reusable infrastructure-as-code. Why block-oriented HCL matters
  • Clear structure: Each block type has an explicit responsibility, which improves readability and simplifies reviews.
  • Flexibility and modularity: Use only the block types required for a given task — combine them as needed to model your infrastructure.
  • Reusable patterns: Well-defined blocks make modules and shared patterns easier to maintain and scale across teams.
Quick overview — common block types
  • provider: Connects Terraform to a target platform (AWS, Azure, GCP, etc.). Acts as the adapter to the platform’s API.
  • resource: Declares the resources Terraform will create and manage (VMs, networks, storage).
  • data: Reads information about existing resources or remote data sources without creating them.
  • variable: Parameterizes values so configurations are reusable across environments.
  • output: Exposes values from a run for use by users, CI/CD systems, or other modules.
  • terraform: Configures Terraform-specific settings, e.g., backends and required providers.
  • module: Groups related resources into reusable units by referencing other directories or remote modules.
  • import (conceptual): Not an HCL block — terraform import CLI brings existing resources into state management.
Summary table of block types, uses, and short examples Practical examples provider block
resource block
data block
variable and output
module and terraform
Additional tips
  • Order is flexible: HCL does not require a strict order for blocks, but grouping related blocks improves readability.
  • Keep modules focused: Design modules to do one thing well (networking, compute, storage) and expose a small set of variables and outputs.
  • Use terraform fmt and terraform validate as part of CI to enforce style and catch errors early.
An infographic titled "Terraform Block Types" showing labeled boxes for blocks like provider, resource, data, variable, output, terraform, module, and import. Each box gives a one-line description of that block's purpose in Terraform configurations.
Note that while the infographic includes “import” for conceptual completeness, Terraform does not provide an HCL “import” block. To bring existing resources into Terraform’s state, use the terraform import CLI command.
With that foundation, we’ll now examine the provider block. Further reading and references

Watch Video