This shows you the differences between two versions of the page.
| programming:providingvaluesforvariables [2024/07/01 10:23] – created kamaradski | programming: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> | ||
| - | |||
| - | ===== Variable Definition Files ===== | ||
| - | |||
| - | Define variables in a .tfvars file or .tfvars.json file. | ||
| - | |||
| - | <code hcl> | ||
| - | // variables.tfvars | ||
| - | instance_type = " | ||
| - | availability_zones = [" | ||
| - | </ | ||
| - | |||
| - | <code hcl> | ||
| - | // variables.tfvars.json | ||
| - | { | ||
| - | " | ||
| - | " | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | Apply these with the -var-file flag: | ||
| - | |||
| - | <code hcl> | ||
| - | terraform apply -var-file=" | ||
| - | </ | ||
| - | |||
| - | ===== Environment Variables ===== | ||
| - | |||
| - | Prefix the variable name with TF_VAR_ and set it as an environment variable. | ||
| - | |||
| - | <code hcl> | ||
| - | export TF_VAR_instance_type=" | ||
| - | terraform apply | ||
| - | </ | ||