0
0
Terraformcloud~10 mins

State file purpose and structure 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 specify the Terraform state file name.

Terraform
terraform {
  backend "local" {
    path = "[1]"
  }
}
Drag options to blanks, or click blank then click option'
Aterraform.tfstate
Bmain.tf
Cvariables.tf
Doutputs.tf
Attempts:
3 left
💡 Hint
Common Mistakes
Using configuration file names instead of the state file name.
Confusing the state file with Terraform code files.
2fill in blank
medium

Complete the code to initialize the Terraform backend for remote state storage.

Terraform
terraform {
  backend "s3" {
    bucket = "[1]"
    key    = "state/terraform.tfstate"
    region = "us-east-1"
  }
}
Drag options to blanks, or click blank then click option'
Aterraform.tfstate
Bmy-terraform-bucket
Cmain.tf
Dstatefile
Attempts:
3 left
💡 Hint
Common Mistakes
Using the state file name instead of the bucket name.
Using configuration file names as bucket names.
3fill in blank
hard

Fix the error in the Terraform state file reference.

Terraform
output "instance_ip" {
  value = aws_instance.example.[1]
}
Drag options to blanks, or click blank then click option'
Aprivate_ip
Bip_address
Cinstance_ip
Dpublic_ip
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like ip_address or instance_ip.
Confusing private and public IP attributes.
4fill in blank
hard

Fill both blanks to define a Terraform state file backend with encryption enabled.

Terraform
terraform {
  backend "s3" {
    bucket         = "[1]"
    encrypt        = [2]
    key            = "prod/terraform.tfstate"
    region         = "us-west-2"
  }
}
Drag options to blanks, or click blank then click option'
Aprod-terraform-state
Btrue
Cfalse
Ddev-terraform-state
Attempts:
3 left
💡 Hint
Common Mistakes
Setting encrypt to false when encryption is needed.
Using incorrect bucket names.
5fill in blank
hard

Fill all three blanks to configure a remote backend with encryption and locking enabled.

Terraform
terraform {
  backend "s3" {
    bucket         = "[1]"
    key            = "envs/prod/terraform.tfstate"
    region         = "us-east-2"
    dynamodb_table = "[2]"
    encrypt        = [3]
  }
}
Drag options to blanks, or click blank then click option'
Aprod-terraform-bucket
Bterraform-lock-table
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Not enabling encryption by setting it to false.
Using incorrect or missing DynamoDB table names.