TF-004 Understand Terraform basics • Complete Question Bank
Complete TF-004 Understand Terraform basics question bank — all 0 questions with answers and detailed explanations.
resource "aws_s3_bucket" "example" {}Output of `terraform state list`: aws_instance.web
Error: Could not satisfy version constraint for provider hashicorp/aws: required version >= 3.0, installed version 2.70
Refer to the exhibit. The engineer runs terraform plan and gets:
Error: Reference to undeclared data source on main.tf line 6, in resource "aws_security_group" "example": 6: vpc_id = data.aws_vpc.selected.id
A data source "aws_vpc" "selected" is declared but not yet read. What is the most likely cause?
data "aws_vpc" "selected" {
default = true
}
resource "aws_security_group" "example" {
name = "example-sg"
vpc_id = data.aws_vpc.selected.id
}
output "vpc_id" {
value = data.aws_vpc.selected.id
}Refer to the exhibit.
```hcl
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
}
}
resource "aws_eip" "ip" {
instance = aws_instance.web.id
}
```You are a platform engineer at a fintech company. Your team manages a multi-region application on AWS using Terraform. The infrastructure includes VPCs, subnets, EC2 instances, and an Application Load Balancer (ALB). The configuration uses modules from the Terraform Registry and remote state in S3 with DynamoDB locking.
Recently, after a colleague ran `terraform apply` in the us-east-1 region, the application experienced downtime because the ALB's target group was accidentally updated to point to instances in us-west-2 instead of us-east-1. The root cause was that the Terraform configuration for the ALB used a variable `target_region` which was hardcoded to us-west-2 in a `terraform.tfvars` file that was not intended for that workspace.
Your team wants to prevent such misconfigurations in the future. Which course of action would most effectively reduce the risk of using incorrect variable values across workspaces?
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
Maps real-world resources to configuration
Plugin to interact with a specific cloud or service API
Container for multiple resources used together
Defines where state snapshots are stored
Executes scripts on local or remote machine during creation/destruction
Drag a concept onto its matching description — or click a concept then click the description.
Copy files to the remote resource
Run a script on the machine running Terraform
Run a script on the remote resource
Configure resource using Chef
Configure resource using Puppet
Error: creating EC2 Instance: InvalidParameterValue: Value (ami-0c55b159cbfafe1f0) for parameter ami is invalid. Expected: 'ami-...'. on main.tf line 22, in resource "aws_instance" "web": 22: ami = "ami-0c55b159cbfafe1f0"
$ terraform init Initializing the backend... Successfully configured the backend "s3"! Terraform will automatically use this backend unless the backend configuration changes. Error refreshing state: state data in S3 does not have the expected content. This may be due to a bug. If you are sure the state file is valid, run: terraform force-unlock <lock_id>
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
}
}
resource "aws_eip" "web" {
instance = aws_instance.web.id
}terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}$ terraform plan
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_instance.web will be created
+ resource "aws_instance" "web" {
+ ami = "ami-0c55b159cbfafe1f0"
+ instance_type = "t2.micro"
+ tags = {
+ "Name" = "WebServer"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.resource "aws_lb" "frontend" {
name = "frontend-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = ["subnet-12345678", "subnet-87654321"]
}
resource "aws_lb_listener" "frontend_http" {
load_balancer_arn = aws_lb.frontend.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.frontend.arn
}
}
resource "aws_lb_target_group" "frontend" {
name = "frontend-tg"
port = 80
protocol = "HTTP"
vpc_id = "vpc-12345678"
}Refer to the exhibit. After running terraform apply, the output shows:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
instance_id = "i-1234567890abcdef0"
However, the engineer notices that the instance type is t2.micro, but the expected instance type was t2.medium. What is the most likely reason for this discrepancy?
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
output "instance_id" {
value = aws_instance.example.id
}terraform plan
Terraform will perform the following actions:
# aws_security_group.web_sg will be updated in-place
~ resource "aws_security_group" "web_sg" {
id = "sg-12345678"
~ ingress {
- cidr_blocks = ["0.0.0.0/0"]
+ cidr_blocks = ["10.0.0.0/8"]
}
}
Plan: 0 to add, 1 to change, 0 to destroy.Error: Error applying IAM policy to role MyRole: MalformedPolicyDocument: The policy is not in the valid JSON format.
status code: 400, request id: ...
on main.tf line 10, in resource "aws_iam_role_policy" "my_policy":
10: policy = <<POLICY
11: {
12: "Version": "2012-10-17",
13: "Statement": [
14: {
15: "Effect": "Allow",
16: "Action": "s3:ListBucket",
17: "Resource": "arn:aws:s3:::my-bucket"
18: }
19: ]
20: }
21: POLICYterraform state list aws_instance.web aws_instance.db aws_eip.web_ip aws_s3_bucket.logs