Interview Prep/Terraform/Secrets Provisioners and Policy as Code

An application needs a secret at boot. A teammate puts it in `user_data`. Why is that wrong, and what's the alternative?

IntermediateScenarioSecrets Provisioners and Policy as Code
Answer

Situation read → User data is readable from the instance metadata and visible in console and state.

What I'd do →

  1. Remove the secret from user data.
  2. Give the instance an IAM role.
  3. Have the app or boot script fetch it from Secrets Manager or SSM Parameter Store at runtime.
  4. Enforce IMDSv2 with metadata_options { http_tokens = "required" }.

Why → Secrets stay out of code, state and metadata, and access is auditable and revocable.

Interview tip → Mention rotation: runtime fetch makes it painless.

All Terraform questions

More on Secrets Provisioners and Policy as Code