User Tools

Site Tools


programming:providingvaluesforvariables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

programming:providingvaluesforvariables [2024/07/01 10:23] – created kamaradskiprogramming:providingvaluesforvariables [2024/07/01 10:32] (current) – removed kamaradski
Line 1: Line 1:
-====== Providing Values for Variables ====== 
- 
-Values for variables can be provided in several ways: 
- 
-===== Command-line Flags ===== 
-Use the -var option with terraform apply or terraform plan. 
- 
-<code hcl>terraform apply -var="instance_type=t2.large"</code> 
- 
-===== Variable Definition Files ===== 
- 
-Define variables in a .tfvars file or .tfvars.json file.  
- 
-<code hcl> 
-// variables.tfvars 
-instance_type = "t2.large" 
-availability_zones = ["us-west-2a", "us-west-2b"] 
-</ocde> 
- 
-<code hcl> 
-// variables.tfvars.json 
-{ 
-  "instance_type": "t2.large", 
-  "availability_zones": ["us-west-2a", "us-west-2b"] 
-} 
-</code> 
- 
-Apply these with the -var-file flag: 
- 
-<code hcl> 
-terraform apply -var-file="variables.tfvars" 
-</code> 
- 
-===== Environment Variables ===== 
- 
-Prefix the variable name with TF_VAR_ and set it as an environment variable. 
- 
-<code hcl> 
-export TF_VAR_instance_type="t2.large" 
-terraform apply 
-</code> 
  
programming/providingvaluesforvariables.1719829399.txt.gz · Last modified: 2024/07/01 10:23 by kamaradski