0
0
Terraformcloud~20 mins

Terraform validate for syntax check - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What does terraform validate check in a Terraform configuration?

Choose the correct description of what terraform validate does when run in a Terraform project directory.

AIt checks the syntax and internal consistency of Terraform files without contacting any cloud provider.
BIt applies the configuration and creates resources in the cloud to verify correctness.
CIt only checks if the cloud provider credentials are valid and can be used.
DIt runs a full plan and shows the changes that will be applied.
Attempts:
2 left
💡 Hint

Think about whether terraform validate needs to connect to the cloud or create resources.

🧠 Conceptual
intermediate
2:00remaining
Which error will terraform validate detect?

Given the following Terraform snippet, what error will terraform validate report?

resource "aws_instance" "example" {
  ami = "ami-123456"
  instance_type = "t2.micro"
  invalid_attribute = "value"
}
ANo error; configuration is valid.
BError: Missing required provider configuration for AWS.
CError: Invalid AMI ID format.
DError: Unsupported argument 'invalid_attribute' for resource 'aws_instance'.
Attempts:
2 left
💡 Hint

Check if all attributes used are supported by the resource type.

Configuration
advanced
2:00remaining
What is the output of terraform validate for this configuration?

Consider this Terraform configuration snippet:

variable "region" {
  type = string
}

provider "aws" {
  region = var.region
}

Run terraform validate without setting any variable values. What will happen?

AValidation passes but warns about missing variable values.
BValidation passes because variables can be unset during validation.
CValidation fails with a syntax error in the provider block.
DValidation fails with an error about missing required variable 'region'.
Attempts:
2 left
💡 Hint

Think about whether terraform validate requires variable values to be set.

security
advanced
2:00remaining
Which terraform validate limitation affects security checks?

Which security-related issue terraform validate cannot detect?

AExposed secrets in variable default values.
BSyntax errors in Terraform files.
CMisconfigured resource attributes that violate security policies.
DMissing required provider blocks.
Attempts:
2 left
💡 Hint

Consider what terraform validate checks and what it does not.

Architecture
expert
2:00remaining
Why might terraform validate succeed but terraform plan fail?

Choose the best explanation for why terraform validate can pass but terraform plan fails with an error.

A<code>terraform validate</code> only checks syntax and does not verify cloud provider connectivity or resource existence, which <code>terraform plan</code> requires.
B<code>terraform validate</code> runs a full plan internally but ignores errors.
C<code>terraform plan</code> uses a different configuration file than <code>terraform validate</code>.
D<code>terraform validate</code> requires credentials but <code>terraform plan</code> does not.
Attempts:
2 left
💡 Hint

Think about the difference between syntax checking and planning.