0
0
Terraformcloud~10 mins

Environment variables (TF_VAR_) in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to reference the environment variable for the Terraform variable 'region'.

Terraform
variable "region" {
  type = string
  default = "us-west-1"
}

provider "aws" {
  region = var.[1]
}
Drag options to blanks, or click blank then click option'
AAWS_REGION
Bregion
CTF_VAR_region
Denv_region
Attempts:
3 left
💡 Hint
Common Mistakes
Using the environment variable name directly in the code.
Confusing environment variable names with Terraform variable names.
2fill in blank
medium

Complete the command to set the environment variable for Terraform variable 'instance_type' in Linux shell.

Terraform
export [1]="t2.micro"
Drag options to blanks, or click blank then click option'
Ainstance_type
Bterraform_instance_type
CAWS_INSTANCE_TYPE
DTF_VAR_instance_type
Attempts:
3 left
💡 Hint
Common Mistakes
Setting environment variable without the TF_VAR_ prefix.
Using unrelated environment variable names.
3fill in blank
hard

Fix the error in the Terraform variable declaration to use a default value from environment variable 'TF_VAR_bucket_name'.

Terraform
variable "bucket_name" {
  type = string
  default = [1]
}
Drag options to blanks, or click blank then click option'
A"my-default-bucket"
Bvar.TF_VAR_bucket_name
Cnull
Denv("TF_VAR_bucket_name")
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call environment functions inside variable defaults.
Using variable names with TF_VAR_ prefix inside Terraform code.
4fill in blank
hard

Fill both blanks to correctly use a variable 'ami_id' set via environment variable and reference it in resource.

Terraform
variable "ami_id" {
  type = string
}

resource "aws_instance" "example" {
  ami           = var.[1]
  instance_type = "t2.micro"
  tags = {
    Name = "ExampleInstance"
  }
  lifecycle {
    ignore_changes = ["[2]"]
  }
}
Drag options to blanks, or click blank then click option'
Aami_id
Bami
Ctags
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in references.
Not quoting attribute names in ignore_changes.
5fill in blank
hard

Fill all three blanks to create a Terraform variable 'env' with default from environment variable, use it in provider, and output it.

Terraform
variable "env" {
  type    = string
  default = "[1]"
}

provider "aws" {
  region = var.[2]
}

output "environment" {
  value = var.[3]
}
Drag options to blanks, or click blank then click option'
Adev
Benv
Dregion
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing variable names with environment variable names.
Using region instead of env in provider or output.