-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Add terraform state registry #36710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add terraform state registry #36710
Changes from 32 commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
2f8577e
Add terraform state packages
elbandi 1d7eaef
Add terraform state lock
elbandi 321d999
Fix lint
elbandi 0926611
Regenerate gitea-terraform svg
elbandi c4e566b
Better package setup details
elbandi 4272ae5
lintfix no2
elbandi e6f33be
fix indent
elbandi e2b1476
Merge branch 'main' into terraform-package
TheFox0x7 ea9b931
port locale addition
TheFox0x7 5fc205f
replace function calls
TheFox0x7 f2a4971
mirror gitlab routes, use serial as verison system
TheFox0x7 b7e51ee
update routes
TheFox0x7 d662d4b
fix test a bit
TheFox0x7 2d51d06
remove direct serve test
TheFox0x7 1273929
add database held locks
TheFox0x7 2ef423c
fix locking not returning the held lock
TheFox0x7 98eb8c0
Merge branch 'main' into terraform-package
TheFox0x7 86d0438
extract consts
TheFox0x7 f985133
remove unlocker since state is stored in database now
TheFox0x7 d67b55e
extract common helpers
TheFox0x7 cb80dde
fix svg
TheFox0x7 c0c6d5b
rename const
TheFox0x7 d29cc85
rephrase the setup section
TheFox0x7 1a6313b
Merge branch 'main' into terraform-package
TheFox0x7 1360e3d
Merge branch 'main' into terraform-package
TheFox0x7 98f0118
add lock display in UI
TheFox0x7 ce4bf24
fix icon
TheFox0x7 21da29a
prevent deletion of locked and latest packages in UI
TheFox0x7 c455ccd
fix nilnil
TheFox0x7 799d7c0
factor out common parts to a module
TheFox0x7 16dca47
fix lint
TheFox0x7 adb2cf2
add copyright header
TheFox0x7 21ec4c9
update copyright date
TheFox0x7 6504ed3
fix duplicated logic
TheFox0x7 b76bbc2
add lock on api upload
TheFox0x7 e93b1de
fix error comparison
TheFox0x7 c8318f5
update svg
TheFox0x7 f80116f
group routes and enforce read write on locks
TheFox0x7 fb3f13f
fix route
TheFox0x7 b4e98ea
remove if in template
TheFox0x7 3ab2acf
parse the state and lock file
TheFox0x7 9d3f2e5
address remaining points of review
TheFox0x7 00c2720
refactor set and remove state to ignore nonempty/empty state
TheFox0x7 e5b5a4e
fix formatting
TheFox0x7 a1c9ddc
Update options/locale/locale_en-US.json
techknowlogick aa509e4
Merge branch 'main' into terraform-package
TheFox0x7 cf3c6e6
Merge branch 'main' into terraform-package
TheFox0x7 e9f0c35
forbid from removing the state from UI when its locked
TheFox0x7 b84389a
drop origin-url
TheFox0x7 5972ab5
add service helpers for state
TheFox0x7 0d6c9a6
add Value to gitea's json module
TheFox0x7 4e8a48f
formatting
TheFox0x7 0e7394f
missed import
TheFox0x7 1412290
json value
wxiaoguang 907dc68
fix lint
wxiaoguang 2bbc654
refactor
wxiaoguang 8e79712
refactor view package version
wxiaoguang f995892
fix err msg
wxiaoguang 700781c
fix lint
wxiaoguang f8adfaf
fix UI regression where lock could not have been added on the package
TheFox0x7 67ab2a2
use flex-text-block and drop margins
TheFox0x7 f17d92c
update example ini with state limit
TheFox0x7 a073c72
remove unused global error var
wxiaoguang 9797754
Merge branch 'main' into terraform-package
wxiaoguang 7bd9134
drop full validation of state file as it was interrupting the encrypt…
TheFox0x7 e45dcbb
someday I'll setup a pre-push hook to stop me from pushing before for…
TheFox0x7 34d8676
expand comment
TheFox0x7 134637b
return
TheFox0x7 ef630e7
Merge branch 'main' into terraform-package
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
| package terraform | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| packages_model "code.gitea.io/gitea/models/packages" | ||
| "code.gitea.io/gitea/modules/json" | ||
| ) | ||
|
|
||
| const LockFile = "terraform.lock" | ||
|
|
||
| // LockInfo is the metadata for a terraform lock. | ||
| type LockInfo struct { | ||
| ID string `json:"ID"` | ||
| Operation string `json:"Operation"` | ||
| Info string `json:"Info"` | ||
| Who string `json:"Who"` | ||
| Version string `json:"Version"` | ||
| Created time.Time `json:"Created"` | ||
| Path string `json:"Path"` | ||
| } | ||
|
|
||
| func (l *LockInfo) IsLocked() bool { | ||
| return l.ID != "" | ||
| } | ||
|
|
||
| // GetLock returns the terraform lock for the given package. | ||
| // Lock is empty if no lock exists. | ||
| func GetLock(ctx context.Context, packageID int64) (LockInfo, error) { | ||
| var lock LockInfo | ||
| locks, err := packages_model.GetPropertiesByName(ctx, packages_model.PropertyTypePackage, packageID, LockFile) | ||
| if err != nil { | ||
| return lock, err | ||
| } | ||
| if len(locks) == 0 || locks[0].Value == "" { | ||
| return lock, nil | ||
| } | ||
|
|
||
| err = json.Unmarshal([]byte(locks[0].Value), &lock) | ||
| return lock, err | ||
| } | ||
|
|
||
| // SetLock sets the terraform lock for the given package. | ||
| func SetLock(ctx context.Context, packageID int64, lock *LockInfo) error { | ||
| jsonBytes, err := json.Marshal(lock) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return packages_model.InsertOrUpdateProperty(ctx, packages_model.PropertyTypePackage, packageID, LockFile, string(jsonBytes)) | ||
| } | ||
|
|
||
| // RemoveLock removes the terraform lock for the given package. | ||
| func RemoveLock(ctx context.Context, packageID int64) error { | ||
| return packages_model.InsertOrUpdateProperty(ctx, packages_model.PropertyTypePackage, packageID, LockFile, "") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.