Terraform Doesn't Know the Hand-Made DB. Let It Build a New One?
A prod RDS instance was made by hand and Terraform's plan wants to create a new one. A teammate says just apply. Defend what you actually do first.
Answer key reviewed by Branko Petric
Read first: Terraform State Explained
Your decision
You're bringing a manually-created prod RDS instance under Terraform, and because it's not in state, plan shows Terraform wanting to create a new instance. A teammate says just apply it, Terraform will make a matching one, we'll point the app at it and be consistent. What do you do, and why?
The situation
A production database was created by hand in the AWS console months ago and is now being adopted into Terraform. You run terraform plan and it shows a create for the RDS instance: the live resource is not tracked in state, so Terraform plans to build a new one from the HCL. A teammate looks at the green plan and says it is fine.
Context
The RDS instance holds live customer data and has been serving production traffic for months. It exists in the account but not in Terraform state, so Terraform has no knowledge of it. A teammate in chat says: just apply it, Terraform will make a matching one, we point the app at it, delete the old console-made one, and then everything is consistent and codified.
Worked interview answers
- Terraform Scenario Based Interview Questions: Read the Plan, Then Answer
Terraform scenario based interview questions, worked: a destroy in the plan, state drift, import vs recreate, state in git and blast radius, with real commands.
Related challenges
- Commit terraform.tfstate to the Repo So Everyone Shares It?
A teammate wants to commit terraform.tfstate to git so the whole team shares one state file. Defend the correct way to share Terraform state.
- Terraform Wants to Replace the Database. Apply Now?
A routine terraform plan unexpectedly wants to destroy and recreate the production database. Defend whether to apply, and how.
- Someone Changed Infra by Hand. Terraform Plan Is a Mess.
A manual console change put Terraform's state out of sync, and the next plan wants to undo it. Defend how you reconcile it.
- One Giant Terraform State Runs Everything
A single Terraform state holds all your infra; every plan is slow and scary. A teammate wants to just keep applying carefully. Defend how you reduce the blast radius.