Skip to main content
This guide shows how to deploy a model on CoreWeave Dedicated Inference using Terraform instead of individual API calls. You describe the gateway and the deployment you want, and Terraform creates them, tracks them, and tears them down in the right order. This guide supplements Getting started with Dedicated Inference, which walks through the same resources using the CoreWeave Intelligent CLI and curl. By the end, you have a running inference endpoint managed as code: a gateway that provides the public, OpenAI-compatible endpoint, and a deployment that serves your model behind it. Because the deployment references the gateway’s id attribute, Terraform creates the gateway first and destroys it last.

Prerequisites

Before you begin, verify that you have the following:

Set your API token

Set your API token as an environment variable. The CoreWeave Terraform provider reads COREWEAVE_API_TOKEN automatically, so you don’t need to reference the token anywhere in your configuration. Replace [API-TOKEN] with your token.
Don’t put the token in a .tf file or commit it to version control. Your token determines which organization Terraform operates on.

Check available parameters

Zones, instance types, and engine versions differ by organization and change over time, so don’t copy values from documentation. Query the parameters endpoints and use the results when you fill in variable values in the next section.
The gateway parameters response lists the available zones. The deployment parameters response lists the available instance types under resourceParameters.instanceTypes, the available versions for each engine under runtimeParameters.runtimeVersions, and the allowed engine_config keys under runtimeParameters.runtimeConfigOptions. For guidance on interpreting these values, see Create a deployment in the Getting started guide.
The provider also exposes these queries as data sources, so you can read them from within a Terraform configuration. See the coreweave_inference_gateway_parameters and coreweave_inference_deployment_parameters references.

Create the configuration

Create a new directory with four files. Splitting the configuration this way keeps versions, inputs, resources, and outputs separate as your configuration grows. However, Terraform reads all .tf files in the directory regardless of how you divide them.

versions.tf

Pins the Terraform and provider versions, and configures the provider. The provider block is empty because the provider reads your token from the COREWEAVE_API_TOKEN environment variable.
versions.tf

variables.tf

Declares the values that differ by organization and model. Terraform prompts for each value when you run terraform plan or terraform apply, or reads them from a terraform.tfvars file if you create one.
variables.tf
To avoid retyping values on every run, create a terraform.tfvars file. Replace the bracketed placeholders with values from Check available parameters and the location of your model weights. An S3 path such as s3://test-bucket/raw/Qwen/Qwen3.5-0.8B/2fc06364715b967f1860aea9cf38778875588b17 breaks down into a bucket_name of test-bucket and a model_path of raw/Qwen/Qwen3.5-0.8B/2fc06364715b967f1860aea9cf38778875588b17.
terraform.tfvars

main.tf

Declares the gateway and the deployment. This is the file you edit to add or change models.
main.tf
Always set runtime.version explicitly. The provider schema marks it as optional and documents a default of the latest available version, but the API rejects configurations that omit it. The terraform plan step succeeds and terraform apply fails with Error: invalid_argument: validation error: runtime.version: value is required.

outputs.tf

Surfaces the endpoint URL, resource IDs, and deployment status after apply.
outputs.tf

Configuration notes

The following table explains the configuration fields that most often need attention:
This example uses the vllm engine. For the dynamo-vllm engine and its configuration keys, see Configure the engine in the Getting started guide. For the full resource schema, see the coreweave_inference_gateway and coreweave_inference_deployment references.

Deploy

With the four configuration files in place, run the standard Terraform workflow from the configuration directory:
The terraform init command downloads the provider. The terraform plan command previews the changes without making any, and it’s safe to run at any time. The terraform apply command shows the same preview and prompts for confirmation before creating anything. Read the plan before every apply. A + means create, ~ means update in place, and -/+ means destroy and recreate. A destroy-and-recreate on a deployment means downtime for that model. The apply waits until each resource is ready before returning, so a first deployment can take several minutes while the model weights load:
Example output
The gateway’s public DNS record and TLS certificate provision asynchronously and can take several minutes to resolve after the apply completes. If your first inference request fails with an SSL handshake error or DNS resolution failure, wait a few minutes and retry.

Verify the deployment

First, check Terraform’s view of the resources:
The deployment_status output should be STATUS_READY. Next, confirm that the gateway serves your model. Export the endpoint and list the models available on it:
The response lists every model served on this endpoint. If the endpoint responds but the list is empty, the gateway is up and the deployment isn’t ready yet. Then send a real request. Replace [MODEL-NAME] with the value you set for the model_name variable:
A response with a choices array containing generated text confirms that the gateway and deployment work. Finally, confirm Terraform is in sync with what’s deployed:
Expect No changes. That means your files match the deployed resources, which is the state you should be in before you finish.

Troubleshooting

The following table lists common failures during deployment and verification, and where to look first:

Add another deployment

To serve another model, add another resource block to main.tf. Each deployment can use its own model, engine version, and hardware, and several deployments can share one gateway. The following listing shows the complete main.tf with the second deployment block highlighted. Declare the two new variables, second_model_name and second_model_path, in variables.tf, and add their values to terraform.tfvars, following the same pattern as the existing variables.
main.tf
To create the new deployment, run the same plan and apply workflow from Deploy. Clients select between models with the model field in the request body. Two deployments that share the same model.name split traffic according to their relative traffic.weight values, which is how you run a canary rollout. For weight semantics, see the Configuration notes.

Make changes

To change a resource, edit the file and re-apply:
To remove everything this configuration manages, run:
Terraform deletes deployments before the gateway automatically, matching the required deletion order.

Adopt existing resources

If you already created gateways or deployments through the API, the CLI, or the Cloud Console, you don’t have to recreate them. You also don’t have to write the configuration by hand. Terraform can import the resources and generate matching configuration.
  1. List your existing resources and note their IDs:
  2. Add an import block for each resource. Replace [GATEWAY-ID] and [DEPLOYMENT-ID] with IDs from the previous step. The label after the resource type is yours to choose. It doesn’t have to match the resource’s name in the API, but the to address must not already exist in your configuration or state. If you completed the earlier sections in this directory, use new labels, as this example does with imported.
    imports.tf
    You can import several deployments behind one gateway, and you can import into a directory that already manages other resources. Existing resources are untouched.
  3. Generate the configuration:
    Terraform writes a matching resource block for every import, with the fields filled in from the live resource.
  4. Move the generated blocks into main.tf, refine them, and confirm:
    Repeat until the plan reports only imports and no changes. That’s the signal that your configuration matches the live resources.
  5. Run terraform apply to record the imported resources in state.
  6. Delete the import blocks. They’re one-time instructions.
After you import a resource, terraform destroy deletes the live resource. Make sure your state file is stored somewhere safe first. See Manage state.

Manage state

Terraform records what it manages in terraform.tfstate.
  • Don’t commit state files to version control. They can contain sensitive values. Do commit .terraform.lock.hcl, which pins provider checksums.
  • Deleting state doesn’t delete infrastructure. Terraform loses track of the resources, which keep running and accruing charges.
  • For teams, use a remote backend so that two people can’t apply conflicting changes at once.
The following is a typical .gitignore for a Terraform directory:
.gitignore

Next steps

To learn more about Dedicated Inference and the Terraform provider, explore these resources:
Last modified on August 20, 2026