Skip to content

Latest commit

 

History

History
78 lines (46 loc) · 1.97 KB

04-using-variables-in-terraform.md

File metadata and controls

78 lines (46 loc) · 1.97 KB

Lab: Using Variables in Terraform

Help for the VSCode editor.

  1. How can we use environment variables to pass input variables in terraform scripts?

    Terraform looks for exported environment variables with names beginning TF_VAR_

    TF_VAR_<variable_name>

  2. Which method has the highest priority in Variable Definition Precedence?

    Refer to the documentation

    Command line flags -var or -var-file

  3. Which one of the following commands is a valid way to make use of a custom variable file with the terraform apply command?

    By convention, variables files have the extension .tfvars or .tfvars.json

    terraform apply -var-file variables.tfvars

  4. Information only

  5. What will happen if we run terraform plan command right now?
    terraform plan
    

    Inspect the output.

  6. Information only

  7. Declare the variable called filename with type string in the file variables.tf.
    Don't have to specify a default value.
    1. Add file variables.tf

    2. Insert variable definition

      Reveal
      variable "filename" {
          type = string
      }
      
  8. If we run terraform apply with a -var command line flag as shown below, which value would be considered by terraform?

    Don't run this now:

    terraform apply -var filename=/root/tennis.txt

    We are explicitly setting the value of the input variable created in Q7 to /root/tennis.txt

  9. Information only