Terraform Fundamentals
Master Terraform providers, configuration basics, and state management fundamentals.
Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp that enables users to define, provision, and manage cloud infrastructure using a declarative configuration language called HashiCorp Configuration Language (HCL). Core Concepts: **Infrastructure as Code (IaC)**: …
Concepts covered: Provider installation and configuration, Provider version constraints, The terraform init command and providers, Provider lock files (.terraform.lock.hcl), Provider plugins and the Terraform Registry, Provider authentication and configuration, Provider aliases for multiple configurations, Using multiple providers in a configuration, Provider configuration blocks, Cross-provider resource management, Understanding Terraform state, State file purpose and structure, State and infrastructure mapping
TA-004 - Terraform Fundamentals Example Questions
Test your knowledge of Terraform Fundamentals
Question 1
Scenario: You are a DevOps engineer at a SaaS company that manages 110 AWS resources using Terraform with state stored in an S3 backend. During a cost optimization project, your finance team requests that you consolidate three separate EC2 instances (aws_instance.app_server_1, aws_instance.app_server_2, aws_instance.app_server_3) into a single resource block using count or for_each. After refactoring the configuration to use 'aws_instance.app_server' with count = 3, running 'terraform plan' shows that Terraform wants to destroy all three existing instances and create three new ones. The instances are running production workloads and cannot experience downtime. You need to preserve the existing EC2 instances while updating the state to reflect the new configuration structure. What sequence of terraform state commands should you execute to remap the existing instance identifiers to the new indexed resource addresses?
Question 2
What is the primary function of the 'id' attribute stored for each resource in Terraform state?
Question 3
You are a cloud architect at a retail company that has been using Terraform for two years. Your organization recently implemented a disaster recovery strategy that requires maintaining Terraform state files in multiple geographic locations. During a DR drill, your team discovers that restoring from a backup state file causes Terraform to attempt recreating resources that already exist. A junior engineer suggests the issue might be related to how the state file tracks resource identity. Your manager asks you to explain which specific state file attribute is responsible for uniquely identifying each resource instance so Terraform can match state entries to actual cloud resources. Which state file attribute serves as the unique identifier that Terraform uses to correlate state entries with their corresponding real infrastructure objects?