TF-004 · domain
Read, generate and modify configuration
This domain covers writing and reading Terraform configuration: output blocks, module input and output descriptions, how resource count changes appear in terraform plan, and passing values between configurations. Questions use HCL exhibits, Terraform Registry modules, and AWS EC2 resources, so you must read code and predict plan behavior accurately.
Focused practice
Practice Read, generate and modify configuration questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Read, generate and modify configuration
Be able to read HCL and explain outputs, module variables, and plan diffs, especially count changes. The key skill is predicting what terraform plan shows and knowing that cross-configuration values flow through outputs, remote state, or module inputs, never by guessing.
Purpose of output blocks in exposing values from a Terraform configuration
Where module input and output descriptions live in Terraform Registry modules
How terraform plan displays instance_count changes on an AWS EC2 resource
Recommended ways to pass outputs from one configuration as input variables
Watch out for
Common Read, generate and modify configuration exam traps
- ▸Confusing output values with variable declarations, or assuming outputs are required rather than optional configuration elements
- ▸Expecting instance_count increases to show as in-place updates instead of new resource instances being added
- ▸Passing outputs between configurations by hardcoding values instead of using remote state data sources or module outputs
Question index
All Read, generate and modify configuration questions (54)
Click any question to see the full explanation, or start a practice session above.
An operator wants to pass output values from one Terraform configuration to another as input variables. Which approach is recommended?
Medium2Refer to the exhibit. What is the purpose of this output block?
Easy3Which TWO statements about Terraform data sources are correct?
Easy4A Terraform configuration uses a for_each expression to create multiple subnets. After applying, one subnet's configuration needs to be modified. The engineer updates the resource block's map key for that subnet. What will terraform plan show?
Hard5You are managing a Terraform configuration for a multi-tier application that includes AWS EC2 instances, an RDS database, and an Application Load Balancer. The configuration uses multiple modules and remote state stored in an S3 bucket with DynamoDB locking. Recently, a colleague made changes to the configuration and applied them successfully. However, you now need to make additional changes and, when you run 'terraform plan', you receive an error: "Error: Error acquiring the state lock". The error message indicates that the lock is held by a different user. You have confirmed that your colleague is not currently running Terraform. What is the most appropriate course of action to proceed with your changes?
Hard6An organization has a policy that all AWS S3 buckets must have versioning enabled. They want to ensure that even if someone removes the `versioning` block from the configuration, the bucket still has versioning enabled after `terraform apply`. Which lifecycle configuration should they add to the `aws_s3_bucket` resource?
Hard7A configuration defines a variable `instance_type` with a default value `t2.micro`. After running `terraform apply`, the operator notices that the instances are being created with type `t2.small`. They check the configuration file and see the default is `t2.micro`. What is the most likely cause?
Medium8Which THREE variable declarations are valid in Terraform?
Hard9A developer is writing a Terraform configuration that uses a `variable` block to define an input variable `region` with a default value of `us-west-2`. The developer wants to ensure that the variable can only be set to one of three approved regions: `us-west-2`, `us-east-1`, or `eu-west-1`. Which approach should the developer use?
Easy10Refer to the exhibit. A developer runs 'terraform plan' and receives the following error: 'Error: InvalidAMIID.NotFound: The image id '[ami-0c55b159cbfafe1f0]' does not exist'. What is the most likely cause?
Easy11Which TWO scenarios require the use of the depends_on argument?
Medium12An engineer modifies a Terraform configuration by increasing the instance_count for an AWS EC2 resource from 2 to 5. After running terraform plan, which change will be displayed?
Easy13A team is writing Terraform configurations for a multi-region deployment. They want to use a module from the public Terraform Registry that provisions AWS VPCs. The module has been updated recently, but the team wants to ensure that all deployments use the same version of the module to avoid unexpected changes. Which configuration approach should they take to lock the module version?
Medium14Which TWO of the following commands can be used to read and inspect the current Terraform state? (Select TWO.)
Easy15A developer wants to conditionally create a resource based on a variable that is a boolean. Which syntax should they use?
Easy16Drag and drop the steps to handle sensitive data in Terraform outputs in the correct order.
Medium17A team wants to reuse a VPC module across multiple environments. They need to pass outputs from one module as inputs to another. Which configuration is correct?
Hard18A DevOps engineer wants to modify the Terraform configuration to control resource lifecycle behavior. Which TWO meta-arguments can be used to influence the order of creation and destruction?
Easy19A team wants to use Terraform to provision infrastructure across multiple cloud providers. Which configuration approach best supports this goal?
Easy20A junior engineer is asked to review a Terraform configuration that defines a module from the Terraform Registry. In which files are the descriptions of the module’s inputs and outputs typically found?
Easy21An operator wants to test an expression used in a Terraform configuration without running a plan or apply. Which command allows interactive evaluation of expressions?
Easy22Which command displays the output values defined in the configuration after apply?
Easy23Match each Terraform variable type to its example value.
Medium24A team is using Terraform to manage a multi-tier application on AWS. The configuration includes resources for VPC, subnets, security groups, and EC2 instances. Recently, a developer manually created an additional security group in the AWS console for testing, and now the team wants to manage it via Terraform. They have updated the configuration to include this security group with the same name and rules. When they run `terraform plan`, it shows that the security group will be created, but the existing one is not detected. They want to bring the existing security group under Terraform management without recreating it. The team is using a remote backend with state locking. What should they do?
Medium25You are a DevOps engineer at a company that manages infrastructure for multiple environments (dev, staging, prod) using Terraform. Each environment has its own state file stored in an S3 backend with DynamoDB locking. The team recently adopted a policy of running 'terraform plan' in CI/CD pipelines to review changes before applying. However, developers have reported that sometimes the plan output shows that Terraform wants to destroy and recreate resources that were not modified in their code changes. For example, a developer added a new tag to an S3 bucket in the staging environment, but the plan also showed that an unrelated EC2 instance would be replaced. Upon investigation, you notice that the state file for staging was last modified two days ago, but the developer's branch is based on a commit from one week ago. Which action is most likely to resolve the issue and ensure that plans only reflect changes from the current configuration changes?
Hard26A Terraform configuration uses a module from the Terraform Registry. After updating the module version in the configuration, the operator runs 'terraform plan' but does not see the changes expected from the new version. What is the most likely cause?
Hard27An operator modifies a Terraform configuration to change the `ami` attribute of an `aws_instance` resource. When they run `terraform plan`, they see that the resource will be destroyed and recreated. They want to avoid the recreation and instead update the instance in-place. What is the best approach?
Medium28Which command initializes a Terraform working directory by downloading providers and modules?
Easy29Refer to the exhibit. You need to add a security group to each instance. You have a local value defined as 'security_group_map = { "subnet-1" = "sg-1", "subnet-2" = "sg-2" }'. Which expression should be used to reference the security group ID in the resource block?
Hard30A configuration uses variables defined in a 'variables.tf' file. The operator wants to override these variables for a specific run without modifying the file. Which method should they use?
Easy31A developer has a module that outputs a list of subnet IDs. They want to use this list to create an EC2 instance in each subnet using for_each. Which for_each expression is correct?
Hard32A team is using a remote backend for Terraform state. After merging a pull request that modifies the configuration, the pipeline runs `terraform plan` and sees an unexpected diff for a resource that was not changed in the code. The state file is up-to-date with the infrastructure. What is the most likely cause?
Hard33A Terraform configuration includes a resource block with a 'lifecycle' block that has 'create_before_destroy = true'. During an apply, the create step succeeds but the destroy step fails. What is the resulting state?
Hard34Which three of the following are valid methods for reading, generating, or modifying Terraform configuration? (Choose three.)
Medium35Which TWO statements about Terraform configuration files are correct? (Choose two.)
Easy36A DevOps engineer needs to generate multiple similar AWS EC2 instances from a single resource block. They want each instance to have a unique name tag based on an index. Which approach should they use?
Medium37Which Terraform command is used to check the syntax and internal consistency of configuration files?
Easy38Which TWO of the following are best practices when writing Terraform configuration for a team? (Select TWO.)
Medium39A module requires an input variable named 'vpc_id'. How should the calling configuration pass the VPC ID from another module's output?
Hard40A Terraform plan shows that an AWS EC2 instance will be destroyed and recreated. The team wants to ensure zero downtime during the update. Which lifecycle attribute should be added?
Medium41A company manages a large Terraform configuration with an S3 backend and DynamoDB locking. After initial setup, they modify the backend block in the main.tf to change the S3 bucket name. Running 'terraform plan' yields: 'Backend reinitialization required. Please run "terraform init".' They run 'terraform init' but it prompts to migrate state from the old bucket to the new one. The old bucket is empty (no state files) because the configuration has never been applied. The team wants to avoid unnecessary state migration. Which step should they take?
Hard42In Terraform, which block is used to define a default value for a variable that can be overridden at runtime?
Easy43A developer needs to retrieve the current state of an AWS EC2 instance that was created by Terraform but the configuration file is missing. Which command will output the attributes of the instance in a format suitable for generating a configuration?
Medium44Which TWO statements about Terraform provisioners are correct?
Medium45Given the following Terraform configuration: resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" } If you change the instance_type to "t2.small" and run terraform apply, what will happen?
Hard46A team has two resources: an AWS security group and an EC2 instance that uses it. Terraform does not automatically detect the dependency. Which argument should be added to the instance resource?
Medium47A developer has a Terraform configuration that includes an output block. They run `terraform apply` and then want to quickly retrieve the output value without re-running the entire apply. Which command should they use?
Easy48When running terraform plan, the output indicates that a resource will be replaced (destroy then create) due to a change in the 'name' attribute. However, the engineer only changed a tag. What is the most likely cause?
Hard49Which four of the following are valid techniques for reading, generating, or modifying Terraform configuration? (Choose all that apply. There are four correct answers.)
Medium50After running `terraform plan`, a developer sees the following line in the output: `Plan: 1 to add, 0 to change, 0 to destroy.` What does this indicate?
Easy51Which TWO statements about Terraform's handling of input variables are true?
Medium52A team has an existing S3 bucket created outside Terraform. They want to manage it with Terraform by importing its state. Which of the following is the correct sequence of commands to read the bucket's configuration and avoid drift?
Hard53A team uses remote state stored in an S3 bucket with DynamoDB locking. A developer wants to read the current state outputs locally without making changes. Which command should they use?
Medium54A team uses Terraform to manage multiple environments (dev, staging, prod) with a shared networking module. The module defines a variable 'cidr_block' with no default. In the root module, they have a file dev.tfvars containing 'cidr_block = "10.0.0.0/16"'. When running 'terraform plan' while in the dev workspace, they receive: 'Error: No value for required variable cidr_block'. They have already run 'terraform init' and confirmed the workspace is 'dev'. What is the most likely cause and correct action?
MediumOther domains
All TF-004 exam domains
Frequently asked questions
- What does the Read, generate and modify configuration domain cover on the TF-004 exam?
- Be able to read HCL and explain outputs, module variables, and plan diffs, especially count changes. The key skill is predicting what terraform plan shows and knowing that cross-configuration values flow through outputs, remote state, or module inputs, never by guessing.
- How many questions are in this domain?
- This page lists all 54 Read, generate and modify configuration questions in the TF-004 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Read, generate and modify configuration questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.