Advanced Terraform test (Advanced)
40 questions · 40 minutes · Free
State surgery, testing, policy and large-scale IaC.
Take the Advanced Terraform test
What it covers
- State import and moves
- Drift and refactoring
- Testing and policy as code
- Multi-environment layouts
- Custom providers
Interview format
- Questions: 40 questions — 24 multiple choice, 16 multi-answer
- Time: 40 minutes, timed from the first question
- Difficulty: Advanced
- Skill area: DevOps & cloud
- Price: Free
Earn a certificate
The Advanced Terraform test is one of the 8 tests of the DevOps Engineer: Advanced learning path. Pass it and the other 7 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Advanced Terraform test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
In a realistic project scenario, how should you implement state versioning to ensure consistent and auditable state management across environments?
- Rely on the default local backend and assume state versioning is handled automatically.
- Use a single state file and manually track versions using comments in the file.
- Store multiple state files locally and use a custom script to track changes.
- Use Terraform workspaces with a remote backend and enable state versioning in the backend configuration.
Answer: D. Use Terraform workspaces with a remote backend and enable state versioning in the backend configuration.
Terraform workspaces allow you to manage multiple versions of state files for different environments (e.g., dev, staging, prod). When combined with a remote backend (like Terraform Cloud or AWS S3 with locking), state versioning is enabled by default, ensuring that changes are tracked and rolled back if needed. This is a realistic scenario for applying state versioning in a project.
Which of the following is a correct requirement for provider documentation standards when finding and fixing a bug related to it?
- The provider documentation must include a complete list of all resource attributes, their types, and validation rules.
- The provider documentation should focus only on the most commonly used resources and ignore less-used ones.
- The provider documentation is not required to specify validation rules for attributes.
- The provider documentation should be written in natural language without any code examples.
Answer: A. The provider documentation must include a complete list of all resource attributes, their types, and validation rules.
Provider documentation standards require that all resource attributes, their types, and validation rules be clearly defined. This ensures that users can understand and use the provider correctly. Other options may be related to documentation but are not specific to the standards required for provider documentation.
Which of the following is the correct command to move resources between states in Terraform?
- terraform state replace
- terraform state mv
- terraform state shift
- terraform state migrate
Answer: B. terraform state mv
The correct command to move resources between states in Terraform is 'terraform state mv'. This command allows you to update the state file to reflect changes in your infrastructure, such as renaming or reorganizing resources. The other options are not valid commands for state move operations.
When comparing policy as code with infrastructure as code (IaC), which statement accurately describes the appropriate use case for policy as code with custom validation rules?
- Infrastructure as code is the better choice for enforcing compliance rules across environments and resources.
- Policy as code allows for centralized enforcement of compliance rules across environments and resources, whereas infrastructure as code (IaC) primarily focuses on declarative provisioning of infrastructure. Policy as code is preferred when enforcing organizational governance, regulatory compliance, or security standards consistently across different environments.
- Policy as code is less flexible than infrastructure as code and cannot be used for defining infrastructure configurations.
- Policy as code is used exclusively for defining infrastructure resources and does not support custom validation rules.
Answer: B. Policy as code allows for centralized enforcement of compliance rules across environments and resources, whereas infrastructure as code (IaC) primarily focuses on declarative provisioning of infrastructure. Policy as code is preferred when enforcing organizational governance, regulatory compliance, or security standards consistently across different environments.
Policy as code is specifically designed to enforce compliance and governance rules, making it suitable for scenarios where adherence to organizational policies is critical. Infrastructure as code (IaC) is focused on defining and provisioning infrastructure resources, not on enforcing policy or compliance. Therefore, policy as code is the correct choice when centralized compliance and governance are required.
In a multi-environment Terraform project, how should you apply backend configuration overrides for different environments while keeping the main configuration file unchanged?
- Use environment variables to override backend settings during initialization.
- Modify the main Terraform configuration file to include environment-specific backend settings directly.
- Use a backend configuration file with -backend-config to pass environment-specific settings without modifying the main configuration.
- Create a separate Terraform configuration for each environment with its own backend configuration.
Answer: C. Use a backend configuration file with -backend-config to pass environment-specific settings without modifying the main configuration.
In a multi-environment setup, using -backend-config allows you to pass environment-specific settings to the backend without modifying the main Terraform configuration. This ensures that the same configuration can be used across different environments with only minor adjustments for backend settings, keeping the codebase clean and maintainable. Other options are incorrect because they either involve modifying the main configuration (which is not ideal for multi-environment setups) or suggest methods that do not align with best practices for backend configuration in Terraform.
Frequently asked questions
- How many questions are in the Advanced Terraform test?
- 40 questions (24 multiple choice, 16 multi-answer), with 40 minutes to answer them.
- What does the Advanced Terraform test cover?
- State import and moves, Drift and refactoring, Testing and policy as code, Multi-environment layouts, Custom providers.
- Is the Advanced Terraform test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Advanced Terraform test?
- Advanced, in DevOps & cloud.