Terraform requires resources to be declared before referencing them in data sources to resolve dependencies correctly.
Final Answer:
The data source references the resource before it is declared -> Option C
Quick Check:
Reference order matters in Terraform [OK]
Hint: Declare resources before referencing them [OK]
Common Mistakes:
Using resource attributes as string literals
Ignoring declaration order
Assuming Terraform can't read AWS secrets
5. You want to securely pass a database password stored in Vault to an AWS RDS instance using Terraform. Which approach follows best practices?
hard
A. Use vault_generic_secret data source to fetch password, then pass it as password argument in aws_db_instance resource without storing it in Terraform state
B. Hardcode the password in Terraform variables and update Vault manually
C. Store the password in a local file and read it in Terraform
D. Create the RDS instance first, then manually update password in Vault
Solution
Step 1: Identify secure secret retrieval method
Using vault_generic_secret data source fetches the password securely at runtime without hardcoding.
Step 2: Pass secret directly to resource without storing in state
Passing the secret as an argument avoids exposing it in Terraform files or state, following best practices.
Final Answer:
Use vault_generic_secret data source to fetch password, then pass it as password argument in aws_db_instance resource without storing it in Terraform state -> Option A
Quick Check:
Fetch secrets dynamically and avoid hardcoding [OK]
Hint: Fetch secrets dynamically, never hardcode passwords [OK]