Configuration Basics Quiz
Quiz
Question 1 of 25
(0 answered)
Question 1
What is the correct basic syntax structure for an HCL block?
โ
Correct!
HCL uses double quotes around block labels. The correct syntax is
<BLOCK_TYPE> "<BLOCK_LABEL>" "<BLOCK_LABEL>" { ... }โ
Incorrect
HCL uses double quotes around block labels. The correct syntax is
<BLOCK_TYPE> "<BLOCK_LABEL>" "<BLOCK_LABEL>" { ... }Think about how resource blocks are defined in Terraform.
Question 2
What operator is used for pessimistic version constraints in Terraform?
โ
Correct!
The
~> operator allows incremental updates to the rightmost specified version component. For example, ~> 1.2.0 allows 1.2.x but not 1.3.0.โ
Incorrect
The
~> operator allows incremental updates to the rightmost specified version component. For example, ~> 1.2.0 allows 1.2.x but not 1.3.0.It’s a two-character operator combining a tilde and greater-than symbol.
Question 3
Complete the terraform block to require version 1.2.0 or later:
Fill in the missing configuration
terraform {
_____ = ">= 1.2.0"
}โ
Correct!
The
required_version argument in the terraform block specifies which versions of Terraform can be used with this configuration.โ
Incorrect
The
required_version argument in the terraform block specifies which versions of Terraform can be used with this configuration.Question 4
Backend configuration in Terraform supports variables and expressions for dynamic configuration.
โ
Correct!
Backend configuration does NOT support variables or expressions because the backend is processed before Terraform loads variables. Use
-backend-config flag or a separate config file instead.โ
Incorrect
Backend configuration does NOT support variables or expressions because the backend is processed before Terraform loads variables. Use
-backend-config flag or a separate config file instead.Think about when the backend needs to be initialized in the Terraform workflow.
Question 5
Which of the following are valid components of the
terraform block?โ
Correct!
terraform block contains: required_version, required_providers, backend, and cloud. The provider is a separate top-level block type, not part of the terraform block.โ
Incorrect
terraform block contains: required_version, required_providers, backend, and cloud. The provider is a separate top-level block type, not part of the terraform block.The provider configuration uses its own block type.
Question 6
What does the version constraint
~> 1.2.0 allow?โ
Correct!
The
~> operator with three version components (1.2.0) allows only patch version updates within that minor version. So ~> 1.2.0 allows 1.2.0, 1.2.1, 1.2.9 but blocks 1.3.0.โ
Incorrect
The
~> operator with three version components (1.2.0) allows only patch version updates within that minor version. So ~> 1.2.0 allows 1.2.0, 1.2.1, 1.2.9 but blocks 1.3.0.More specific version constraints create tighter restrictions.
Question 7
Complete the provider alias configuration for a disaster recovery region:
Fill in the missing keyword
provider "aws" {
_____ = "west"
region = "us-west-2"
}โ
Correct!
The
alias argument creates an alternative provider configuration that can be referenced in resources using provider = aws.west.โ
Incorrect
The
alias argument creates an alternative provider configuration that can be referenced in resources using provider = aws.west.Question 8
How do you reference an aliased provider in a resource?
โ
Correct!
Use
provider = aws.west without quotes. The format is provider_type.alias_name.โ
Incorrect
Use
provider = aws.west without quotes. The format is provider_type.alias_name.It’s a reference, not a string literal.
Question 9
Which attributes are typically computed (not provided by you) for an
aws_instance resource?โ
Correct!
Computed attributes are generated by AWS after the instance is created:
id, public_ip, arn, etc. Input attributes like ami and instance_type are provided by you.โ
Incorrect
Computed attributes are generated by AWS after the instance is created:
id, public_ip, arn, etc. Input attributes like ami and instance_type are provided by you.Computed attributes are values only known after the resource is created.
Question 10
Arrange the resource dependency chain in the correct creation order:
Drag to arrange from first to last
โฎโฎ
aws_vpc
โฎโฎ
aws_subnet
โฎโฎ
aws_instance
โ
Correct!
VPC must be created first, then subnet (which depends on VPC), then instance (which depends on subnet). Destruction happens in reverse order.
โ
Incorrect
VPC must be created first, then subnet (which depends on VPC), then instance (which depends on subnet). Destruction happens in reverse order.
Question 11
When using references like
aws_vpc.main.id, Terraform automatically creates implicit dependencies.โ
Correct!
Terraform automatically detects dependencies when you reference one resource’s attributes in another resource. This creates an implicit dependency graph.
โ
Incorrect
Terraform automatically detects dependencies when you reference one resource’s attributes in another resource. This creates an implicit dependency graph.
Terraform analyzes your configuration to understand resource relationships.
Question 12
What is the resource address for a resource defined as
resource "aws_instance" "web_server"?โ
Correct!
Resource addresses combine the resource type and name with a dot:
resource_type.resource_name.โ
Incorrect
Resource addresses combine the resource type and name with a dot:
resource_type.resource_name.Combine the two quoted strings with a dot separator.
Question 13
In a standard Terraform project structure, where should provider configurations be placed?
โ
Correct!
Provider configurations should be in
providers.tf following standard conventions. This separates concerns and improves organization.โ
Incorrect
Provider configurations should be in
providers.tf following standard conventions. This separates concerns and improves organization.The file name typically matches what it contains.
Question 14
What is the difference between a Map and an Object in Terraform?
What is the difference between a Map and an Object in Terraform?
Map: Flexible keys, all values must be the same type. Used for tags, labels, dynamic data.
Object: Fixed keys (schema), values can be different types. Used for structured configuration.
Example:
- Map:
map(string)- all values are strings - Object:
object({ name = string, count = number })- mixed types
Did you get it right?
โ
Correct!
โ
Incorrect
Question 15
Given this configuration, which region will
aws_instance.app be created in?provider "aws" {
region = "us-east-1"
}
provider "aws" {
alias = "west"
region = "us-west-2"
}
resource "aws_instance" "app" {
ami = "ami-123"
instance_type = "t2.micro"
}What will this code output?
โ
Correct!
The resource uses the default provider (without alias), which is
us-east-1. To use the aliased provider, you’d need to add provider = aws.west to the resource.โ
Incorrect
The resource uses the default provider (without alias), which is
us-east-1. To use the aliased provider, you’d need to add provider = aws.west to the resource.Resources without explicit provider argument use the default provider.
Question 16
Which of the following are correct workarounds for the limitation that backends cannot use variables?
โ
Correct!
Valid workarounds: (1)
-backend-config flag, (2) separate config file, (3) partial configuration. Environment variables and string interpolation are NOT supported in backend blocks.โ
Incorrect
Valid workarounds: (1)
-backend-config flag, (2) separate config file, (3) partial configuration. Environment variables and string interpolation are NOT supported in backend blocks.The backend configuration must be static, but can be provided externally.
Question 17
What does
terraform fmt do?โ
Correct!
terraform fmt automatically formats Terraform configuration files to a canonical style and format, making code consistent and readable.โ
Incorrect
terraform fmt automatically formats Terraform configuration files to a canonical style and format, making code consistent and readable.Think about code formatting and style consistency.
Question 18
Nested blocks inside resources use the equals sign (
=) just like arguments.โ
Correct!
Nested blocks do NOT use
=. For example: ingress { ... } not ingress = { ... }. Arguments use =, nested blocks don’t.โ
Incorrect
Nested blocks do NOT use
=. For example: ingress { ... } not ingress = { ... }. Arguments use =, nested blocks don’t.Look at how security group ingress rules are defined.
Question 19
Complete the required_providers block for AWS provider version 5.x:
Fill in the version constraint
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "_____"
}
}
}โ
Correct!
The
~> 5.0 constraint allows any 5.x version but blocks 6.0 and above. This is the standard way to lock to a major version.โ
Incorrect
The
~> 5.0 constraint allows any 5.x version but blocks 6.0 and above. This is the standard way to lock to a major version.Question 20
In which order does Terraform destroy resources with dependencies?
โ
Correct!
Terraform destroys resources in reverse dependency order. If Instance depends on Subnet, and Subnet depends on VPC, destruction is: Instance โ Subnet โ VPC.
โ
Incorrect
Terraform destroys resources in reverse dependency order. If Instance depends on Subnet, and Subnet depends on VPC, destruction is: Instance โ Subnet โ VPC.
You need to delete dependent resources before their dependencies.
Question 21
Which statements about HCL comments are true?
โ
Correct!
HCL supports
# and // for single-line comments, /* */ for multi-line comments, and inline comments. Comment nesting is not supported.โ
Incorrect
HCL supports
# and // for single-line comments, /* */ for multi-line comments, and inline comments. Comment nesting is not supported.HCL comment syntax is similar to many other languages.
Question 22
Why are provider aliases necessary?
Why are provider aliases necessary?
Provider aliases enable multiple configurations of the same provider type.
Common use cases:
- Multi-region deployments (deploy to multiple AWS regions)
- Multi-account setups (manage resources across different accounts)
- Disaster recovery (replicate infrastructure in backup regions)
- Cross-region dependencies (e.g., CloudFront + S3 in different regions)
Without aliases, you could only have one configuration per provider type.
Did you get it right?
โ
Correct!
โ
Incorrect
Question 23
What will happen when you run
terraform apply with this configuration?terraform {
backend "s3" {
bucket = var.state_bucket
key = "terraform.tfstate"
region = "us-east-1"
}
}
variable "state_bucket" {
default = "my-state-bucket"
}What will this code output?
โ
Correct!
Backend configuration does NOT support variables. This will produce an error. Use
-backend-config flag or a separate config file instead.โ
Incorrect
Backend configuration does NOT support variables. This will produce an error. Use
-backend-config flag or a separate config file instead.Think about when the backend is initialized versus when variables are loaded.
Question 24
What is the purpose of the
.terraform.lock.hcl file?โ
Correct!
The
.terraform.lock.hcl file records the exact provider versions and checksums used, ensuring consistent provider versions across team members and CI/CD runs.โ
Incorrect
The
.terraform.lock.hcl file records the exact provider versions and checksums used, ensuring consistent provider versions across team members and CI/CD runs.It’s created after
terraform init and relates to providers.Question 25
You can have multiple default providers (without alias) of the same type in a Terraform configuration.
โ
Correct!
You can only have ONE default provider (without alias) per provider type. Additional configurations of the same provider type must use aliases.
โ
Incorrect
You can only have ONE default provider (without alias) per provider type. Additional configurations of the same provider type must use aliases.
Think about how Terraform decides which provider to use by default.
Quiz Results
Score
0/0
Accuracy
0%
Right
0
Wrong
Skipped
0
Last updated on