r/Terraform • • 8h ago

Discussion how do you bring stuff that was clicked together in the console under terraform, import blocks or just rebuild it

3 Upvotes

every account seems to have a pile of resources someone made by hand before terraform was a thing, or during an incident.

curious how people actually deal with it. import blocks and generate config, terraformer style tools, or just rebuild it clean and cut over?

and what's the worst thing you found halfway through an import


r/Terraform • • 8h ago

Discussion Cloud security findings: platform team fixes them or app teams do? trying to settle an argument

1 Upvotes

We keep going back and forth on this and I would like an outside view.

Option A: platform owns all the terraform modules, so platform fixes every cloud finding. ownership is clean, but they become a bottleneck and app teams never learn anything.

Option B: app teams fix findings in their own stacks. faster in theory, but half of them do not really understand the modules and the fixes end up as one off patches that drift from the module.

Right now it's a mix, which in practice means nobody owns anything. Security is trialing gomboc and rival security to see if fixes can go straight back into the IaC, but that doesn't settle who should own the fix in the first place.

which way did you go, and would you do it again?


r/Terraform • • 1d ago

Passed Terraform Associate (004), sharing how I prepared

Post image
81 Upvotes

Hi all,

I passed the Terraform Associate (004) exam yesterday and wanted to share my experience, since this sub helped me a lot while studying.

Background: developer, with RHCSA/RHCE (Ansible) and AWS SAA/DVA behind me. I had a couple of free days and a birthday voucher, so the whole thing cost me very little. Personally I found the exam fairly easy, but I already had hands-on Linux/AWS/Ansible experience, so your mileage may vary.

How I prepared:

- Video course with slides (Bryan Krausen's course), plus the official HashiCorp docs

- Practice tests on Udemy to find weak spots, then going back to the docs for every mistake

- Writing small configs myself instead of only reading: modules, variables vs locals, remote backend, import, lifecycle rules

- I decided to book the exam after the practice tests started going well

Topics that took me the most time to really understand:

- Module variable scope: child modules inherit nothing, everything is passed explicitly

- State, locking and backends, and what actually gets written to state (secrets in plain text)

- Ephemeral values vs sensitive vs write-only arguments

- plan -refresh-only vs the old terraform refresh, drift and the import workflow

- Variable precedence and version constraints (~>)

Tips:

- If English is not your first language, you can request +30 extra minutes on top of the standard 60 when you register for the exam

- Read each question carefully, many differ by one word (NOT, FALSE, "select two")

- Know the CLI commands and what files they create, not only the HCL syntax

- Do the pre-flight check for the online proctoring well in advance


r/Terraform • • 1d ago

Discussion I built a local emulator of the Nebius AI Cloud API so the official provider can run without an account

1 Upvotes

I've been writing Terraform for Nebius AI Cloud, and iterating against a real tenant was slow and cost money for every apply/destroy cycle. There's no LocalStack equivalent for Nebius, so I wrote one: NebiusMocker.

It serves the same gRPC API as Nebius, so the unmodified nebius/nebius provider works against it. You only change the provider block:

hcl
provider "nebius" {
resolvers = { "*" = "127.0.0.1:4566" }
address_options = { "*" = { insecure = true } }
token = "nmock-dev-admin"
}

Where it stands:

  • 114 of the provider's 116 objects (resources, data sources and ephemeral resources) work. The other two are provider-local and call no API.
  • Every resource is tested with the real provider: create, empty plan, in-place update, empty plan, replace on immutable fields, destroy. A non-empty plan after apply counts as a bug in the mock.
  • Authorization can be enforced, so a viewer token really gets PERMISSION_DENIED, and quotas fail with RESOURCE_EXHAUSTED like the real thing.
  • Some areas have optional real data planes in Docker: S3 on RustFS, docker push via Harbor, Kubernetes on k3s (get-credentials + kubectl work), real PostgreSQL and MLflow.

What it doesn't do: no VMs boot and there are no GPUs (instances are management-plane records), and state is in memory.

It's not affiliated with Nebius, it's a side project, and it's early. If you use Nebius, I'd like to know which resources or workflows you'd want it to handle better.

Repo: https://github.com/kfirgollan/NebiusMocker
Support matrix: https://kfirgollan.github.io/NebiusMocker/terraform.html


r/Terraform • • 1d ago

Discussion how do you review big terraform plans in PRs without just scrolling to the bottom and approving

6 Upvotes

small plans are easy to read but once a change touches a shared module the plan can run to hundreds of lines. it gets really tempting to skim it, see no destroys and hit approve.

what do people actually do here. tools that summarize the plan, policy checks, splitting changes up, or just careful reading? and has a skimmed plan ever let something bad through for you


r/Terraform • • 1d ago

Tutorial Terraform for Enterprise Deployments – Managing Infrastructure Beyond Basic IaC

Thumbnail datadevblog.com
1 Upvotes

Hi everyone,

As infrastructure grows, managing Terraform configurations across multiple environments can become challenging.

What works for a small project doesn't always work when you're managing enterprise infrastructure with multiple environments, teams, modules, remote state files and shared resources.

Some common challenges include:

  • Managing Terraform state securely across teams.
  • Reusing configurations through modules.
  • Handling different environments such as Dev, UAT and Production.
  • Managing remote state and state locking.
  • Avoiding configuration duplication.
  • Maintaining consistency across infrastructure deployments.

I've put together an article discussing how Terraform can be structured and used for enterprise deployments, with a focus on making infrastructure management more organized and maintainable.

If you're working with Terraform or planning to adopt it, you might find it useful:

https://datadevblog.com/terraform-best-enterprise-deployments/

I'd also like to hear from other sysadmins and infrastructure engineers:

What's your biggest challenge when managing Terraform in a production or enterprise environment?

Is it state management, module design, environment separation, or something else?

Happy to hear your experiences and suggestions.


r/Terraform • • 1d ago

Discussion GL.iNet Terraform Provider

Thumbnail reddit.com
2 Upvotes

r/Terraform • • 2d 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 • • 2d ago

Discussion Should you allow deletion on a self service platform?

2 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 • • 2d ago

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

22 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 • • 2d ago

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

19 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 • • 3d 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 • • 3d 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 test terraform modules before rolling them out, or is it mostly plan and hope

7 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 • • 5d 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 • • 5d 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 • • 5d 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 • • 5d 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 • • 6d 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 • • 6d 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 • • 6d ago

Azure IaC with Azure Virtual Desktop

4 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 • • 6d 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 • • 7d ago

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

28 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 • • 8d 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?