What is YAML to Terraform Variable Generator?
This tool converts YAML configuration into Terraform HCL variable definitions. It generates two outputs: variables.tf containing typed variable blocks with descriptions and defaults, and terraform.tfvars containing simple key = value assignments. The tool automatically infers HCL types from YAML values — strings become string, numbers become number, booleans become bool, arrays become list(type), and objects become object({...}).
How to Use
- Paste your YAML configuration into the input area.
- Optionally enable descriptions and set a variable prefix.
- Click 'Convert' to generate Terraform variable definitions.
- Switch between variables.tf and terraform.tfvars tabs to view each output.
- Copy each output to the corresponding file in your Terraform project.
Why Use This Tool?
Tips & Best Practices
- Use the variable prefix to avoid naming conflicts in shared Terraform modules
- The type inference uses the first element of arrays to determine list type
- Complex nested objects become HCL object types with nested attribute definitions
- Null values in YAML are mapped to the 'any' type in Terraform
- Review generated descriptions and customize them for your specific use case
Frequently Asked Questions
What is Terraform HCL?
HCL (HashiCorp Configuration Language) is the configuration language used by Terraform to define infrastructure as code. Variables are declared in variables.tf files with type, description, and default values, while actual values are assigned in terraform.tfvars files.
How are YAML types mapped to HCL?
YAML strings map to HCL string type, numbers map to number type, booleans map to bool type, arrays map to list(type) where the element type is inferred, objects map to object({...}) with nested type definitions, and null values map to the any type.
Can I use this for terraform.tfvars?
Yes. The tool generates both variables.tf (with variable blocks including type, description, and default) and terraform.tfvars (with simple key = value assignments). Switch between tabs to view and copy each output.
What about complex types?
The tool handles nested objects, arrays of objects, and mixed-type structures. Nested objects become HCL object types with nested attribute definitions. Arrays become list types with element types inferred from the first element.
Is my data sent to a server?
No, all conversion happens entirely in your browser. Your YAML configuration and Terraform code never leave your device. No data is collected, stored, or transmitted.
Real-world Examples
Infrastructure Configuration
Convert a YAML infrastructure config to Terraform variables with proper types.
resource_group: myapp-prod location: eastus replicas: 3 enabled: true
variable "resource_group" {
type = string
description = "resource_group configuration value"
default = "myapp-prod"
}
variable "location" {
type = string
description = "Cloud region or location"
default = "eastus"
}
variable "replicas" {
type = number
description = "Number of instances or replicas"
default = 3
}
variable "enabled" {
type = bool
description = "Enable or disable "
default = true
}terraform.tfvars Output
The same config generates simple key = value assignments for terraform.tfvars.
resource_group: myapp-prod location: eastus replicas: 3
resource_group = "myapp-prod" location = "eastus" replicas = 3