0
0
Terraformcloud~20 mins

Terraform's declarative approach - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Declarative Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform's Desired State

Terraform uses a declarative approach to manage infrastructure. What does Terraform primarily store and use to manage resources?

AThe desired state of infrastructure as code
BThe sequence of commands to create resources
CThe current live state of infrastructure only
DManual scripts to update resources
Attempts:
2 left
💡 Hint

Think about what Terraform compares before making changes.

service_behavior
intermediate
2:00remaining
Terraform Plan Behavior

What does the terraform plan command do in Terraform's declarative workflow?

ADeletes all existing resources
BShows the changes Terraform will make to reach the desired state
CImmediately applies changes to the infrastructure
DGenerates random resource names
Attempts:
2 left
💡 Hint

It previews changes without applying them.

Configuration
advanced
3:00remaining
Terraform Resource Dependency Declaration

Given the following Terraform configuration snippet, what is the correct way to declare that aws_instance.web depends on aws_security_group.web_sg?

resource "aws_security_group" "web_sg" {
  name = "web_sg"
}

resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  # Where to declare dependency?
}
AAdd <code>depends_on = ["aws_security_group.web_sg"]</code> inside <code>aws_instance.web</code>
BAdd <code>depends_on = [aws_instance.web]</code> inside <code>aws_security_group.web_sg</code>
CNo need to declare; Terraform infers dependencies automatically
DAdd <code>depends_on = [aws_security_group.web_sg]</code> inside <code>aws_instance.web</code>
Attempts:
2 left
💡 Hint

Explicit dependencies use depends_on with resource references.

Architecture
advanced
3:00remaining
Terraform State Management Best Practice

In a team environment, what is the best practice for managing Terraform state files to avoid conflicts and ensure consistency?

AStore state files locally on each developer's machine
BManually merge state files after each run
CUse remote state storage with locking, such as Terraform Cloud or S3 with DynamoDB locking
DDelete state files after each apply to avoid conflicts
Attempts:
2 left
💡 Hint

Think about shared access and preventing simultaneous changes.

security
expert
4:00remaining
Handling Sensitive Data in Terraform

Which approach best protects sensitive data such as passwords or API keys in Terraform configurations and state files?

AUse Terraform variables marked as <code>sensitive = true</code> and store secrets in a secure secrets manager referenced via data sources
BHardcode secrets directly in Terraform configuration files for easy access
CShare secrets via email among team members to keep them private
DStore secrets in plain text in the Terraform state file without encryption
Attempts:
2 left
💡 Hint

Consider both configuration and state file security.