Infrastructure as code

Cloud, deploys and infrastructure Mid-level Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Pick the fix

A plan shows -/+ aws_db_instance.main (forces replacement) for a tag change. What should you do?

Options
Hint 1 of 1

What does -/+ mean?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Stop and find which attribute forces replacement before applying

Correct. Replacing a database can lose data.

-/+ with 'forces replacement' means the tool will destroy the database and create a new one. Find the attribute causing it first; often it is a setting that can only be set at creation.

Why not the others?
  • B Apply; tags are harmless. The plan says it will replace the database.
  • C Delete the state file. Makes everything worse.
  • D Apply from a laptop instead. Same plan.

30-second answer

Declaring servers, databases, networks and permissions in code (Terraform, OpenTofu, Pulumi, CloudFormation) makes infrastructure reviewable, repeatable across environments and recoverable after a disaster. Change it like application code: pull request, automatic plan showing exactly what will change, review, then apply from CI with a locked remote state. Watch the plan for destroys and replacements of stateful resources.

Practise saying it · 25 s. No recording, just a timer

Infrastructure as code.

Say your answer out loud, then check which of these points you covered:

  • Reviewable, repeatable
  • Plan in PR
  • Apply from CI with locked state
  • Guard stateful resources

Deep dive

Remote state with locking stops two applies racing.

Prevent-destroy guards on databases and buckets.

Detect drift from manual console changes.

Modules keep environments consistent.

Common mistakes

  • Clicking changes in the console.
  • Applying from laptops with local state.
  • Not reading the plan before apply.

Senior take & follow-ups

Benefits, PR + plan + review + CI apply, and guards for stateful resources.

Follow-up questions

Think of your answer first, then open the hint.

  1. What's drift?

    Show hint

    Real infrastructure differing from the code.

  2. Why remote state locking?

    Show hint

    Two applies at once can corrupt state.

Suggest a fix if something here is wrong or out of date.