variables in terraform code example
Example 1: terraform define variable
variable "image_id" {
type = string
description = "The id of the machine image (AMI) to use for the server."
}
resource "some_resource" "resource_name" {
image = var.image_id
}
Example 2: terraform env variables
export TF_CLI_CONFIG_FILE="$HOME/.terraformrc-custom"
export TF_INPUT=0
export TF_LOG_PATH=./terraform.log
export TF_LOG=TRACE
TF_CLI_ARGS="-input=false" terraform apply -force is the equivalent to manually typing: terraform apply -input=false -force
TF_CLI_ARGS_plan="-refresh=false"
export TF_VAR_region=us-west-1
export TF_VAR_ami=ami-049d8641
export TF_VAR_alist='[1,2,3]'
export TF_VAR_amap='{ foo = "bar", baz = "qux" }'
export TF_IN_AUTOMATION
export TF_DATA_DIR
export TF_REGISTRY_DISCOVERY_RETRY
export TF_REGISTRY_CLIENT_TIMEOUT=15
export TF_IGNORE=trace
Example 3: how many ways you can create the varible in terraform
terraform apply -var-file="assign.tfvars"