Skip to content
Open
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.36.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 the Owner or User Admin role, or the Organization Admin or Organization User Admin role in the group's organization.
Each member of the group can spend up to the limit in each budget period https://coder.com/docs/ai-coder/ai-gateway/cost-controls#deployment-settings. When a user belongs to several groups with a budget, the deployment's budget policy https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution selects the group that applies.
Each member of the group can spend up to the limit in each budget period https://coder.com/docs/ai-coder/ai-gateway/cost-controls#deployment-settings. When a user belongs to several groups with a budget, the deployment's budget policy https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution 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. Future requests from members of the group use their next effective group https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution, and spend already recorded stays attributed to this group. 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.36.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 the Owner or User Admin role, or the Organization Admin or Organization User Admin role in the group's organization.

Each member of the group can spend up to the limit in each [budget period](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#deployment-settings). When a user belongs to several groups with a budget, the deployment's [budget policy](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution) selects the group that applies.
Each member of the group can spend up to the limit in each [budget period](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#deployment-settings). When a user belongs to several groups with a budget, the deployment's [budget policy](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution) 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.36.0 and later.
Manages an AI spend limit for a single user, which takes precedence https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution over the user's coderd_ai_group_budget limits. Requires a Premium license with the AI Gateway feature, and the Owner or User Admin role.
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. Future requests from the user use their effective group https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution, and spend already recorded stays attributed to the override's group.
---

# coderd_ai_user_budget_override (Resource)

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

Manages an AI spend limit for a single user, which [takes precedence](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution) over the user's `coderd_ai_group_budget` limits. Requires a Premium license with the AI Gateway feature, and the Owner or User Admin role.

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. Future requests from the user use their [effective group](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution), and spend already recorded stays attributed to the override's group.

## 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 alice
```
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 = "alice"
}
```
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 alice
```
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 = "alice"
}
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"
}
Comment on lines +1 to +4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we update integration/agents-model-test to cover this resource and coderd_ai_group_budget, like #445 and #448 did for the other AI resources? Something like:

  • create a user, add it to the existing agents-users group, and give the group a coderd_ai_group_budget and the user a coderd_ai_user_budget_override, all in the same apply
  • assert that UserAISpendStatus for that user returns the override's limit with limit_source set to user_override

The acceptance tests for both resources create the users and groups through the SDK, so nothing applies this example shape end to end or checks that Coder enforces the override over the group budget.

Generated by an agent on behalf of the user


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 @@ -130,7 +130,8 @@ func (r *AIGroupBudgetResource) Schema(ctx context.Context, req resource.SchemaR
"Requires a Premium license with the AI Gateway feature, and the Owner or User Admin role, " +
"or the Organization Admin or Organization User Admin role in the group's organization.\n\n" +
"Each member of the group can spend up to the limit in each [budget period](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#deployment-settings). " +
"When a user belongs to several groups with a budget, the deployment's [budget policy](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution) selects the group that applies.\n\n" +
"When a user belongs to several groups with a budget, the deployment's [budget policy](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution) 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. Future requests from members of the group use their next " +
"[effective group](https://coder.com/docs/ai-coder/ai-gateway/cost-controls#effective-group-resolution), " +
Expand Down
Loading