Skip to content

Commit 10cc792

Browse files
fix: AWS supported
1 parent ecc94e2 commit 10cc792

File tree

9 files changed

+110
-89
lines changed

9 files changed

+110
-89
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,29 @@ terraform-provider-litellm
4242
.Trashes
4343
ehthumbs.db
4444
Thumbs.db
45+
46+
# Go specific
47+
*.exe
48+
*.exe~
49+
*.dll
50+
*.so
51+
*.dylib
52+
*.test
53+
*.out
54+
go.work
55+
56+
# Dependency directories (remove the comment below to include it)
57+
# vendor/
58+
59+
# Output of the go coverage tool, specifically when used with LiteIDE
60+
*.out
61+
62+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
63+
*.o
64+
*.a
65+
66+
# Log files
67+
*.log
68+
69+
# Environment files
70+
.env

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# LiteLLM Terraform Provider
22

3-
[![Build Status](https://github.com/bitop/terraform-provider-litellm/workflows/tests/badge.svg)](https://github.com/bitop/terraform-provider-litellm/actions)
4-
53
This Terraform provider allows you to manage LiteLLM resources through Infrastructure as Code. It provides support for managing models, teams, and team members via the LiteLLM REST API.
64

7-
## Documentation
8-
9-
Full documentation is available on the [Terraform Registry](https://registry.terraform.io/providers/bitop/litellm/latest/docs).
10-
115
## Features
126

137
- Manage LiteLLM model configurations
@@ -27,28 +21,29 @@ Full documentation is available on the [Terraform Registry](https://registry.ter
2721
terraform {
2822
required_providers {
2923
litellm = {
30-
source = "bitop/litellm"
24+
source = "local/litellm/litellm"
3125
version = "1.0.0"
3226
}
3327
}
3428
}
3529
3630
provider "litellm" {
37-
api_base = "http://your-litellm-instance:4000"
38-
api_key = "your-api-key"
31+
api_base = var.litellm_api_base
32+
api_key = var.litellm_api_key
3933
}
4034
41-
# Example model configuration
42-
resource "litellm_model" "gpt4" {
43-
model_name = "gpt-4-proxy"
44-
custom_llm_provider = "openai"
45-
model_api_key = "sk-your-api-key"
46-
model_api_base = "https://api.openai.com/v1"
47-
api_version = "2023-05-15"
48-
base_model = "gpt-4"
49-
tier = "paid"
50-
tpm = 100000
51-
rpm = 1000
35+
# Example model configuration for AWS Bedrock
36+
resource "litellm_model" "claude_aws_bedrock" {
37+
model_name = "claude-3.5-sonnet-v2"
38+
custom_llm_provider = "bedrock"
39+
base_model = "anthropic.claude-3-5-sonnet-20241022-v2:0"
40+
tier = "paid"
41+
aws_access_key_id = var.aws_access_key_id
42+
aws_secret_access_key = var.aws_secret_access_key
43+
aws_region_name = var.aws_region
44+
45+
input_cost_per_million_tokens = 4.0
46+
output_cost_per_million_tokens = 16.0
5247
}
5348
```
5449

@@ -58,7 +53,7 @@ resource "litellm_model" "gpt4" {
5853

5954
1. Clone the repository
6055
```sh
61-
git clone https://github.com/bitop/terraform-provider-litellm.git
56+
git clone https://github.com/your-username/terraform-provider-litellm.git
6257
```
6358

6459
2. Enter the repository directory
@@ -86,3 +81,9 @@ Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTIN
8681
## License
8782

8883
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
84+
85+
## Notes
86+
87+
- Always use environment variables or secure secret management solutions to handle sensitive information like API keys and AWS credentials.
88+
- Refer to the `examples/` directory for more detailed usage examples.
89+
- Make sure to keep your provider version updated for the latest features and bug fixes.

examples/model-test/.terraform.lock.hcl

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/model-test/README.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/model-test/main.tf

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
terraform {
22
required_providers {
33
litellm = {
4-
source = "local/litellm/litellm"
4+
source = "registry.terraform.io/local/litellm"
5+
version = "1.0.0"
56
}
67
}
78
}
@@ -22,25 +23,37 @@ variable "litellm_api_key" {
2223
sensitive = true
2324
}
2425

25-
resource "litellm_model" "test_model" {
26-
model_name = "test-azure-gpt4"
27-
custom_llm_provider = "azure"
28-
base_model = "gpt-4"
29-
model_api_key = var.model_api_key
30-
model_api_base = var.model_api_base
31-
api_version = "2023-05-15"
32-
rpm = 50
33-
tpm = 80000
34-
tier = "free"
26+
variable "aws_access_key_id" {
27+
type = string
28+
description = "AWS Access Key ID"
29+
sensitive = true
3530
}
3631

37-
variable "model_api_key" {
32+
variable "aws_secret_access_key" {
3833
type = string
39-
description = "Model API Key"
34+
description = "AWS Secret Access Key"
4035
sensitive = true
4136
}
4237

43-
variable "model_api_base" {
38+
variable "aws_region" {
4439
type = string
45-
description = "Model API Base URL"
40+
description = "AWS Region"
41+
default = "us-west-2"
42+
}
43+
44+
resource "litellm_model" "test_aws_bedrock_model" {
45+
model_name = "claude-3.5-sonnet-v2"
46+
custom_llm_provider = "bedrock"
47+
base_model = "anthropic.claude-3-5-sonnet-20241022-v2:0"
48+
tier = "paid"
49+
aws_access_key_id = var.aws_access_key_id
50+
aws_secret_access_key = var.aws_secret_access_key
51+
aws_region_name = var.aws_region
52+
53+
input_cost_per_million_tokens = 4.0
54+
output_cost_per_million_tokens = 16.0
55+
}
56+
57+
output "model_id" {
58+
value = litellm_model.test_aws_bedrock_model.id
4659
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
litellm_api_base = "https://your-litellm-api-base"
1+
litellm_api_base = "http://localhost:4000"
22
litellm_api_key = "your-litellm-api-key"
3-
model_api_key = "your-model-api-key"
4-
model_api_base = "https://your-model-api-base"
3+
aws_access_key_id = "your-aws-access-key-id"
4+
aws_secret_access_key = "your-aws-secret-access-key"
5+
aws_region = "us-west-2"

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
55
)
66

7+
// main is the entry point for the plugin. It serves the provider
8+
// using the Terraform plugin SDK.
79
func main() {
810
plugin.Serve(&plugin.ServeOpts{
911
ProviderFunc: Provider,

provider.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
55
)
66

7+
// ProviderConfig holds the configuration for the LiteLLM provider
78
type ProviderConfig struct {
89
APIBase string
910
APIKey string
1011
}
1112

13+
// Provider returns a terraform.ResourceProvider.
1214
func Provider() *schema.Provider {
1315
return &schema.Provider{
1416
ResourcesMap: map[string]*schema.Resource{
@@ -20,18 +22,21 @@ func Provider() *schema.Provider {
2022
Required: true,
2123
Sensitive: false,
2224
DefaultFunc: schema.EnvDefaultFunc("LITELLM_API_BASE", nil),
25+
Description: "The base URL of the LiteLLM API",
2326
},
2427
"api_key": {
2528
Type: schema.TypeString,
2629
Required: true,
2730
Sensitive: true,
2831
DefaultFunc: schema.EnvDefaultFunc("LITELLM_API_KEY", nil),
32+
Description: "The API key for authenticating with LiteLLM",
2933
},
3034
},
3135
ConfigureFunc: providerConfigure,
3236
}
3337
}
3438

39+
// providerConfigure configures the provider with the given schema data.
3540
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
3641
config := ProviderConfig{
3742
APIBase: d.Get("api_base").(string),

resource_litellm_model.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type LiteLLMParams struct {
2525
Model string `json:"model,omitempty"`
2626
InputCostPerToken float64 `json:"input_cost_per_token,omitempty"`
2727
OutputCostPerToken float64 `json:"output_cost_per_token,omitempty"`
28+
AWSAccessKeyID string `json:"aws_access_key_id,omitempty"`
29+
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
30+
AWSRegionName string `json:"aws_region_name,omitempty"`
2831
Additional map[string]interface{} `json:"additionalProp1,omitempty"`
2932
}
3033

@@ -119,6 +122,20 @@ func resourceLiteLLMModel() *schema.Resource {
119122
Optional: true,
120123
Default: 0.0,
121124
},
125+
"aws_access_key_id": {
126+
Type: schema.TypeString,
127+
Optional: true,
128+
Sensitive: true,
129+
},
130+
"aws_secret_access_key": {
131+
Type: schema.TypeString,
132+
Optional: true,
133+
Sensitive: true,
134+
},
135+
"aws_region_name": {
136+
Type: schema.TypeString,
137+
Optional: true,
138+
},
122139
},
123140
}
124141
}
@@ -199,6 +216,9 @@ func createOrUpdateModel(d *schema.ResourceData, m interface{}, isUpdate bool) e
199216
Model: modelName,
200217
InputCostPerToken: inputCostPerToken,
201218
OutputCostPerToken: outputCostPerToken,
219+
AWSAccessKeyID: d.Get("aws_access_key_id").(string),
220+
AWSSecretAccessKey: d.Get("aws_secret_access_key").(string),
221+
AWSRegionName: d.Get("aws_region_name").(string),
202222
},
203223
ModelInfo: ModelInfo{
204224
ID: modelID,
@@ -287,6 +307,9 @@ func resourceLiteLLMModelRead(d *schema.ResourceData, m interface{}) error {
287307
d.Set("api_version", modelResp.LiteLLMParams.APIVersion)
288308
d.Set("base_model", modelResp.ModelInfo.BaseModel)
289309
d.Set("tier", modelResp.ModelInfo.Tier)
310+
d.Set("aws_access_key_id", modelResp.LiteLLMParams.AWSAccessKeyID)
311+
d.Set("aws_secret_access_key", modelResp.LiteLLMParams.AWSSecretAccessKey)
312+
d.Set("aws_region_name", modelResp.LiteLLMParams.AWSRegionName)
290313

291314
return nil
292315
}

0 commit comments

Comments
 (0)