Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/resources/ai_group_budget.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |-
~> Warning
This resource is only compatible with Coder version 2.34.0 and later.
Manages the AI spend limit that AI Gateway applies to each member of a group. Requires a Premium license with the AI Gateway feature, and permission to update the group.
Each member of the group can spend up to the limit in each budget period. When a user belongs to several groups with a budget, the deployment's AI budget policy selects the group that applies.
Each member of the group can spend up to the limit in each budget period. When a user belongs to several groups with a budget, the deployment's AI budget policy selects the group that applies. Use coderd_ai_user_budget_override to set a different limit for a single user.
-> If Coder already has a different budget for the group, the plan fails. Import that budget to manage it with Terraform.
Destroying this resource removes the budget, so members of the group no longer have a spend limit from it. Coder also removes the budget when the group is deleted.
---
Expand All @@ -18,7 +18,7 @@ This resource is only compatible with Coder version 2.34.0 and later.

Manages the AI spend limit that AI Gateway applies to each member of a group. Requires a Premium license with the AI Gateway feature, and permission to update the group.

Each member of the group can spend up to the limit in each budget period. When a user belongs to several groups with a budget, the deployment's AI budget policy selects the group that applies.
Each member of the group can spend up to the limit in each budget period. When a user belongs to several groups with a budget, the deployment's AI budget policy selects the group that applies. Use `coderd_ai_user_budget_override` to set a different limit for a single user.

-> If Coder already has a different budget for the group, the plan fails. Import that budget to manage it with Terraform.

Expand Down
79 changes: 79 additions & 0 deletions docs/resources/ai_user_budget_override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coderd_ai_user_budget_override Resource - terraform-provider-coderd"
subcategory: "AI Governance"
description: |-
~> Warning
This resource is only compatible with Coder version 2.35.0 and later.
Manages an AI spend limit for a single user, which takes precedence over the user's coderd_ai_group_budget limits. Requires a Premium license with the AI Gateway feature, and permission to update both the user and the group.
The override attributes the user's spend to a group, which the user must be a member of. Coder removes the override when the user leaves that group or its organization, or when the user or the group is deleted.
-> If Coder already has a different override for the user, the plan fails. Import that override to manage it with Terraform.
Destroying this resource removes the override, so the user's group budgets apply again.
---

# coderd_ai_user_budget_override (Resource)

~> **Warning**
This resource is only compatible with Coder version 2.35.0 and later.

Manages an AI spend limit for a single user, which takes precedence over the user's `coderd_ai_group_budget` limits. Requires a Premium license with the AI Gateway feature, and permission to update both the user and the group.

The override attributes the user's spend to a group, which the user must be a member of. Coder removes the override when the user leaves that group or its organization, or when the user or the group is deleted.

-> If Coder already has a different override for the user, the plan fails. Import that override to manage it with Terraform.

Destroying this resource removes the override, so the user's group budgets apply again.

## Example Usage

```terraform
resource "coderd_user" "alice" {
username = "alice"
email = "alice@example.com"
}

resource "coderd_group" "engineering" {
name = "engineering"
members = [coderd_user.alice.id]
}

resource "coderd_ai_group_budget" "engineering" {
group_id = coderd_group.engineering.id
spend_limit = 50000000 // $50.00 for each member of the group
}

resource "coderd_ai_user_budget_override" "alice" {
user_id = coderd_user.alice.id
group_id = coderd_group.engineering.id
spend_limit = 200000000 // $200.00 for alice, attributed to engineering
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `group_id` (String) ID of the group that the user's spend is attributed to. The user must be a member of the group.
- `spend_limit` (Number) Spend limit for the user in each budget period, in integer micro-units: `1000000` is $1.00. A limit of `0` allows no spend. The maximum is `1000000000000` ($1,000,000.00).
- `user_id` (String) ID of the user the override applies to. Changing this forces a new resource.

## Import

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# The ID supplied can be either a user UUID retrieved via the API
# or a username.
$ terraform import coderd_ai_user_budget_override.example developer
```
Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used:

```terraform
import {
to = coderd_ai_user_budget_override.example
id = "developer"
}
```
11 changes: 11 additions & 0 deletions examples/resources/coderd_ai_user_budget_override/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The ID supplied can be either a user UUID retrieved via the API
# or a username.
$ terraform import coderd_ai_user_budget_override.example developer
```
Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used:

```terraform
import {
to = coderd_ai_user_budget_override.example
id = "developer"
}
20 changes: 20 additions & 0 deletions examples/resources/coderd_ai_user_budget_override/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resource "coderd_user" "alice" {
username = "alice"
email = "alice@example.com"
}

resource "coderd_group" "engineering" {
name = "engineering"
members = [coderd_user.alice.id]
}

resource "coderd_ai_group_budget" "engineering" {
group_id = coderd_group.engineering.id
spend_limit = 50000000 // $50.00 for each member of the group
}

resource "coderd_ai_user_budget_override" "alice" {
user_id = coderd_user.alice.id
group_id = coderd_group.engineering.id
spend_limit = 200000000 // $200.00 for alice, attributed to engineering
}
3 changes: 2 additions & 1 deletion internal/provider/ai_group_budget_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ func (r *AIGroupBudgetResource) Schema(ctx context.Context, req resource.SchemaR
"Manages the AI spend limit that AI Gateway applies to each member of a group. " +
"Requires a Premium license with the AI Gateway feature, and permission to update the group.\n\n" +
"Each member of the group can spend up to the limit in each budget period. " +
"When a user belongs to several groups with a budget, the deployment's AI budget policy selects the group that applies.\n\n" +
"When a user belongs to several groups with a budget, the deployment's AI budget policy selects the group that applies. " +
"Use `coderd_ai_user_budget_override` to set a different limit for a single user.\n\n" +
"-> If Coder already has a different budget for the group, the plan fails. Import that budget to manage it with Terraform.\n\n" +
"Destroying this resource removes the budget, so members of the group no longer have a spend limit from it. " +
"Coder also removes the budget when the group is deleted.",
Expand Down
Loading