Repository navigation
feat: add coderd_ai_user_budget_override resource #454
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
Open
+708
−4
Open
Changes from all commits
Commits
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
| 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
11
examples/resources/coderd_ai_user_budget_override/import.sh
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,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
20
examples/resources/coderd_ai_user_budget_override/resource.tf
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,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 | ||
| } | ||
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.
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.
There was a problem hiding this comment.
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-testto cover this resource andcoderd_ai_group_budget, like #445 and #448 did for the other AI resources? Something like:agents-usersgroup, and give the group acoderd_ai_group_budgetand the user acoderd_ai_user_budget_override, all in the same applyUserAISpendStatusfor that user returns the override's limit withlimit_sourceset touser_overrideThe 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.