Skip to content

feat: add users and groups support#7

Draft
mircea-pavel-anton wants to merge 2 commits intodeevus:mainfrom
mirceanton:feat/users
Draft

feat: add users and groups support#7
mircea-pavel-anton wants to merge 2 commits intodeevus:mainfrom
mirceanton:feat/users

Conversation

@mircea-pavel-anton
Copy link

Fixes #1

This PR adds support for managing both truenas_users and truenas_groups as resources as well as data sources.

Disclaimer: I did use claude code to help me generate this code. Feel free to dismiss this PR if that does not align with the project goals. I saw a CLAUDE.md file in the repo root so I assumed it would be fine.

I have tested this in my homelab with this code: https://github.com/mirceanton/truenas-apps/tree/feat!/terraform/terraform/truenas

@deevus
Copy link
Owner

deevus commented Feb 23, 2026

This looks great! The api changes will need to be moved to https://github.com/deevus/truenas-go as services. Once that lands, it should be fairly simple to consume those here as resources.

@deevus
Copy link
Owner

deevus commented Feb 27, 2026

Rebase and integrate UserService and GroupService from deevus/truenas-go#11

Once tested and confirmed working I will merge upstream.

@mircea-pavel-anton
Copy link
Author

found a bug:

resource "truenas_group" "test" { name = "test" }
resource "truenas_user" "test" {
  username     = "test"
  full_name    = "Test User"
  email        = "test@mirceanton.com"
  shell        = "/usr/sbin/nologin"
  group_id = truenas_group.test.id
  groups   = [data.truenas_group.builtin_users.id]
  password     = "test"
}

This config causes the group to also be deleted if i delete the group. need to look into it some more. Will mark this PR as draft until then

@mircea-pavel-anton mircea-pavel-anton marked this pull request as draft March 4, 2026 19:31
filter := [][]string{{"group", "=", data.Name.ValueString()}}

result, err := d.client.Call(ctx, "group.query", filter)
result, err := d.services.Client.Call(ctx, "group.query", filter)
Copy link
Owner

Choose a reason for hiding this comment

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

This is not what I meant. We shouldn't be calling Client.Call directly from terraform-provider-truenas anymore. In this case you probably want GroupService.GetByName

You will need to use a replace directive to use the code from deevus/truenas-go#11 (clone and checkout the branch locally).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Users and Groups

2 participants