The forgejo_ssh_key resource uses the AdminCreateUserPublicKey method from the forgejo client to create a public key for a given user:
|
key, res, err := r.client.AdminCreateUserPublicKey( |
This requires an admin account to be provided in the provider credentials. Instead it should be possible to create ssh keys for the provider user as non-admin using the CreatePublicKey method:
https://codeberg.org/mvdkleijn/forgejo-sdk/src/commit/75e5a725cf15e0025bf635fd6f0efa9b24e15b1f/forgejo/user_key.go#L73
This would allow the terraform to be used with pre-existing non-admin users e.g.
locals {
username = "my_svc"
password = "my_svc_password"
forgejo_url = "https://forgejo.example.com"
}
provider "tls" {}
provider "forgejo" {
alias = "my_svc"
host = local.forgejo_url
username = local.username
password = local.password
}
resource "tls_private_key" "ssh_key" {
algorithm = "ED25519"
}
data "forgejo_user" "user" {
provider = forgejo.my_svc
login = local.username
}
resource "forgejo_ssh_key" "ssh_key" {
provider = forgejo.my_svc
user = data.forgejo_user.user.login
key = trimspace(tls_private_key.ssh_key.public_key_openssh)
title = "terraform"
create_as_admin = false # Add this option to disable the admin client
}
This allows a terraform module that has access to existing user credentials to create SSH keys for those users without needing to provide admin credentials for forgejo:
provider "forgejo" {
alias = "my_svc"
host = local.forgejo_url
username = "my_svc"
password = "my_svc_password"
}
module "forgejo_ssh_my_svc" {
providers = {
forgejo = forgejo.my_svc
}
...
}
The
forgejo_ssh_keyresource uses theAdminCreateUserPublicKeymethod from the forgejo client to create a public key for a given user:terraform-provider-forgejo/internal/provider/ssh_key_resource.go
Line 208 in d3b15f4
This requires an admin account to be provided in the provider credentials. Instead it should be possible to create ssh keys for the provider user as non-admin using the
CreatePublicKeymethod:https://codeberg.org/mvdkleijn/forgejo-sdk/src/commit/75e5a725cf15e0025bf635fd6f0efa9b24e15b1f/forgejo/user_key.go#L73
This would allow the terraform to be used with pre-existing non-admin users e.g.
This allows a terraform module that has access to existing user credentials to create SSH keys for those users without needing to provide admin credentials for forgejo: