Skip to content

Add terraform state registry#36710

Merged
lunny merged 69 commits into
go-gitea:mainfrom
TheFox0x7:terraform-package
Apr 6, 2026
Merged

Add terraform state registry#36710
lunny merged 69 commits into
go-gitea:mainfrom
TheFox0x7:terraform-package

Conversation

@TheFox0x7
Copy link
Copy Markdown
Contributor

@TheFox0x7 TheFox0x7 commented Feb 22, 2026

Adds terraform/opentofu state registry with locking

implements: #33644


Based mostly on: #34331 as it was in more complete state (it didn't error out on apply) and somewhat on: #33277

I also checked encrypted state, it works out of the box.

Docs PR: https://gitea.com/gitea/docs/pulls/357

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 22, 2026
I think it's out of scope - if the feature doesn't work, terraform state
isn't the place to check that
@delvh
Copy link
Copy Markdown
Member

delvh commented Feb 23, 2026

What's keeping it a WIP PR?

@TheFox0x7
Copy link
Copy Markdown
Contributor Author

The fact it's a messy merge of the two linked ones, the fact I haven't read the code properly and just removed failing parts and the fact I'm not sure it works properly aside from simple tests (for example if locking works as it should).

Reviews are welcome but I don't want to advertise this as ready for merge/review if I don't know it is.

@TheFox0x7
Copy link
Copy Markdown
Contributor Author

TheFox0x7 commented Feb 23, 2026

@elbandi In case you're still around and interested in the topic, maybe you could you take a look? It's mostly based on your work which was in way better state than the other one (plus the other one is stale)
I mostly added versioning by serial and changed endpoints a bit so they match gitlab's system but you had some ideas for the feature which I could include.

unless you want to resume working on your version or take this one back.

@elbandi
Copy link
Copy Markdown
Contributor

elbandi commented Feb 23, 2026

@elbandi In case you're still around and interested in the topic, maybe you could you take a look? It's mostly based on your work which was in way better state than the other one (plus the other one is stale) I mostly added versioning by serial and changed endpoints a bit so they match gitlab's system but you had some ideas for the feature which I could include.

unless you want to resume working on your version or take this one back.

This serial based versioning is not good. terraform state has only one version: the latest. Old states are obsolete.

But we want to store different states on one project: eg branch or different input variables. like in gitlab:

https://gitlab.com/api/v4/projects/<TARGET-PROJECT-ID>/terraform/state/<TARGET-STATE-NAME>

@TheFox0x7
Copy link
Copy Markdown
Contributor Author

Makes sense but in that case why does gitlab have /projects/:id/terraform/state/:name/versions/:serial route?

@elbandi
Copy link
Copy Markdown
Contributor

elbandi commented Feb 23, 2026

Makes sense but in that case why does gitlab have /projects/:id/terraform/state/:name/versions/:serial route?

Looks like, in gitlab you can only download and delete the old states. (maybe for audit?, i dont know what is it good for in normal circumstances).

But upload/lock/unlock based on state-name, UI hasn't got version control too.

@wxiaoguang
Copy link
Copy Markdown
Contributor

So finally it catches 1.26 release.

Copy link
Copy Markdown
Member

@bircni bircni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy 1.26

@wxiaoguang wxiaoguang enabled auto-merge (squash) April 6, 2026 16:11
@TheFox0x7
Copy link
Copy Markdown
Contributor Author

TheFox0x7 commented Apr 6, 2026

Spoke too soon. Found a bug with encrypted state handling... I'll fix that and add it to tests so it's also covered. It's fairly simple, it just decodes the state wrong

@TheFox0x7 TheFox0x7 marked this pull request as draft April 6, 2026 16:12
auto-merge was automatically disabled April 6, 2026 16:12

Pull request was converted to draft

@TheFox0x7 TheFox0x7 marked this pull request as ready for review April 6, 2026 16:46
@TheFox0x7
Copy link
Copy Markdown
Contributor Author

Fixed. Dropped some validation rules which weren't that useful in the first place. I really don't expect anyone to actively push state files via curl with only two properties and even if I can reintroduce it if needed via a patch.

Comment thread routers/web/user/package.go
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 6, 2026
@bircni
Copy link
Copy Markdown
Member

bircni commented Apr 6, 2026

@TheFox0x7 did you create a pr for docs?

@TheFox0x7
Copy link
Copy Markdown
Contributor Author

It's in PR description - https://gitea.com/gitea/docs/pulls/357

@lunny lunny merged commit ff777cd into go-gitea:main Apr 6, 2026
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 6, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 7, 2026
* main:
  Repair duration display for bad stopped timestamps (go-gitea#37121)
  Add terraform state registry (go-gitea#36710)
  Add placeholder content for empty content page (go-gitea#37114)
  Improve control char rendering and escape button styling (go-gitea#37094)
  Add gpg signing for merge rebase and update by rebase (go-gitea#36701)
  Move package settings to package instead of being tied to version (go-gitea#37026)
  Merge some standalone Vite entries into index.js (go-gitea#37085)
  Update Nix flake (go-gitea#37110)
  [skip ci] Updated translations via Crowdin
  Fix the wrong push commits in the pull request when force push (go-gitea#36914)
@elbandi
Copy link
Copy Markdown
Contributor

elbandi commented Apr 7, 2026

This PR still lacks the ability to store more state files for one "package".
If you run same terraform code with different envs, you need different package names like (foorepo-devel, foorepo-stage, foo-prod).

I will try to rebase my code to this.

@TheFox0x7
Copy link
Copy Markdown
Contributor Author

I'd argue that it makes little sense to store different states in the same package. If you can add different suffix to the name, you can have them in separate packages - why keep them in a single one? What's the usecase?

I'm not entirely against the idea of having the states user named instead of generic "tfstate", but it does complicate the UI side of locks as they now would have to list each state lock individually for the state in the package. Backend is less of an issue as you could just add a state name suffix to the tflock name of the lock record.

@elbandi
Copy link
Copy Markdown
Contributor

elbandi commented Apr 7, 2026

why keep them in a single one? What's the usecase?

As i said: same terraform code with different envs. (devel, stage, prod). The difference only the input tfvars (=provider auth, setting params, like ip address, dns names, etc), but resources are same.

If we want to add separete envs for every developers, the number of state packages are grows fast (N project * M developers)

@wxiaoguang
Copy link
Copy Markdown
Contributor

Maybe you can open a proposal issue with real examples (detailed config, commands, etc), then it would be very useful to help people to understand the problem in real world and discuss the design.

By the way, if we would come to a conclusion that "same terraform code with different envs" is a must and it is a breaking change (hopefully not), we can even spend more time on it to make it right before 1.26.0.

@TheFox0x7
Copy link
Copy Markdown
Contributor Author

okay I dug for a bit and I have a good enough reason to nack this, sorry.
What you're basically talking about are workspaces, which let you split your one single config into separate states named as you'd like. I do see a use for this, sure, but the http backend does not support workspaces in the first place, so we have no way to do so.
I honestly can't see a downside with separate packages per state, especially since they all have different lineage to begin with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-update-needed The document needs to be updated synchronously lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.