Terraform Configuration
Write advanced Terraform configurations using resources, data sources, variables, outputs, and expressions.
Terraform Configuration refers to the set of files written in HashiCorp Configuration Language (HCL) or JSON that define the infrastructure resources you want to create, manage, and provision. These configuration files serve as the blueprint for your infrastructure and are the foundation of Infrast…
Concepts covered: Resource blocks and syntax, Data sources and data blocks, Resource vs data source differences, Resource attribute references, Cross-resource dependencies, Implicit and explicit dependencies, Input variables (variable blocks), Output values (output blocks), Variable definitions and defaults, Setting variable values, List and set types, Map and object types, Tuple types and type constraints, Type conversion and coercion, Terraform expressions and operators, Built-in functions, Conditional expressions, For expressions and iteration, Dynamic blocks, The depends_on meta-argument, Dependency graph and ordering, Preconditions and postconditions, Variable validation rules, Sensitive variables and outputs, Secrets management best practices, Vault integration for secrets
TA-004 - Terraform Configuration Example Questions
Test your knowledge of Terraform Configuration
Question 1
A global logistics company operates a Terraform-managed infrastructure spanning five AWS regions. The platform team uses Terraform Enterprise with Sentinel policies for governance. During a quarterly security assessment, the team discovered that their current workflow involves developers creating short-lived AWS IAM access keys through a self-service portal, then manually configuring these as workspace variables in Terraform Enterprise. The security team has flagged several issues: keys are valid for 24 hours but often not revoked after Terraform runs complete, multiple workspaces share the same credentials, and there's no centralized audit trail linking specific infrastructure changes to credential usage. The company's new security policy mandates that credentials must be scoped to individual Terraform runs, automatically expire after use, and provide complete auditability of which credentials modified which resources. The platform team needs to redesign their credential management approach while minimizing changes to existing Terraform configurations. Which architectural change most effectively addresses all three security policy mandates?
Question 2
You are a platform engineer at a government contractor developing a Terraform module for deploying Azure virtual machines. The module includes a variable called 'vm_sku' that accepts string values representing Azure VM sizes. Your security policy requires that VMs must have a minimum of 4 vCPUs, which corresponds to SKUs containing 'Standard_D4' or higher numeric suffixes (like Standard_D4s_v3, Standard_D8s_v5, etc.). During a compliance review, you discover that some deployments used 'Standard_D2s_v3' which violated the minimum compute requirements. A team member suggests using a regex pattern in the validation block to match SKUs with numeric values of 4 or greater. However, you realize that regex in Terraform's 'can(regex())' function cannot perform numeric comparisons on extracted values. You need to implement a practical validation approach. Which validation strategy best addresses this VM SKU validation requirement?
Question 3
A platform engineering team at a logistics company is building a Terraform module that provisions AWS Lambda functions for order processing. Each Lambda function requires access to different third-party API credentials stored in HashiCorp Vault. The team has configured the Vault provider using AppRole authentication, where the role_id is stored in the CI/CD pipeline variables and the secret_id is fetched from a secure parameter store at runtime. During a deployment, the team notices that some Lambda functions are being created with empty environment variables for the API credentials, while others receive the correct values. The Vault audit logs show successful secret retrievals for all requested paths. Investigation reveals that the issue occurs intermittently and seems correlated with parallel resource creation. What is the most likely cause of this behavior and how should the team address it?