r/Terraform • • 10h ago

Discussion how do you protect prod from an accidental terraform destroy, and has it ever actually happened to you

12 Upvotes

was reading about someone running destroy in the wrong workspace and it got me thinking how thin the guardrails usually are.

do you rely on prevent_destroy, separate creds per env, deletion protection on the resources themselves, or just a pipeline that never runs destroy at all?

and if you have a story of it going wrong, what did you change after


r/Terraform • • 7h ago

Discussion Should you allow deletion on a self service platform?

1 Upvotes

I work on a platform for data engineers that allows people to request spaces to work or store their data in. One of the infra you can request is a glue DB.

Because we want it to be as self service as possible, we also allow you to delete said glue DB, resulting in TF destroy.

However, if something goes wrong in the translation between platform and TF yaml, there are no guardrails whatsoever and we destroy all Glue DBs, thinking it's what the end user wants.

How would you approach this? What is the boundary for the guardrails, where do you put human / agent approves before auto destroy?


r/Terraform • • 21h ago

Discussion Is it just me, or are AI-written Terraform PRs getting rubber-stamped?

8 Upvotes

I work with a lot of teams on AWS and I keep seeing the same thing: Terraform PRs mostly written by an agent, sometimes with a human steering, sometimes not. The plan looks clean, the diff is big, and the review quietly turns into scrolling and approving.

I can't shake the feeling this shouldn't become the norm. But maybe I'm in a bubble.

How do you handle it?

  • Do you use AI for Terraform at all?
  • If yes, do you treat AI-written infra PRs differently?
  • Can agents run plan/apply, or only open PRs?
  • What actually helped: policy checks, smaller PRs, a second reviewer for prod?

Edit: Yes I used AI to fix my english, im not native. Thanks for the real answers, really useful


r/Terraform • • 5h ago

Announcement I built a local-first web UI for Terraform/OpenTofu – browse state, review plans visually, detect drift

0 Upvotes

Hey r/Terraform,

I'm a DevOps engineer, and I built Hclaro because I was tired of chaining state list / state show / plan output in the terminal to understand a workspace.

It's a single binary. Run hclaro in a Terraform/OpenTofu root and it opens a private web UI on your machine. No accounts, no telemetry, no cloud service.

What it does:

  • Resource Explorer: browse resources, nested modules, and providers from state, with sensitive attributes redacted
  • Visual Plan Review: see every change, its replacement order, the reason, and the attribute diff
  • Safe applies: it only applies a reviewed saved plan, after preflight checks and a typed confirmation. It never runs destroy, state rm/mv, or force-unlock
  • Drift detection (refresh-only, never writes state), a dependency graph, and workspace comparison
  • Workspace Hub for managing multiple roots and workspaces
  • Developer tools: execution profiles, operation history, Git status and branch switching, plus opt-in Infracost estimates and AI review
  • Cloud Discovery: read-only discovery for AWS, Azure, and Google Cloud

Github: https://github.com/botopsy/hclaro

I'd appreciate it if you tried it with a project and shared your feedback, feature ideas, or bug reports here or through GitHub Issues.


r/Terraform • • 1d ago

Discussion how do you test terraform modules before rolling them out, or is it mostly plan and hope

6 Upvotes

plan tells you what changes but not if the thing actually works after apply. i've seen terraform test, terratest, and people just spinning up a sandbox account and poking around. what do you actually run before bumping a module version that other teams use? and has a module change ever passed plan fine but broke something real


r/Terraform • • 1d ago

Discussion new platform for running Terraform/OpenTofu

0 Upvotes

Hi all!

I am building tool/platform Zenfra.

If you ever managed terraform/tofu for a team, you know the drill. Starts with a simple pipeline, then you add some approvals, CI runners, some custom scripts to glue it all together, etc. Before you know it - you are spending more time managing the pipeline(s) than the infrastructure itself.

This is what I wanted to solve with Zenfra. It executes Terraform/Opentofu plan and applies, keeping track of the plan, approvals history, execution logs in one place.

Support managed and self-hosted workers in your network so creds remain safe, Keyless auth for AWS/Azure/gcp.
Additional feature as drift detection, policies, dependencies, etc...

But the main reason I'm posting is to learn from people who work with IaaC tools daily.
- What annoys you in you current iaac pipeline/workflow setup?
- What would a new tool need to have have before you consider to try it?
- And what should be there for you to trust it with your state and credentials?

All answers appreciated, including "I would never use this (and here is why)".

https://zenfra.cloud

thanks!


r/Terraform • • 1d ago

Discussion What evidence makes you ask someone to hold a Terraform apply?

0 Upvotes

I’m building Proofline, a tool that reviews pull requests. I’m trying to work out when a review comment on a Terraform change is worth reading. The thread here about rolling back an AzureRM provider upgrade got me thinking about a case where I’d genuinely like a second opinion.

Say a PR bumps the provider and the plan shows an in-place update. Someone asks how we’d back it out. The author says “revert the version pin.” That sounds reasonable until you ask whether the old provider can still read the state after the upgrade, and what reverting the pin would actually undo in Azure.

My instinct is that if Proofline can point to a specific resource whose state schema changed and explain what that means for this rollback plan, I’d want that in the PR. Where I’m torn is what to do when it can’t establish the answer. Would “has anyone tested the downgrade?” make you pause and check something useful, or is that exactly the kind of comment you’d mute after the third upgrade?

If you’ve been through one of these, what did you actually check before apply? I’m especially curious about cases where the plan looked routine and someone on the team knew to ask one more question.


r/Terraform • • 3d ago

Discussion how do you handle provider version upgrades across a bunch of modules without breaking stuff

20 Upvotes

we have a lot of modules pinned to older aws provider versions and every big upgrade turns into a week of plan diffs and surprise changes.

do you bump everything at once, go module by module, or use something like renovate to keep them moving in small steps?

curious how people keep this from becoming a scary once a year job.


r/Terraform • • 3d ago

Discussion Is there a way to sort the outputs other than the default alphabetical order?

5 Upvotes

terraform output command in my humble opinion should follow outputs.tf order...


r/Terraform • • 2d ago

Announcement uapi: v4, an MCP server for AI agents, and a package PR for OpenWrt

Thumbnail reddit.com
0 Upvotes

Sharing here because the main goal of uapi is to be a terraform provider backend.


r/Terraform • • 3d ago

Discussion planfence: a small CLI that gates terraform/tofu plan JSON between plan and apply, and fails closed (looking for holes)

0 Upvotes

I wrote a small open-source CLI (MIT, Python) that reads `terraform show -json` / `tofu show -json` output and checks it against a TOML contract before apply. Exit 0 = pass, 1 = violation, 2 = could not judge (fail closed: unknown format, errored/incomplete plan, etc.).

Rules: no-delete, no-replace, scope (allowed addresses), stateful-protect, budget (max changes). Example from a real fixture:

[error] no-replace local_file.hello (local_file) delete,create

planfence: FAIL - 1 violation(s)

No model in the loop: it is plain deterministic code. The tests use real plans from Terraform 1.17.2 and OpenTofu 1.13.9, plus fuzzing against an independent oracle and mutation testing.

Why not a jq one-liner? A replace can show up as delete+create in either order, a moved resource has `previous_address`, and a for_each key rename is a delete + create of different addresses (no-replace does not catch that one, no-delete does). The point is to encode those edge cases once and fail closed on anything it cannot read.

Honest limits: this is not a security audit and does not replace review. If you already use Sentinel/OPA/Conftest you probably don't need it. Drift and output-only changes are ignored by default, and OpenTofu `-target` is not detectable from the plan.

Disclosure: I built this with a lot of help from Claude Code.

Question: where would you expect it to fail open?

pip install planfence

https://github.com/ZahraMost/planfence


r/Terraform • • 4d ago

terraform_remote_state Data Source

Thumbnail developer.hashicorp.com
5 Upvotes

We have a project underway for subscription vending in Azure, as part of the code base, it has been decided to use the terraform_remote_state data source.

To date I have never seen or used this resource, I have always utilised data blocks and providers.

Is anyone using this or am I right in assuming this is not a good idea, I know its mentioned on the HCP site that using the terraform_remote_state is not the preferred option.


r/Terraform • • 4d ago

Azure Terraform provider upgrade rollback, is roll-forward the best practice?

5 Upvotes

It's to my understanding that terraform really has no concept of a `rollback`. After all we are just modifying resources.

Below is what I found online from people working on Terraform.

Instead when using Terraform it’s more common to roll forward by correcting whatever made the apply fail and then planning and applying again. One possible way to “correct” your configuration would be to change it back to how it was before the problem, but that’s not always sufficient and so human intervention is typically required.

So mu question is, regarding provider upgrades like major upgrades to azurerm provider version, what would be the best option for rollback if something stuffs up for sake of risk assessment?

For normal resource changes we can often just re-run the ci for the older build and it will work, but provider upgrades don't work like this. It seems like there are two options

  1. Fix whatever is breaking and roll-forward
  2. TF cloud state version history, however this doesn't modify your infra?

r/Terraform • • 5d ago

Discussion how do you catch drift when someone changes stuff by hand in the console

29 Upvotes

terraform only finds out much later when something was changed by hand. do you run plan on a schedule and get alerts or just let it be. also do you lock down console access to stop it. curious what actually works.


r/Terraform • • 4d ago

Azure IaC with Azure Virtual Desktop

3 Upvotes

Hello everyone,

I am currently attempting to implement some automation into our Azure infrastructure. I was thinking about implementing Terraform with our AVDs but Nerdio automates a lot of the process. Does anyone have any ideas on how I could automate the gaps that Nerdio doesn't?


r/Terraform • • 4d ago

Azure How to handle pod eveictions while running terraform apply in github actions.

1 Upvotes

We are deploying azure infra using github actions which uses a self hosted runner hosted on the GCP kubernetes cluster. What we have observed is apply getting failed with 130 code because of pod eviction. How to handle these scenarios.


r/Terraform • • 6d ago

Discussion Agent written Terraform PRs keep fighting manual changes in the console

0 Upvotes

We manage about 400 resources in Terraform across 3 AWS accounts. Agents write most of our infra PRs now, and they write them against the code, not against what's actually deployed.

Last month someone had raised an RDS instance size in the console during an incident and never put it back in code. Two weeks later an agent PR for an unrelated tag change went through, the plan showed the instance size going back down, it was one line in a 60 line plan, and nobody noticed. The database got resized during business hours.

coderabbit reviews the HCL and it's useful, it caught a hardcoded secret in a variable default last month. But drift between code and reality isn't in the diff, it's only in the plan, and long plans don't get read carefully.

What we're trying now:

- a scheduled drift check that opens an issue when real state differs from code

- failing CI if a plan modifies or replaces anything in our "do not touch" list

- posting a short plan summary at the top of the PR instead of the full output

How do you stop console changes and agent PRs from overwriting each other?


r/Terraform • • 7d ago

Help Wanted Explicitly overridden data source still "unknown" in test

3 Upvotes

I am trying to write some tests, and stumbled upon "Unknown condition value" which I cannot resolve with any overrides. It gives that error in second assert even though both resource and data source are overridden, why? Tried latest 1.17.2

main.tf:

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 6.0"
    }
  }
}

resource "github_repository" "main" {
  name = "my-test"
}

data "github_repository_file" "existing_file" {
  repository = github_repository.main.name
  file       = "existing_file.yaml"
}

main.tftest.hcl:

mock_provider "github" {
  override_during = plan
}

override_resource {
  override_during = plan
  target = github_repository.main
}

override_data {
  override_during = plan
  target = data.github_repository_file.existing_file
  values = {
    content = "{}"
  }
}

run "release_defaults" {
  command = plan
  assert {
    condition     = github_repository.main.name == "x"
    error_message = "repo"
  }
  assert {
    condition     = data.github_repository_file.existing_file.content == "x"
    error_message = "content"
  }
}

If I switch reference to repository = "my-test" it works, but I need to keep a dependency.


r/Terraform • • 8d ago

Discussion do you split terraform state per environment or per component

40 Upvotes

trying to decide how to carve up our state files. one per environment is easy to follow but each one keeps growing. one per component keeps plans small but then outputs have to be shared between them. what do you use and what made you pick it


r/Terraform • • 9d ago

Discussion Do junior DevOps engineers need to write Terraform from memory?

117 Upvotes

Hey everyone,

I'm learning DevOps and trying to land my first junior role. I've been practicing Linux, Docker, GitHub Actions, CI/CD, GCP, and recently started learning Terraform.

I understand what Terraform does and how the resources work, but I still struggle to write the configurations from scratch without looking at examples or documentation.

For people actually working in DevOps, how much Terraform syntax do you remember? Are juniors expected to write configurations from memory, or is understanding the concepts and being able to work with documentation enough?

I'm trying to figure out what level I should reach before applying for jobs.

Thanks!


r/Terraform • • 8d ago

Discussion The community Neon Terraform provider is now official as neondatabase/neon

Thumbnail reddit.com
5 Upvotes

r/Terraform • • 8d ago

Discussion Do you block every Terraform plan that replaces a database?

0 Upvotes

Say a PR moves an RDS instance into a module. The author expects the database to stay put, but the plan says it’ll be replaced. That’s an easy call in review. What I’m curious about is what happens when the replacement is intentional. Does the same check block it? Who can clear it, and what do they want to see first?


r/Terraform • • 10d ago

Discussion do you keep one state per environment or one per team and why

17 Upvotes

i keep seeing both setups. one state per environment is simple to reason about but gets big and slow. one per team limits the blast radius but then shared stuff like networking gets awkward. curious where people draw the line.


r/Terraform • • 10d ago

Discussion Terraform Provider Development Consulting

8 Upvotes

Does anyone have recommendations for consultants or service providers that specialize in Terraform provider development and maintenance?

Curious what experiences others have had with getting outside help to improve existing providers that have struggled with quality, reliability, and ongoing maintenance.

Would be interested to hear who you’ve worked with and how it went.