> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Deploy with Terraform

> Deploy a Sarvam SageMaker endpoint with Terraform. One apply provisions the IAM execution role, the model from your Marketplace package, the endpoint config, and a live endpoint.

Prefer infrastructure-as-code? This Terraform module provisions everything a Sarvam endpoint needs — the **IAM execution role**, the **model** (from your Marketplace package ARN), the **endpoint configuration**, and the **endpoint** — in a single `terraform apply`. It works for Saaras v3, Bulbul v3, and Sarvam Vision; just point `model_package_arn` at the right package (all three run on `ml.g6e.xlarge` by default).

## Prerequisites

* Terraform 1.5+ and AWS credentials configured.
* An active [Marketplace subscription](/api/self-hosted/sagemaker/get-started#2-subscribe-on-aws-marketplace) and the **model package ARN** for your region.

## Variables

```hcl variables.tf
variable "region"            { type = string  default = "ap-south-1" }
variable "endpoint_name"     { type = string  default = "sarvam-endpoint" }
variable "model_package_arn" { type = string } # from your Marketplace subscription
variable "instance_type"     { type = string  default = "ml.g6e.xlarge" }
variable "instance_count"    { type = number  default = 1 }
```

## Main configuration

```hcl main.tf
provider "aws" {
  region = var.region
}

# Execution role SageMaker assumes to run the endpoint
resource "aws_iam_role" "exec" {
  name = "${var.endpoint_name}-exec"
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect    = "Allow"
      Principal = { Service = "sagemaker.amazonaws.com" }
      Action    = "sts:AssumeRole"
    }]
  })
}

resource "aws_iam_role_policy_attachment" "sagemaker" {
  role       = aws_iam_role.exec.name
  policy_arn = "arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"
}

# Model from the Marketplace package
resource "aws_sagemaker_model" "this" {
  name                     = var.endpoint_name
  execution_role_arn       = aws_iam_role.exec.arn
  enable_network_isolation = true

  primary_container {
    model_package_name = var.model_package_arn
  }
}

resource "aws_sagemaker_endpoint_configuration" "this" {
  name = var.endpoint_name

  production_variants {
    variant_name           = "AllTraffic"
    model_name             = aws_sagemaker_model.this.name
    instance_type          = var.instance_type
    initial_instance_count = var.instance_count
  }
}

resource "aws_sagemaker_endpoint" "this" {
  name                 = var.endpoint_name
  endpoint_config_name = aws_sagemaker_endpoint_configuration.this.name
}

output "endpoint_name" {
  value = aws_sagemaker_endpoint.this.name
}
```

## Deploy

```bash
terraform init
terraform plan  -var="model_package_arn=arn:aws:sagemaker:ap-south-1:<vendor>:model-package/<id>"
terraform apply -var="model_package_arn=arn:aws:sagemaker:ap-south-1:<vendor>:model-package/<id>"
```

Once `apply` finishes and the endpoint reaches `InService`, invoke it exactly as in the [Deploy Saaras v3](/api/self-hosted/sagemaker/deploy-saaras#3-invoke-it) or [Deploy Vision](/api/self-hosted/sagemaker/deploy-vision#3-invoke-it) guides.

For **async** endpoints, add an `async_inference_config` block (with an S3 output path) to the endpoint configuration and attach S3 permissions to the execution role. Add an `aws_appautoscaling_target` / `aws_appautoscaling_policy` pair to autoscale — including scale-to-zero for async.

## Tear down

```bash
terraform destroy -var="model_package_arn=arn:aws:sagemaker:ap-south-1:<vendor>:model-package/<id>"
```