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:- A CoreWeave account with Inference access enabled.
- A CoreWeave API access token with the Inference Admin role.
- Model weights uploaded to a CoreWeave AI Object Storage bucket. To create a bucket, see Create a bucket.
- A bucket policy that grants the inference service account read and list access to your weights bucket. Follow Grant inference access to your bucket before you continue. A missing bucket policy is the most common cause of deployments that fail to load weights.
- Terraform 1.5 or later, or OpenTofu. The Adopt existing resources section uses
importblocks and configuration generation, which require Terraform 1.5. curlto send a test inference request, andjqto format JSON responses in thecurlexamples.- Optional: The CoreWeave Intelligent CLI (
cwic). This guide showscwiccommands and equivalentcurlrequests for the steps that query the CoreWeave API directly.
Set your API token
Set your API token as an environment variable. The CoreWeave Terraform provider readsCOREWEAVE_API_TOKEN automatically, so you don’t need to reference the token anywhere in your configuration. Replace [API-TOKEN] with your token.
.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.- CoreWeave Intelligent CLI
- curl
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
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
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: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: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:
[MODEL-NAME] with the value you set for the model_name variable:
choices array containing generated text confirms that the gateway and deployment work.
Finally, confirm Terraform is in sync with what’s deployed:
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 anotherresource 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
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: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.-
List your existing resources and note their IDs:
- CoreWeave Intelligent CLI
- curl
-
Add an
importblock 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 thetoaddress 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 withimported.You can import several deployments behind one gateway, and you can import into a directory that already manages other resources. Existing resources are untouched.imports.tf -
Generate the configuration:
Terraform writes a matching
resourceblock for every import, with the fields filled in from the live resource. -
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. -
Run
terraform applyto record the imported resources in state. -
Delete the
importblocks. They’re one-time instructions.
Manage state
Terraform records what it manages interraform.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.
.gitignore for a Terraform directory:
.gitignore
Next steps
To learn more about Dedicated Inference and the Terraform provider, explore these resources:- Getting started with Dedicated Inference: The same workflow using the CoreWeave Intelligent CLI and
curl, plus observability and engine configuration. - Gateways: Authentication, routing strategies, and traffic splitting.
- Models and deployments: Runtime configuration, GPU selection, and deployment options.
- Scaling: Autoscaling and reserved GPU capacity.
- CoreWeave Terraform provider reference: Provider configuration, resources, and data sources.