Loading...
Loading...
Learn HashiCorp Configuration Language — the foundation of Terraform
HashiCorp Configuration Language (HCL) is Terraform's declarative language. You describe WHAT you want (a virtual network, a database, a DNS record), and Terraform figures out HOW to create it.
resource "azurerm_resource_group" "main" {
name = "my-resources"
location = "East US"
}| Part | What it does |
|---|---|
| `resource` | Block type — declares a resource to create |
| `"azurerm_resource_group"` | Resource type — what kind of Azure resource |
| `"main"` | Local name — referenced elsewhere in your config |
| `name = "my-resources"` | Argument — a property of this resource |
| `location = "East US"` | Another argument — Azure region |
resource "azurerm_resource_group" "main" {
name = "my-resources"
location = "East US"
}
resource "azurerm_virtual_network" "main" {
name = "my-network"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
address_space = ["10.0.0.0/16"]
}Notice how the virtual network references the resource group: azurerm_resource_group.main.name — this is how Terraform creates dependencies.
| Wrong | Why | Right |
|---|---|---|
| `name = my-resources` (no quotes) | Strings must be quoted | `name = "my-resources"` |
| `Azurerm_Resource_Group` (wrong case) | Resource types are lowercase | `azurerm_resource_group` |
| Forgetting local name `resource "type" "name"` | Every resource needs a unique local name | `resource "type" "my_name"` |
Write a Terraform configuration that creates an Azure resource group named "my-app-rg" in "West Europe" location.
resource "azurerm_resource_group" "app" {
name = "my-app-rg"
location = "West Europe"
}