Terraform

Deploy and manage Virtual Servers using Terraform

Virtual Servers are a Kubernetes Custom Resource on CoreWeave Cloud, which means the Kubernetes Terraform provider can be used to create and modify Virtual Servers as Custom Resources.

Getting Started

Before you can access CoreWeave Cloud, you must first request an account.

To use the Terraform module as your deployment method, you will first need to obtain valid access credentials in the form of a kubeconfig file.

Note

See Obtain Access Credentials for more information.

With the Virtual Server module cloned, and all configuration options adjusted to your preferences, a Virtual Server can either be created by running the module directly:

$ terraform init
$ terraform plan
$ terraform apply -auto-approve

Or, if managing a fleet of Virtual Servers, then ideally their outputs can be consumed by new module definitions for each machine, or by other modules.

Example

module "virtualserver_1" {
  source               = "./coreweave/kubernetes-cloud/tree/master/virtual-server/examples/terraform"
  kubeconfig_path      = "./kube/config/kubeconfig"
  vs_name              = "myserver"
  vs_username          = "myuser"
  vs_generate_password = "true"
  user_namespace       = "mynamespace"
}

Repeating a single definition for additional machines, then managing each Virtual Server, can be done by using the target option:

$ terraform plan -target=module.virtualserver_1
$ terraform apply -target=module.virtualserver_1 -auto-approve
$ terraform destroy -target=module.virtualserver_1

Once deployed, the status of the new machine can be verified using kubectl:

$ kubectl get vs example-vs

NAME                STATUS               REASON                                           STARTED   INTERNAL IP      EXTERNAL IP
example-vs          Initializing         Waiting for VirtualMachineInstance to be ready   False                      123.123.123.123

Note

The output of this command will include the Service External IP address for accessing the server.

Output variables

As shown in the example above, this module has two output values that can be referenced as attributes by other modules.

Example

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

vs_network = "[address]"
vs_password = "[password]"

This will include the Service IP address and either the provided password or the one generated by Terraform as vs_network and vs_password, which can be referenced, for example, as outputs:

output "vs_network" {
  value = module.virtualserver_1.vs_network
}

output "vs_password" {
  value = module.virtualserver_1.vs_password
}

Examples

CoreWeave provides an example plan on GitHub.

Configuration quick reference

The table below is intended as a quick-reference guide for all available configuration options using the Kubernetes CLI deployment method. Learn more about each configuration option in their respective pages under Virtual Server Configuration Options.

Variable nameTypeDescription

kubeconfig_path

string

The system path to the kubeconfig file to use

user_namespace

string

The namespace into which the Virtual Server will be deployed. Does not have a default value; must be set

vs_name

string

The hostname for the Virtual Server

vs_username

string

Username for the virtual server Does not have a default value; must be set

vs_generate_password

bool

When set to true, a strong password is generated

vs_password

string

With vs_generate_password set to false, provide a password for vs_username

vs_memory

string

Memory requested in Gi (i.e. 16Gi)

vs_root_storage

string

The amount of storage requested for the root volume in Gi (i.e. 80Gi)

vs_os_type

string

Virtual Server OS variant (i.e. linux)

vs_image

string

The name of the OS image to deploy to the Virtual Server

vs_gpu

string

The GPU model name for Virtual Server

vs_gpu_enable

bool

Enables a GPU for this Virtual Server

vs_gpu_count

int

The number of GPUs requested

vs_cpu_count

int

The number of CPUs requested

vs_region

string

The data center region in which to deploy the Virtual Server

vs_running

bool

Start the Virtual Server once deployed

vs_public_networking

bool

Enable public networking

vs_attach_loadbalancer

bool

Attach a Service Load Balancer IP directly to the Virtual Server (vs_tcp_ports and vs_udp_ports must be empty, if enabled)

vs_tcp_ports

list

A list of TCP ports to allow access to

vs_udp_ports

list

A list of UDP ports to allow access to

Last updated