litellm/terraform/provider/docs/resources/credential.md
Yassin Kortam 7c69ede9be
feat(terraform): write-only secret attributes to keep secrets out of state (#46538)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-15 15:36:15 -07:00

5.8 KiB

page_title subcategory description
litellm_credential Resource - terraform-provider-litellm Manages a LiteLLM credential for storing sensitive authentication information.

litellm_credential (Resource)

Manages a LiteLLM credential for storing sensitive authentication information. Credentials can be used to securely store API keys, tokens, and other sensitive data that can be referenced by models and vector stores.

Example Usage

Basic OpenAI Credential

resource "litellm_credential" "openai_cred" {
  credential_name = "openai-api-key"
  model_id        = "gpt-4"
  
  credential_info = {
    provider = "openai"
    region   = "us-east-1"
    purpose  = "chat-completions"
  }
  
  credential_values = {
    api_key = var.openai_api_key
    org_id  = var.openai_org_id
  }
}

Anthropic Credential

resource "litellm_credential" "anthropic_cred" {
  credential_name = "anthropic-api-key"
  
  credential_info = {
    provider = "anthropic"
    purpose  = "text-generation"
  }
  
  credential_values = {
    api_key = var.anthropic_api_key
  }
}

Pinecone Vector Store Credential

resource "litellm_credential" "pinecone_cred" {
  credential_name = "pinecone-production"
  
  credential_info = {
    provider    = "pinecone"
    environment = "production"
    region      = "us-east-1"
  }
  
  credential_values = {
    api_key    = var.pinecone_api_key
    index_name = "document-embeddings"
  }
}

Using Credentials with Vector Store

resource "litellm_vector_store" "example" {
  vector_store_name        = "my-vector-store"
  custom_llm_provider      = "pinecone"
  litellm_credential_name  = litellm_credential.pinecone_cred.credential_name
  
  vector_store_description = "Example vector store using Pinecone"
  
  vector_store_metadata = {
    environment = "production"
    team        = "ai-team"
  }
}

Multiple Provider Credentials

# AWS Bedrock credential
resource "litellm_credential" "aws_bedrock" {
  credential_name = "aws-bedrock-cred"
  
  credential_info = {
    provider = "aws"
    service  = "bedrock"
    region   = "us-east-1"
  }
  
  credential_values = {
    aws_access_key_id     = var.aws_access_key_id
    aws_secret_access_key = var.aws_secret_access_key
    aws_region            = "us-east-1"
  }
}

# Azure OpenAI credential
resource "litellm_credential" "azure_openai" {
  credential_name = "azure-openai-cred"
  
  credential_info = {
    provider = "azure"
    service  = "openai"
  }
  
  credential_values = {
    api_key      = var.azure_openai_key
    api_base     = var.azure_openai_endpoint
    api_version  = "2023-12-01-preview"
  }
}

Keeping Secrets Out of State

resource "litellm_credential" "openai_cred" {
  credential_name = "openai-api-key"

  credential_info = {
    provider = "openai"
  }

  credential_values_wo = jsonencode({
    api_key = var.openai_api_key
  })
  credential_values_wo_version = 1
}

Argument Reference

The following arguments are supported:

  • credential_name - (Required) Name of the credential. This will be used as the identifier for the credential.
  • credential_values - (Optional, Sensitive) Map of sensitive credential values such as API keys, tokens, etc. Written to the state file in plaintext. Exactly one of credential_values and credential_values_wo must be set.
  • credential_values_wo - (Optional, Write-only, Sensitive) JSON object of string values, usually jsonencode({ api_key = var.key }). Every value must be a string (pass a service account file as file(...), not jsondecode(...)) because the proxy only encrypts string values at rest; nested objects and numbers are rejected before any request. Sent to the proxy on every apply and never written to plan or state. Requires Terraform 1.11 or later and credential_values_wo_version.
  • credential_values_wo_version - (Optional) Integer that triggers an update when credential_values_wo changes. Write-only values produce no diff on their own, so bump this number whenever you rotate the secret.
  • model_id - (Optional) Model ID associated with this credential.
  • credential_info - (Optional) Map of additional non-sensitive information about the credential.
  • adopt_existing - (Optional, default false) Take over a credential of this name that already exists on the proxy instead of failing. Turning this on overwrites the existing credential's values with the ones in this configuration.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • credential_name - The name of the credential.

Import

Credentials can be imported using their name:

terraform import litellm_credential.example "credential-name"

Security Considerations

  • The credential_values field is marked as sensitive and will not be displayed in Terraform output or logs.
  • Credential values are not read back from the API for security reasons, so they are preserved in the Terraform state.
  • Like every Terraform attribute marked Sensitive, credential_values is still written in plaintext to the state file. Anyone with read access to the state (or state artifacts such as plan files) can recover the configured secrets. Use credential_values_wo to keep them out of state entirely, or at least use an encrypted remote backend with tight access controls.

Migrating to Write-only Values

  1. Upgrade to Terraform 1.11 or later.
  2. Replace credential_values = { ... } with credential_values_wo = jsonencode({ ... }) and add credential_values_wo_version = 1.
  3. Run terraform apply. The proxy receives the same values and the state file no longer carries them.
  4. To rotate a secret later, change the value and bump credential_values_wo_version.