Terraform Input Variables using terraform.tfvars
Step-01: Introduction¶
- Provide Input Variables using
terraform.tfvarsfiles
Step-02: Assign Input Variables from terraform.tfvars¶
- Create a file named
terraform.tfvarsand define variables - If the file name is
terraform.tfvars, terraform will auto-load the variables present in this file by overriding thedefaultvalues inc2-variables.tf
Step-03: Execute Terraform Commands¶
# Initialize Terraform
terraform init
# Validate Terraform configuration files
terraform validate
# Format Terraform configuration files
terraform fmt
# Review the terraform plan
terraform plan
# Create Resources
terraform apply
# Verify Resources
1. Resource Group Name
2. Resource Group Location
3. Virtual Network Name
4. Virtual Network Subnet Name
5. Compare with names present in c2-variables.tf to reconfirm it has overrided it and took from terraform.tfvars
Step-04: Clean-Up Files¶
# Destroy Resources
terraform destroy -auto-approve
# Delete Files
rm -rf .terraform*
rm -rf terraform.tfstate*
References¶
🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99
$84.99
81% OFF
MARCH2026
Enroll Now on Udemy →
🎉 Offer