github.com/pulumi/terraform@v1.4.0/website/docs/language/index.mdx (about) 1 --- 2 page_title: Overview - Configuration Language 3 description: >- 4 Use the Terraform configuration language to describe the infrastructure that Terraform manages. 5 --- 6 7 # Terraform Language Documentation 8 9 This is the documentation for Terraform's configuration language. It is relevant 10 to users of [Terraform CLI](/cli), 11 [Terraform Cloud](https://cloud.hashicorp.com/products/terraform), and 12 [Terraform Enterprise](/enterprise). Terraform's language is 13 its primary user interface. Configuration files you write in Terraform 14 language tell Terraform what plugins to install, what infrastructure to create, 15 and what data to fetch. Terraform language also lets you define dependencies 16 between resources and create multiple similar resources from a single 17 configuration block. 18 19 > **Hands-on:** Try the [Write Terraform Configuration](https://learn.hashicorp.com/collections/terraform/configuration-language) tutorials. 20 21 ## About the Terraform Language 22 23 The main purpose of the Terraform language is declaring 24 [resources](/language/resources), which represent infrastructure objects. All other 25 language features exist only to make the definition of resources more flexible 26 and convenient. 27 28 A _Terraform configuration_ is a complete document in the Terraform language 29 that tells Terraform how to manage a given collection of infrastructure. A 30 configuration can consist of multiple files and directories. 31 32 The syntax of the Terraform language consists of only a few basic elements: 33 34 ```hcl 35 resource "aws_vpc" "main" { 36 cidr_block = var.base_cidr_block 37 } 38 39 <BLOCK TYPE> "<BLOCK LABEL>" "<BLOCK LABEL>" { 40 # Block body 41 <IDENTIFIER> = <EXPRESSION> # Argument 42 } 43 ``` 44 45 - _Blocks_ are containers for other content and usually represent the 46 configuration of some kind of object, like a resource. Blocks have a 47 _block type,_ can have zero or more _labels,_ and have a _body_ that contains 48 any number of arguments and nested blocks. Most of Terraform's features are 49 controlled by top-level blocks in a configuration file. 50 - _Arguments_ assign a value to a name. They appear within blocks. 51 - _Expressions_ represent a value, either literally or by referencing and 52 combining other values. They appear as values for arguments, or within other 53 expressions. 54 55 The Terraform language is declarative, describing an intended goal rather than 56 the steps to reach that goal. The ordering of blocks and the files they are 57 organized into are generally not significant; Terraform only considers implicit 58 and explicit relationships between resources when determining an order of 59 operations. 60 61 ### Example 62 63 The following example describes a simple network topology for Amazon Web 64 Services, just to give a sense of the overall structure and syntax of the 65 Terraform language. Similar configurations can be created for other virtual 66 network services, using resource types defined by other providers, and a 67 practical network configuration will often contain additional elements not 68 shown here. 69 70 ```hcl 71 terraform { 72 required_providers { 73 aws = { 74 source = "hashicorp/aws" 75 version = "~> 1.0.4" 76 } 77 } 78 } 79 80 variable "aws_region" {} 81 82 variable "base_cidr_block" { 83 description = "A /16 CIDR range definition, such as 10.1.0.0/16, that the VPC will use" 84 default = "10.1.0.0/16" 85 } 86 87 variable "availability_zones" { 88 description = "A list of availability zones in which to create subnets" 89 type = list(string) 90 } 91 92 provider "aws" { 93 region = var.aws_region 94 } 95 96 resource "aws_vpc" "main" { 97 # Referencing the base_cidr_block variable allows the network address 98 # to be changed without modifying the configuration. 99 cidr_block = var.base_cidr_block 100 } 101 102 resource "aws_subnet" "az" { 103 # Create one subnet for each given availability zone. 104 count = length(var.availability_zones) 105 106 # For each subnet, use one of the specified availability zones. 107 availability_zone = var.availability_zones[count.index] 108 109 # By referencing the aws_vpc.main object, Terraform knows that the subnet 110 # must be created only after the VPC is created. 111 vpc_id = aws_vpc.main.id 112 113 # Built-in functions and operators can be used for simple transformations of 114 # values, such as computing a subnet address. Here we create a /20 prefix for 115 # each subnet, using consecutive addresses for each availability zone, 116 # such as 10.1.16.0/20 . 117 cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 4, count.index+1) 118 } 119 ```